-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from rao-pics/224-系统托盘
224 系统托盘
- Loading branch information
Showing
11 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const globalApp = globalThis as { | ||
/** 是否退出 App */ | ||
isQuite?: boolean; | ||
}; | ||
|
||
globalApp.isQuite = false; | ||
|
||
export default globalApp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Menu, app } from "electron"; | ||
|
||
import { hideWindow } from "../mainWindow"; | ||
|
||
/** | ||
* 创建菜单 | ||
*/ | ||
const createMenu = () => { | ||
const menu = Menu.buildFromTemplate([ | ||
{ | ||
label: app.name, | ||
submenu: [ | ||
{ | ||
label: "Quit", | ||
accelerator: "CmdOrCtrl+Q", | ||
click: () => hideWindow(), | ||
}, | ||
], | ||
}, | ||
]); | ||
Menu.setApplicationMenu(menu); | ||
}; | ||
|
||
export default createMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { join } from "path"; | ||
import { Menu, Tray, app, nativeTheme } from "electron"; | ||
|
||
import globalApp from "../global"; | ||
import { restoreOrCreateWindow } from "../mainWindow"; | ||
|
||
export const getTrayIcon = () => { | ||
if (app.isPackaged) { | ||
return join(process.resourcesPath, "buildResources", nativeTheme.shouldUseDarkColors ? "tray-dark.png" : "tray-light.png"); | ||
} else { | ||
return join(__dirname, "../../buildResources", nativeTheme.shouldUseDarkColors ? "tray-dark.png" : "tray-light.png"); | ||
} | ||
}; | ||
|
||
/** | ||
* 系统托盘 | ||
* @returns {Tray} | ||
*/ | ||
const createTray = () => { | ||
// 托盘图标 | ||
const tray = new Tray(getTrayIcon()); | ||
|
||
const contextMenu = Menu.buildFromTemplate([ | ||
{ | ||
label: "打开 Rao Pics", | ||
type: "normal", | ||
click: () => { | ||
void restoreOrCreateWindow(); | ||
}, | ||
}, | ||
{ | ||
label: "退出", | ||
type: "normal", | ||
click: () => { | ||
globalApp.isQuite = true; | ||
app.quit(); | ||
}, | ||
}, | ||
]); | ||
tray.setContextMenu(contextMenu); | ||
|
||
return tray; | ||
}; | ||
|
||
export default createTray; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters