From 69db584e8465cb455fdadb273bfb0b9f8246f656 Mon Sep 17 00:00:00 2001
From: chen fan <1490040662@qq.com>
Date: Wed, 9 Oct 2024 09:03:38 +0800
Subject: [PATCH] feat: tray
---
electron-builder.yml | 9 ++-
resources/iconTemplate.png | Bin 0 -> 235 bytes
src/main/index.ts | 73 ++++++++++++++++--
.../StreamConfigList/StreamConfigList.tsx | 2 +-
4 files changed, 76 insertions(+), 8 deletions(-)
create mode 100644 resources/iconTemplate.png
diff --git a/electron-builder.yml b/electron-builder.yml
index d4300c3..b19624f 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -9,9 +9,13 @@ files:
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
- '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
-
+asarUnpack:
+ - ./resources/iconTemplate.png
win:
executableName: fideo
+ extraFiles:
+ - from: "./resources/iconTemplate.png"
+ to: "Resources"
nsis:
oneClick: false
artifactName: ${name}-${version}.${ext}
@@ -33,6 +37,9 @@ mac:
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
notarize: false
identity: null
+ extraFiles:
+ - from: "./resources/iconTemplate.png"
+ to: "Resources"
dmg:
artifactName: ${name}-${version}-${arch}.${ext}
npmRebuild: false
diff --git a/resources/iconTemplate.png b/resources/iconTemplate.png
new file mode 100644
index 0000000000000000000000000000000000000000..9a907ea4452a31c3e47077eca3c353b6815d8b6f
GIT binary patch
literal 235
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|mU_B4hFJJ7
zog66CpupksG3DyXRg**2SC<_t6=|Gvay?JQh6c}D#ZO-AC@tUgv1+fpwEoG0MTJ6w
z7O$BL8mk%Dru+DrK4QEklW
}4gp()zs!zu|K6Z{=XL4VrnOuX=8D$5+RpHUU9#$5p5Qe(
ip47g$_RelF{r5}E)K+FLCE
literal 0
HcmV?d00001
diff --git a/src/main/index.ts b/src/main/index.ts
index 3cd4315..354e57a 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1,4 +1,14 @@
-import { app, shell, BrowserWindow, ipcMain, dialog, Notification } from 'electron'
+import {
+ app,
+ shell,
+ BrowserWindow,
+ ipcMain,
+ dialog,
+ Notification,
+ Tray,
+ Menu,
+ nativeImage
+} from 'electron'
import { join, resolve } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
@@ -106,8 +116,25 @@ const stopDownloadDepTimerWhenAllDownloadDepEnd = () => {
}
let win: BrowserWindow | null
+let tray: Tray | null
+
+function hideTaskbar() {
+ if (process.platform === 'darwin') {
+ app.dock.hide()
+ } else {
+ win?.setSkipTaskbar(true)
+ }
+}
+
+function showTaskbar() {
+ if (process.platform === 'darwin') {
+ app.dock.show()
+ } else {
+ win?.setSkipTaskbar(false)
+ }
+}
+
async function createWindow() {
- // Create the browser window.
const mainWindow = new BrowserWindow({
width: 900,
height: 670,
@@ -121,6 +148,7 @@ async function createWindow() {
devTools: is.dev
}
})
+
win = mainWindow
mainWindow.on('ready-to-show', () => {
@@ -134,7 +162,9 @@ async function createWindow() {
mainWindow.on('close', (e) => {
e.preventDefault()
- mainWindow.webContents.send(USER_CLOSE_WINDOW)
+
+ mainWindow.hide()
+ hideTaskbar()
})
// HMR for renderer base on electron-vite cli.
@@ -147,6 +177,36 @@ async function createWindow() {
await handleMakeSureDependenciesExist()
}
+async function createTray() {
+ const isChinese = ['zh', 'zh-CN', 'zh-TW', 'zh-HK'].includes(app.getLocale())
+ const iconPath = is.dev
+ ? join(__dirname, '../../resources/iconTemplate.png')
+ : join(process.resourcesPath, 'iconTemplate.png')
+
+ const icon = nativeImage.createFromPath(iconPath)
+ tray = new Tray(icon)
+ const contextMenu = Menu.buildFromTemplate([
+ {
+ label: isChinese ? '打开Fideo' : 'Open Fideo',
+ click: () => {
+ win?.show()
+ showTaskbar()
+ }
+ },
+ {
+ label: isChinese ? '退出' : 'Quit',
+ click: () => {
+ if (!isAllFfmpegProcessEnd()) {
+ win?.show()
+ }
+ win?.webContents.send(USER_CLOSE_WINDOW)
+ }
+ }
+ ])
+ tray.setToolTip('Fideo')
+ tray.setContextMenu(contextMenu)
+}
+
function showNotification(title: string, body: string) {
const notification = new Notification({
title,
@@ -308,6 +368,7 @@ app.whenReady().then(async () => {
})
await createWindow()
+ await createTray()
setTimeout(() => {
checkUpdate()
@@ -326,9 +387,9 @@ app.whenReady().then(async () => {
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
- if (process.platform !== 'darwin' || is.dev) {
- app.quit()
- }
+ // if (process.platform !== 'darwin' || is.dev) {
+ app.quit()
+ // }
})
// In this file you can include the rest of your app"s specific main process
diff --git a/src/renderer/src/components/StreamConfigList/StreamConfigList.tsx b/src/renderer/src/components/StreamConfigList/StreamConfigList.tsx
index b378ca8..17c2d4a 100644
--- a/src/renderer/src/components/StreamConfigList/StreamConfigList.tsx
+++ b/src/renderer/src/components/StreamConfigList/StreamConfigList.tsx
@@ -197,7 +197,7 @@ export default function StreamConfigList() {
return (
<>
{
-
+
{streamConfigList.map((streamConfig) => (