mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-06 16:07:06 +08:00
✨ Feature: 为Linux系统适配桌面图标栏(Tray) (#603)
This commit is contained in:
@@ -19,14 +19,15 @@ import { handleCopyUrl } from '~/main/utils/common'
|
|||||||
let contextMenu: Menu | null
|
let contextMenu: Menu | null
|
||||||
let menu: Menu | null
|
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,
|
||||||
type: 'radio',
|
type: 'radio',
|
||||||
checked: db.get('picBed.current') === item.type,
|
checked: db.get('picBed.current') === item.type,
|
||||||
click () {
|
click() {
|
||||||
picgo.saveConfig({
|
picgo.saveConfig({
|
||||||
'picBed.current': item.type,
|
'picBed.current': item.type,
|
||||||
'picBed.uploader': item.type
|
'picBed.uploader': item.type
|
||||||
@@ -40,7 +41,7 @@ export function createContextMenu () {
|
|||||||
contextMenu = Menu.buildFromTemplate([
|
contextMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '关于',
|
label: '关于',
|
||||||
click () {
|
click() {
|
||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
title: 'PicGo',
|
title: 'PicGo',
|
||||||
message: 'PicGo',
|
message: 'PicGo',
|
||||||
@@ -50,7 +51,7 @@ export function createContextMenu () {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '打开详细窗口',
|
label: '打开详细窗口',
|
||||||
click () {
|
click() {
|
||||||
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||||
settingWindow!.show()
|
settingWindow!.show()
|
||||||
settingWindow!.focus()
|
settingWindow!.focus()
|
||||||
@@ -70,14 +71,14 @@ export function createContextMenu () {
|
|||||||
label: '打开更新助手',
|
label: '打开更新助手',
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
checked: db.get('settings.showUpdateTip'),
|
checked: db.get('settings.showUpdateTip'),
|
||||||
click () {
|
click() {
|
||||||
const value = db.get('settings.showUpdateTip')
|
const value = db.get('settings.showUpdateTip')
|
||||||
db.set('settings.showUpdateTip', !value)
|
db.set('settings.showUpdateTip', !value)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '重启应用',
|
label: '重启应用',
|
||||||
click () {
|
click() {
|
||||||
app.relaunch()
|
app.relaunch()
|
||||||
app.exit(0)
|
app.exit(0)
|
||||||
}
|
}
|
||||||
@@ -88,11 +89,62 @@ export function createContextMenu () {
|
|||||||
label: '退出'
|
label: '退出'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
}
|
||||||
|
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()
|
||||||
@@ -168,9 +220,16 @@ 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') {
|
||||||
const template = [{
|
const template = [{
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
@@ -185,7 +244,7 @@ export function createMenu () {
|
|||||||
{
|
{
|
||||||
label: 'Quit',
|
label: 'Quit',
|
||||||
accelerator: 'CmdOrCtrl+Q',
|
accelerator: 'CmdOrCtrl+Q',
|
||||||
click () {
|
click() {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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