mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-05 15:37:21 +08:00
✨ Feature: 为Linux系统适配桌面图标栏(Tray) (#603)
This commit is contained in:
@@ -21,6 +21,7 @@ let menu: Menu | null
|
|||||||
let tray: Tray | null
|
let tray: Tray | null
|
||||||
export function createContextMenu() {
|
export function createContextMenu() {
|
||||||
const picBeds = getPicBeds()
|
const picBeds = getPicBeds()
|
||||||
|
if (process.platform === "darwin" || process.platform === "win32") {
|
||||||
const submenu = picBeds.filter(item => item.visible).map(item => {
|
const submenu = picBeds.filter(item => item.visible).map(item => {
|
||||||
return {
|
return {
|
||||||
label: item.name,
|
label: item.name,
|
||||||
@@ -89,10 +90,61 @@ export function createContextMenu () {
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
else if (process.platform === "linux") {
|
||||||
|
// TODO 图床选择功能
|
||||||
|
// 由于在Linux难以像在Mac和Windows上那样在点击时构造ContextMenu,
|
||||||
|
// 暂时取消这个选单,避免引起和设置中启用的图床不一致
|
||||||
|
|
||||||
|
// TODO 重启应用功能
|
||||||
|
// 目前的实现无法正常工作
|
||||||
|
|
||||||
|
contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: '打开详细窗口',
|
||||||
|
click() {
|
||||||
|
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||||
|
settingWindow!.show()
|
||||||
|
settingWindow!.focus()
|
||||||
|
if (windowManager.has(IWindowList.MINI_WINDOW)) {
|
||||||
|
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
{
|
||||||
|
label: '打开更新助手',
|
||||||
|
type: 'checkbox',
|
||||||
|
checked: db.get('settings.showUpdateTip'),
|
||||||
|
click() {
|
||||||
|
const value = db.get('settings.showUpdateTip')
|
||||||
|
db.set('settings.showUpdateTip', !value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关于应用',
|
||||||
|
click() {
|
||||||
|
dialog.showMessageBox({
|
||||||
|
title: 'PicGo',
|
||||||
|
message: 'PicGo',
|
||||||
|
buttons: ['Ok'],
|
||||||
|
detail: `Version: ${pkg.version}\nAuthor: Molunerfinn\nGithub: https://github.com/Molunerfinn/PicGo`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
{
|
||||||
|
role: 'quit',
|
||||||
|
label: '退出'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createTray() {
|
export function createTray() {
|
||||||
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
||||||
tray = new Tray(menubarPic)
|
tray = new Tray(menubarPic)
|
||||||
|
// click事件在Mac和Windows上可以触发(在Ubuntu上无法触发,Unity不支持)
|
||||||
|
if (process.platform === "darwin" || process.platform === "win32") {
|
||||||
tray.on('right-click', () => {
|
tray.on('right-click', () => {
|
||||||
if (windowManager.has(IWindowList.TRAY_WINDOW)) {
|
if (windowManager.has(IWindowList.TRAY_WINDOW)) {
|
||||||
windowManager.get(IWindowList.TRAY_WINDOW)!.hide()
|
windowManager.get(IWindowList.TRAY_WINDOW)!.hide()
|
||||||
@@ -169,6 +221,13 @@ export function createTray () {
|
|||||||
})
|
})
|
||||||
// toggleWindow()
|
// toggleWindow()
|
||||||
}
|
}
|
||||||
|
// click事件在Ubuntu上无法触发,Unity不支持(在Mac和Windows上可以触发)
|
||||||
|
// 需要使用 setContextMenu 设置菜单
|
||||||
|
else if (process.platform === "linux") {
|
||||||
|
createContextMenu()
|
||||||
|
tray!.setContextMenu(contextMenu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function createMenu() {
|
export function createMenu() {
|
||||||
if (process.env.NODE_ENV !== 'development') {
|
if (process.env.NODE_ENV !== 'development') {
|
||||||
|
|||||||
@@ -56,9 +56,7 @@ class LifeCycle {
|
|||||||
}
|
}
|
||||||
windowManager.create(IWindowList.TRAY_WINDOW)
|
windowManager.create(IWindowList.TRAY_WINDOW)
|
||||||
windowManager.create(IWindowList.SETTING_WINDOW)
|
windowManager.create(IWindowList.SETTING_WINDOW)
|
||||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
||||||
createTray()
|
createTray()
|
||||||
}
|
|
||||||
db.set('needReload', false)
|
db.set('needReload', false)
|
||||||
updateChecker()
|
updateChecker()
|
||||||
// 不需要阻塞
|
// 不需要阻塞
|
||||||
|
|||||||
@@ -271,8 +271,12 @@ export default class extends Vue {
|
|||||||
}
|
}
|
||||||
closeWindow () {
|
closeWindow () {
|
||||||
const window = BrowserWindow.getFocusedWindow()
|
const window = BrowserWindow.getFocusedWindow()
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
window!.hide()
|
||||||
|
} else {
|
||||||
window!.close()
|
window!.close()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
buildMenu () {
|
buildMenu () {
|
||||||
const _this = this
|
const _this = this
|
||||||
const template = [
|
const template = [
|
||||||
|
|||||||
Reference in New Issue
Block a user