Skip to content

Commit 870eacc

Browse files
committed
refactor: windows关闭通知
1 parent b790bec commit 870eacc

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/main/scrcpy/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const Noti = {
2020
}))
2121
}
2222
}
23+
let isNoti = !appStore.get('closeNotification') && platform.isMacOS
24+
platform.isMacOS && appStore.onDidChange('closeNotification', (v) => { isNoti = !v })
2325

2426
let scrcpyPath = 'scrcpy'
2527
// @ts-ignore - .
@@ -44,7 +46,7 @@ const Scrcpy = {
4446
this.scrcpy.stderr!.on('data', (errorOutput) => {
4547
console.error(`标准错误: ${errorOutput.toString()}`)
4648
ipcMain.emit('scrcpyMessage', { type: 'stderr', data: errorOutput.toString() })
47-
new Notification({
49+
isNoti && new Notification({
4850
title: 'Scrcpy 错误提示',
4951
body: errorOutput.toString(),
5052
silent: true
@@ -55,14 +57,14 @@ const Scrcpy = {
5557
console.log(`子进程退出码: ${code}`)
5658
this.close()
5759
ipcMain.emit('scrcpyMessage', { type: 'close', data: 'scrcpy 已关闭' })
58-
Noti.close.show()
60+
isNoti && Noti.close.show()
5961
})
6062

6163
this.scrcpy.on('error', (err) => {
6264
console.error(`子进程启动失败: ${err}`)
6365
this.close()
6466
ipcMain.emit('scrcpyMessage', { type: 'error', data: 'scrcpy 启动失败' })
65-
Noti.error.show()
67+
isNoti && Noti.error.show()
6668
})
6769
},
6870
stop() {

src/main/store/appStore.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const appStore = new Store({
99
scrcpyOptions: [] as string[],
1010
hideDock: false,
1111
hideWindow: false,
12+
closeNotification: false,
1213
isStartScrcpy: false
1314
}
1415
})

src/main/tray/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ const trayTemplate: Parameters<typeof Menu.buildFromTemplate>[0] = [
4242
appStore.set('hideDock', menuItem.checked)
4343
menuItem.checked ? app.dock.hide() : app.dock.show()
4444
}
45+
}, {
46+
id: 'closeNotification',
47+
label: 'Close Notification',
48+
type: 'checkbox',
49+
get checked() {
50+
return appStore.get('closeNotification')
51+
},
52+
click: (menuItem) => {
53+
appStore.set('closeNotification', menuItem.checked)
54+
}
4555
}] as Parameters<typeof Menu.buildFromTemplate>[0]
4656
: [] as any),
4757
{

0 commit comments

Comments
 (0)