diff --git a/app/main.ts b/app/main.ts index 38cbaf7..0188915 100644 --- a/app/main.ts +++ b/app/main.ts @@ -1,9 +1,9 @@ import path from 'node:path' import process from 'node:process' import { ElectronAdapter } from '@nailyjs/electron' -import { app, BrowserWindow, Menu } from 'electron' +import { app, BrowserWindow, ipcMain, Menu } from 'electron' import { app as rpc } from '../backend/main' -import { version } from '../package.json' +import { author, productName, version } from '../package.json' let __dirname: string = globalThis.__dirname if (!__dirname) @@ -14,15 +14,21 @@ app.whenReady().then(async () => { width: 1200, height: 800, minWidth: 400, + frame: false, webPreferences: { preload: path.resolve(decodeURIComponent(__dirname), './preload.cjs'), }, }) + ipcMain.on('mld:close-window', () => win.close()) + ipcMain.on('mld:minimize-window', () => win.minimize()) + ipcMain.on('mld:maximize-window', () => win.maximize()) + ipcMain.handle('mld:get-platform', () => process.platform) + app.setAboutPanelOptions({ - applicationName: '网易云音乐下崽器', + applicationName: productName, applicationVersion: version, - authors: ['Naily Zero (https://naily.cc)'], + authors: [author], version, }) @@ -61,15 +67,14 @@ app.whenReady().then(async () => { ]), ) + // 设置naily后端适配器为 Electron await rpc.setBackendAdapter(ElectronAdapter) .getRpcMethodExecutor() .setBackendAdapter(rpc.getBackendAdapter() as ElectronAdapter) .setup() - if (process.env.VITE_DEV_SERVER_URL) { + if (process.env.VITE_DEV_SERVER_URL) win.loadURL(process.env.VITE_DEV_SERVER_URL) - } - else { + else win.loadFile(path.join(__dirname, '../dist/frontend/index.html')) - } }) diff --git a/app/preload.ts b/app/preload.ts index 31fec3a..796c2c1 100644 --- a/app/preload.ts +++ b/app/preload.ts @@ -5,6 +5,26 @@ const request: InvokeFn = (channel: string, ...args: any[]) => { return electron.ipcRenderer.invoke(channel, ...args) } +function closeWindow() { + electron.ipcRenderer.send('mld:close-window') +} + +function minimizeWindow() { + electron.ipcRenderer.send('mld:minimize-window') +} + +function maximizeWindow() { + electron.ipcRenderer.send('mld:maximize-window') +} + +function getPlatform(): Promise { + return electron.ipcRenderer.invoke('mld:get-platform') +} + electron.contextBridge.exposeInMainWorld('electron' as Exclude, { request, + closeWindow, + minimizeWindow, + maximizeWindow, + getPlatform, } as GlobalElectron) diff --git a/frontend/components/default-header.vue b/frontend/components/default-header.vue index aeb9f9b..a4e03b5 100644 --- a/frontend/components/default-header.vue +++ b/frontend/components/default-header.vue @@ -5,8 +5,11 @@ const { t } = useI18n() const { y } = useWindowScroll() const { width: windowWidth } = useWindowSize() const { toggleLocales } = useToggleLocale() +const { isElectron, platform } = useEnvironment() const route = useRoute() +const headerRef = ref(null) + interface NavItem { icon: string text: string @@ -21,12 +24,33 @@ const nav = computed((): NavItem[] => ([ ])) const currentLocation = computed(() => nav.value.find(item => item.to === route.name)) +const electronOperations = computed(() => isElectron.value + ? [ + { + icon: 'i-ph-arrows-in-simple', + text: t('common.minimize'), + onClick: () => window.electron.minimizeWindow(), + }, + { + icon: 'i-ph-arrows-out-simple', + text: t('common.maximize'), + onClick: () => window.electron.maximizeWindow(), + }, + { + icon: 'i-ph-sign-out', + text: t('common.exit'), + onClick: () => window.electron.closeWindow(), + }, + ] + : []) + const leftButton = computed(() => [ { icon: 'i-ph-music-note-duotone', text: t('nav.music-player'), onClick: () => void 0, }, + ...(platform.value === 'darwin' ? electronOperations.value : []), ]) const rightButton = computed(() => [ { @@ -39,15 +63,17 @@ const rightButton = computed(() => [ text: t('nav.switch-language'), onClick: () => toggleLocales(), }, + ...(platform.value !== 'darwin' ? electronOperations.value : []), ])