Skip to content

Commit

Permalink
✨ Feature: add dock menu and appbar menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 5, 2023
1 parent 107e8ae commit 19e1191
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 30 deletions.
100 changes: 72 additions & 28 deletions src/main/apis/app/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,79 @@ import { T } from '~/main/i18n'
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
import { buildPicBedListMenu } from '~/main/events/remotes/menu'
let contextMenu: Menu | null
let menu: Menu | null
let tray: Tray | null

export function createMenu () {
const submenu = buildPicBedListMenu()
const appMenu = Menu.buildFromTemplate([
{
label: 'PicList',
submenu: [
{
label: T('ABOUT'),
click () {
dialog.showMessageBox({
title: 'PicList',
message: 'PicList',
detail: `Version: ${pkg.version}\nAuthor: Kuingsmile\nGithub: https://github.com/Kuingsmile/PicList`
})
}
},
{
label: T('OPEN_MAIN_WINDOW'),
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: T('OPEN_UPDATE_HELPER'),
type: 'checkbox',
checked: db.get('settings.showUpdateTip'),
click () {
const value = db.get('settings.showUpdateTip')
db.set('settings.showUpdateTip', !value)
}
},
{
label: T('PRIVACY_AGREEMENT'),
click () {
privacyManager.show(false)
}
},
{
label: T('RELOAD_APP'),
click () {
app.relaunch()
app.exit(0)
}
}
]
},
{
label: T('CHOOSE_DEFAULT_PICBED'),
type: 'submenu',
// @ts-ignore
submenu
},
{
label: T('QUIT'),
submenu: [
{
label: T('QUIT'),
role: 'quit'
}
]
}
])
Menu.setApplicationMenu(appMenu)
}

export function createContextMenu () {
if (process.platform === 'darwin' || process.platform === 'win32') {
const submenu = buildPicBedListMenu()
Expand Down Expand Up @@ -250,33 +321,6 @@ export function createTray () {
}
}

export function createMenu () {
if (process.env.NODE_ENV !== 'development') {
const template = [{
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' },
{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click () {
app.quit()
}
}
]
}]
// @ts-ignore
menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
}

const toggleWindow = (bounds: IBounds) => {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
if (trayWindow.isVisible()) {
Expand Down
21 changes: 20 additions & 1 deletion src/main/lifeCycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
app,
globalShortcut,
protocol,
Notification
Notification,
Menu
} from 'electron'
import {
createProtocol
Expand Down Expand Up @@ -40,6 +41,7 @@ import { remoteNoticeHandler } from 'apis/app/remoteNotice'
import { manageIpcList } from '../manage/events/ipcList'
import getManageApi from '../manage/Main'
import UpDownTaskQueue from '../manage/datastore/upDownTaskQueue'
import { T } from '~/main/i18n'
const isDevelopment = process.env.NODE_ENV !== 'production'

const handleStartUpFiles = (argv: string[], cwd: string) => {
Expand Down Expand Up @@ -89,6 +91,23 @@ class LifeCycle {
}
windowManager.create(IWindowList.TRAY_WINDOW)
windowManager.create(IWindowList.SETTING_WINDOW)
if (process.platform === 'darwin') {
app.dock.setMenu(
Menu.buildFromTemplate([
{
label: T('OPEN_MAIN_WINDOW'),
click () {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)
settingWindow!.show()
settingWindow!.focus()
if (windowManager.has(IWindowList.MINI_WINDOW)) {
windowManager.get(IWindowList.MINI_WINDOW)!.hide()
}
}
}
])
)
}
createTray()
db.set('needReload', false)
updateChecker()
Expand Down
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const config = {
mac: {
icon: 'build/icons/icon.icns',
extendInfo: {
LSUIElement: 1
LSUIElement: 0
},
target: [{
target: 'dmg',
Expand Down

0 comments on commit 19e1191

Please sign in to comment.