diff --git a/package.json b/package.json index 86c4a7cc..704e6c18 100644 --- a/package.json +++ b/package.json @@ -165,6 +165,7 @@ "asar": true, "asarUnpack": "**\\*.{node,dll}", "files": [ + "assets/icons/tray", "dist", "node_modules", "package.json" diff --git a/src/main/main.ts b/src/main/main.ts index 6c9f1e26..07aa68fd 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,7 +9,7 @@ import { configStorage } from './config'; import { autoUpdater } from 'electron-updater'; import log from 'electron-log'; import createMenu from './menu'; -import { resolveHtmlPath, File } from './util'; +import { resolveHtmlPath, getAssetPath, File } from './util'; import createFileWatcher from './modules/FileWatcher'; import { createTray } from './tray'; import './modules/Ipc'; @@ -52,13 +52,6 @@ const handleMove = () => { } const createWindow = async() => { - const RESOURCES_PATH = app.isPackaged - ? path.join(process.resourcesPath, 'assets') - : path.join(__dirname, '../../assets'); - - const getAssetPath = (...paths: string[]): string => { - return path.resolve(RESOURCES_PATH, ...paths); - }; mainWindow = new BrowserWindow({ width: 1280, height: 1000, diff --git a/src/main/tray.ts b/src/main/tray.ts index 08ef6a9e..73b007f1 100644 --- a/src/main/tray.ts +++ b/src/main/tray.ts @@ -1,6 +1,7 @@ import { app, Tray, Menu } from 'electron'; import { mainWindow, createWindow } from './main'; import { configStorage } from './config'; +import { getAssetPath } from './util'; import { setFile } from './modules/File'; let tray; @@ -56,8 +57,8 @@ function getMenuTemplate(files) { function createTray(create) { try { + tray?.destroy(); if (!create) { - tray?.destroy(); if (app.dock) { app.dock.show(); } @@ -67,7 +68,7 @@ function createTray(create) { const files = configStorage.get('files') as File[] || []; const menu = Menu.buildFromTemplate(getMenuTemplate(files)); - tray = new Tray('./assets/icons/tray/tray.png'); + tray = new Tray(getAssetPath('icons/tray/tray.png')); tray.setContextMenu(menu); tray.on('click', (event) => { if (mainWindow) { diff --git a/src/main/util.ts b/src/main/util.ts index 3388aad9..1b0ec16e 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -1,5 +1,14 @@ import { URL } from 'url'; import path from 'path'; +import { app } from 'electron'; + +const RESOURCES_PATH = app.isPackaged + ? path.join(process.resourcesPath, 'assets') + : path.join(__dirname, '../../assets'); + +export const getAssetPath = (...paths: string[]): string => { + return path.resolve(RESOURCES_PATH, ...paths); +}; export function resolveHtmlPath(htmlFileName: string): string { try {