Open noevermaurice opened 2 weeks ago
@noevermaurice
Could you try to use nativeImage
like this?
// main/background.ts
const resourcePath = process.env.NODE_ENV === 'production' ? process.resourcesPath : path.join(__dirname, '../resources');
const trayIcon = nativeImage.createFromPath(path.join(resourcePath, 'logoTemplate.png'));
tray = new Tray(trayIcon);
And, place logoTemplate.png to resources
folder.
@noevermaurice
And, make sure that preload.ts
is included by BrowserWindow:
mainWindow = createWindow('main', {
width: 1280,
height: 720,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
});
With the above two points, I was able to avoid the error you met :)
i have testet the code
Unable to load preload script: /Users/mnoever/Private_Projekte/Nextron_Projekte/checknotes-pro-nextron/app/preload.js (anonymous) @ node:electron/js2c/renderer_init:2 node:electron/js2c/renderer_init:2 Error: Cannot find module '/Users/mnoever/Private_Projekte/Nextron_Projekte/checknotes-pro-nextron/app/preload.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1152:15) at a._resolveFilename (node:electron/js2c/renderer_init:2:2669) at Module._load (node:internal/modules/cjs/loader:993:27) at c._load (node:electron/js2c/node_init:2:17025) at s._load (node:electron/js2c/renderer_init:2:31018) at node:electron/js2c/renderer_init:2:33087 at node:electron/js2c/renderer_init:2:33556 at _electron_webpack_init (node:electron/js2c/renderer_init:2:33560) at node:electron/js2c/renderer_init:2:33683 at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:398:7) (anonymous) @ node:electron/js2c/renderer_init:2 node:electron/js2c/renderer_init:2 Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security Policy set or a policy with "unsafe-eval" enabled. This exposes users of this app to unnecessary security risks.
For more information and help, consult https://electronjs.org/docs/tutorial/security. This warning will not show up once the app is packaged.
i get on yarn dev this errrors and still white window
mainWindow = createWindow('main', { width: 1280, height: 720, webPreferences: { nodeIntegration: true, preload: path.join(__dirname, 'preload.js'), }, });
@noevermaurice
You should investigate Cannot find module '/Users/mnoever/Private_Projekte/Nextron_Projekte/checknotes-pro-nextron/app/preload.js
(Ensure that preload.js in your "app" directory)
@noevermaurice
I found the problem when production build.
Please change the path from home.html
to home
:
if (isProd) {
await mainWindow.loadURL('app://./home') // <= here
} else {
const port = process.argv[2]
await mainWindow.loadURL(`http://localhost:${port}/home`)
mainWindow.webContents.openDevTools()
}
@noevermaurice Any updates? If you have troubles, feel free to ask me :)
i have testet my producation app in the network tab i get are red home.hmtl with size of 0B in dev mode the network tab is okay
this is my background.ts
my next js config
my package.json
is there a wrong configuration for dev and build with electron 31.
on yarn dev i get this errors
(node:72375) UnhandledPromiseRejectionWarning: Error: Failed to load image from path '/Users/mnoever/Private_Projekte/Nextron_Projekte/checknotes-pro-nextron/app/logoTemplate.png' at App.createMainWindow (/Users/mnoever/Private_Projekte/Nextron_Projekte/checknotes-pro-nextron/app/background.js:6716:10) (Use
Electron --trace-warnings ...
to show where the warning was created) (node:72375) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) [72375:0618/122139.244061:ERROR:CONSOLE(1)] "Request Autofill.enable failed. {"code":-32601,"message":"'Autofill.enable' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1) [72375:0618/122139.244095:ERROR:CONSOLE(1)] "Request Autofill.setAddresses failed. {"code":-32601,"message":"'Autofill.setAddresses' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)@saltyshiomix