Skip to content

Commit

Permalink
feat: tray
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Oct 9, 2024
1 parent adebf4b commit 69db584
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
9 changes: 8 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
Binary file added resources/iconTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 67 additions & 6 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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,
Expand All @@ -121,6 +148,7 @@ async function createWindow() {
devTools: is.dev
}
})

win = mainWindow

mainWindow.on('ready-to-show', () => {
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -308,6 +368,7 @@ app.whenReady().then(async () => {
})

await createWindow()
await createTray()

setTimeout(() => {
checkUpdate()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default function StreamConfigList() {
return (
<>
{
<div className="stream-config-list flex flex-col gap-[12px] p-[24px] overflow-y-auto h-[calc(100vh-80px)]">
<div className="show-scrollbar flex flex-col gap-[12px] p-[24px] overflow-y-auto h-[calc(100vh-80px)]">
{streamConfigList.map((streamConfig) => (
<div
key={streamConfig.title}
Expand Down

0 comments on commit 69db584

Please sign in to comment.