Skip to content

Commit

Permalink
refactor(main): notice fn
Browse files Browse the repository at this point in the history
  • Loading branch information
QC2168 committed Jun 26, 2023
1 parent 9985a3d commit 7677f57
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Mib, {
} from '@qc2168/mib';

import {
app, BrowserWindow, ipcMain, shell, Notification,
app, BrowserWindow, ipcMain, shell, Notification, nativeImage,
} from 'electron';
import { release } from 'os';
import semver from 'semver';
Expand All @@ -26,6 +26,15 @@ const mibInstance = new Mib();
mibInstance.setAdbPath(AdbPath);

const NOTIFICATION_TITLE = 'MIB';
const ICON = nativeImage.createFromPath('./resources/icon.ico');

function notice(body:string) {
new Notification({
title: NOTIFICATION_TITLE,
body,
icon: ICON,
}).show();
}

// Disable GPU Acceleration for Windows 7
if (release()
Expand Down Expand Up @@ -274,10 +283,7 @@ ipcMain.handle('openLink', async (event, url:string) => {
try {
await shell.openExternal(url);
} catch (error) {
new Notification({
title: NOTIFICATION_TITLE,
body: '访问链接失败',
}).show();
notice('访问链接失败');
}
});

Expand All @@ -286,17 +292,11 @@ ipcMain.handle('checkVersion', async () => {
try {
const { data: { version: remoteVersion } } = await axios.get('https://gitee.com/QC2168/mib/raw/client/package.json');
if (semver.gt(remoteVersion, version)) {
new Notification({
title: NOTIFICATION_TITLE,
body: '检测到新版本,请更新',
}).show();
notice('检测到新版本,请更新');
return true;
}
return false;
} catch (error) {
new Notification({
title: NOTIFICATION_TITLE,
body: '检测程序版本失败,请检测网络',
}).show();
notice('检测程序版本失败,请检测网络');
}
});

0 comments on commit 7677f57

Please sign in to comment.