@@ -4,44 +4,82 @@ const { app, BrowserWindow } = require('electron');
44const path = require ( 'path' ) ;
55const fs = require ( 'fs' ) ;
66
7- // Get the correct path for the .next directory
87const nextDir = path . join ( process . resourcesPath , '.next' ) ;
98
10- // Check if production build exists
119const buildIdPath = path . join ( nextDir , 'BUILD_ID' ) ;
1210if ( ! fs . existsSync ( buildIdPath ) ) {
1311 console . error ( 'ERROR: No Next.js production build found.' ) ;
1412 console . error ( 'Expected build at:' , nextDir ) ;
1513 process . exit ( 1 ) ;
1614}
1715
18- // For AppImage, we need to ensure Node.js can find all dependencies
19- // Add the resources path to NODE_PATH
20- process . env . NODE_PATH = `${ process . resourcesPath } /app/node_modules:${ process . resourcesPath } /.next/static/chunks` ;
16+ if ( process . platform === 'win32' ) {
17+ const nodeModulesPath = path . join ( process . resourcesPath , 'app' , 'node_modules' ) ;
18+ const nextStaticPath = path . join ( nextDir , 'static' , 'chunks' ) ;
19+
20+ process . env . NODE_PATH = [
21+ nodeModulesPath ,
22+ nextStaticPath ,
23+ process . env . NODE_PATH || ''
24+ ] . join ( path . delimiter ) ;
25+
26+ require ( 'module' ) . Module . _nodeModulePaths ( nodeModulesPath ) ;
27+ require ( 'module' ) . Module . _nodeModulePaths ( nextStaticPath ) ;
28+ } else {
29+ process . env . NODE_PATH = `${ process . resourcesPath } /app/node_modules:${ process . resourcesPath } /.next/static/chunks` ;
30+ }
31+
2132require ( 'module' ) . Module . _initPaths ( ) ;
2233
34+ if ( process . platform === 'win32' ) {
35+ const requiredNextFiles = [
36+ path . join ( process . resourcesPath , 'app' , 'node_modules' , 'next' , 'dist' , 'compiled' , 'next-server' , 'app-page.runtime.prod.js' ) ,
37+ path . join ( process . resourcesPath , 'app' , 'node_modules' , 'react' , 'jsx-runtime.js' )
38+ ] ;
39+
40+ for ( const file of requiredNextFiles ) {
41+ if ( ! fs . existsSync ( file ) ) {
42+ console . warn ( 'Missing file (may be packed in asar):' , file ) ;
43+
44+ const alternativePaths = [
45+ path . join ( process . resourcesPath , 'app.asar.unpacked' , 'node_modules' , 'next' , 'dist' , 'compiled' , 'next-server' , 'app-page.runtime.prod.js' ) ,
46+ path . join ( __dirname , 'node_modules' , 'next' , 'dist' , 'compiled' , 'next-server' , 'app-page.runtime.prod.js' ) ,
47+ ] ;
48+
49+ for ( const altPath of alternativePaths ) {
50+ if ( fs . existsSync ( altPath ) ) {
51+ console . log ( 'Found alternative at:' , altPath ) ;
52+ break ;
53+ }
54+ }
55+ }
56+ }
57+ }
58+
2359const nextApp = next ( {
2460 dev : false ,
2561 dir : process . resourcesPath ,
2662 conf : {
2763 distDir : '.next' ,
28- // Disable features that require write access
2964 generateBuildId : ( ) => 'static-build' ,
30- // Disable webpack watching
3165 webpack : ( config ) => {
3266 config . watch = false ;
67+ if ( process . platform === 'win32' ) {
68+ config . resolve = config . resolve || { } ;
69+ config . resolve . fallback = config . resolve . fallback || { } ;
70+ config . resolve . fallback . path = require . resolve ( 'path-browserify' ) ;
71+ }
3372 return config ;
3473 } ,
3574 experimental : {
36- // Increase timeout for static generation
37- staticPageGenerationTimeout : 1000
75+ staticPageGenerationTimeout : 1000 ,
76+ esmExternals : false
3877 }
3978 }
4079} ) ;
4180
4281const handle = nextApp . getRequestHandler ( ) ;
4382
44- // Ensure single instance
4583if ( ! app . requestSingleInstanceLock ( ) ) {
4684 app . quit ( ) ;
4785}
@@ -57,14 +95,14 @@ function createWindow() {
5795 contextIsolation : true ,
5896 nodeIntegration : false ,
5997 enableRemoteModule : false ,
98+ webSecurity : true ,
99+ allowRunningInsecureContent : false
60100 } ,
61- // Disable font warnings
62101 show : false
63102 } ) ;
64103
65104 mainWindow . setMenuBarVisibility ( false ) ;
66105
67- // Wait for window to be ready before showing to avoid font warnings
68106 mainWindow . once ( 'ready-to-show' , ( ) => {
69107 mainWindow . show ( ) ;
70108 } ) ;
@@ -76,7 +114,6 @@ function createWindow() {
76114 } ) ;
77115}
78116
79- // Initialize Next.js and create server
80117nextApp . prepare ( ) . then ( ( ) => {
81118 server = createServer ( ( req , res ) => {
82119 return handle ( req , res ) ;
@@ -90,6 +127,8 @@ nextApp.prepare().then(() => {
90127
91128 console . log ( '> Production server ready on http://localhost:3000' ) ;
92129 console . log ( '> Serving from:' , nextDir ) ;
130+ console . log ( '> Platform:' , process . platform ) ;
131+ console . log ( '> NODE_PATH:' , process . env . NODE_PATH ) ;
93132 app . whenReady ( ) . then ( createWindow ) ;
94133 } ) ;
95134} ) . catch ( err => {
0 commit comments