From 0869610372235b1bb2b53e2ea4b8db898e704c36 Mon Sep 17 00:00:00 2001 From: leejooy96 Date: Sat, 26 Apr 2025 22:13:48 +0900 Subject: [PATCH] fix: change the public path, fix image resource not loaded in production --- src/main/tray.ts | 3 ++- src/main/utils/Constants.ts | 6 +++++- .../public/images/vutron-logo.webp | Bin src/public/images/vutron-tray-icon.png | Bin 0 -> 1108 bytes vite.config.mts | 4 +++- 5 files changed, 10 insertions(+), 3 deletions(-) rename src/{renderer => }/public/images/vutron-logo.webp (100%) create mode 100644 src/public/images/vutron-tray-icon.png diff --git a/src/main/tray.ts b/src/main/tray.ts index 9ced3d3..a5284ec 100644 --- a/src/main/tray.ts +++ b/src/main/tray.ts @@ -1,6 +1,7 @@ import { app, screen, Menu, Tray, BrowserWindow } from 'electron' import Constants from './utils/Constants' import { debounce } from './utils/Util' +import { join } from 'path' let tray let trayOptions @@ -11,7 +12,7 @@ export function createTray(window: BrowserWindow, options) { trayOptions.menu = false } - tray = new Tray('buildAssets/icons/icon16.png') + tray = new Tray(join(Constants.PUBLIC_PATH, 'images/vutron-tray-icon.png')) tray.setToolTip(trayOptions.tooltip) if (trayOptions.menu) { const contextMenu = Menu.buildFromTemplate([ diff --git a/src/main/utils/Constants.ts b/src/main/utils/Constants.ts index 6afb0ba..2a08571 100644 --- a/src/main/utils/Constants.ts +++ b/src/main/utils/Constants.ts @@ -1,4 +1,4 @@ -import { join, dirname } from 'path' +import { join, dirname, resolve } from 'path' import { name, version, debug } from '../../../package.json' import { fileURLToPath } from 'url' @@ -21,6 +21,10 @@ export default class Constants { static IS_DEV_ENV = process.env.NODE_ENV === 'development' + static PUBLIC_PATH = Constants.IS_DEV_ENV + ? resolve(__dirname, '../../src/public') + : resolve(__dirname, '..') + // To show devtools at startup. It requires IS_DEV_ENV=true. // Note: For debugging purpose, window won't be closed if click elsewhere, if devtools is open. static IS_DEVTOOLS = true diff --git a/src/renderer/public/images/vutron-logo.webp b/src/public/images/vutron-logo.webp similarity index 100% rename from src/renderer/public/images/vutron-logo.webp rename to src/public/images/vutron-logo.webp diff --git a/src/public/images/vutron-tray-icon.png b/src/public/images/vutron-tray-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ae51b5126421e9f0f48814acdd77d0c0e8edb899 GIT binary patch literal 1108 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|T2doC(|mmy zw18|523AHP24;{FAY@>aVqgWc85q16rQz%#Mh&PMCI*J~Oa>OHnkXO*0v4nJa0`PlBg3pY5xV%QuQiw3qZOUY$~jP%-qzHM1_jnoV;SI3R@+x3M(KRB&@Hb09I0xZL1XF8=&Bv zUzDm~re~mMpk&9TprBw=l#*r@P?Wt5Z@Sn2DRmzV368|&p4rRy77T3YHG z80i}s=>k>g7FXt#Bv$C=6)QswftllyTAW;zSx}OhpQivaH!&%{w8U0P31kr*K-^i9 znTD__uNdkrpa=CqGWv#k2KsQbfm&@qqE`MznW;dVLFU^T+JIG}h(YbK(Fa+MHfYh=pKjkZpHxpupVUALAyuD(bk1F^h$jndxOD zPRv-Cq&#Ws){F8Rr6N3B>YJy9NgZ)3&^6Q4*}UIL;7A0A*C)Go?Zxjtw+YN=p6rwM z?2Ki(+M;@!d8b0Y&)Mu+w#(zw_xo$#y~_xH(*ImOZoksDzq|S63(tFhF3ptses1Nn zseYPEy?g`Ds94&oX?Co+{Br3wf$EiCw7s7kQIwTE`QV(aQoB^u1@0at(^CRp89fV=8-j<*jKy``|SJiY5C0^_dRF*mQ|j5tt`|heS5pPiB!w- z^e46R*NC5SaQ(jA==7XDOP;S#7Q5@RuuX2#zC#7ReE0aSd^uN;wRuwcM2$)_!#I2X&elG@kGW%GQBgs{>kyUe zx1Q8Ta=Pz1Sy%M>B#%TwB;%SOK{aFNJFPdaviz5~p74+>(Pf6k#@F2+Jj3SiZ&lsC z?!Dx`-&LPQf4AhH^*-XB8m(2)-g|mCi+bNruRmqm>#AMWiYf@Ivx{2y?mNrXyeDhf zExpeL-)}VAGfxUAEdF-ru%NPdcE{peO$V!01XM7c<{q&X7CyFLWF4ia>!|&hr12=WS|8WL-5Sm;VRzO@2w0%1(j% PpseNT>gTe~DWM4fm!pNO literal 0 HcmV?d00001 diff --git a/vite.config.mts b/vite.config.mts index f36552e..622747f 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -33,8 +33,10 @@ export default defineConfig(({ mode }) => { }, vite: { root: resolve('.'), + base: './', build: { assetsDir: '.', + publicDir: resolve('./src/public'), outDir: 'dist/main', rollupOptions: { external: ['electron', ...builtinModules] @@ -82,7 +84,7 @@ export default defineConfig(({ mode }) => { }, base: './', root: resolve('./src/renderer'), - publicDir: resolve('./src/renderer/public'), + publicDir: resolve('./src/public'), clearScreen: false, build: { sourcemap: isDevEnv,