@@ -8,10 +8,11 @@ const { setupMenu } = require('./menu')
88const { buildChromeContextMenu } = require ( 'electron-chrome-context-menu' )
99
1010// https://www.electronforge.io/config/plugins/webpack#main-process-code
11+ const ROOT_DIR = path . join ( __dirname , '../../../../' ) ;
1112const PATHS = {
12- EXTENSIONS : path . join ( __dirname , 'extensions' ) ,
1313 WEBUI : path . join ( __dirname , 'ui' ) ,
1414 PRELOAD : path . join ( __dirname , '../renderer/browser/preload.js' ) ,
15+ LOCAL_EXTENSIONS : path . join ( ROOT_DIR , 'extensions' ) ,
1516}
1617
1718let webuiExtensionId
@@ -26,6 +27,7 @@ const manifestExists = async (dirPath) => {
2627 }
2728}
2829
30+ const VERSION_REGEX = / ^ (?: \d + \. ? ) { 2 , 4 } _ \d + $ / // e.g. 2024.9.29.1273_0
2931async function loadExtensions ( session , extensionsPath ) {
3032 const subDirectories = await fs . readdir ( extensionsPath , {
3133 withFileTypes : true ,
@@ -45,10 +47,10 @@ async function loadExtensions(session, extensionsPath) {
4547 withFileTypes : true ,
4648 } )
4749
48- const versionDirPath =
49- extSubDirs . length === 1 && extSubDirs [ 0 ] . isDirectory ( )
50- ? path . join ( extPath , extSubDirs [ 0 ] . name )
51- : null
50+ const versionDir = extSubDirs . find (
51+ ( dir ) => dir . isDirectory ( ) && dir . name . match ( VERSION_REGEX )
52+ ) ?. name
53+ const versionDirPath = path . join ( extPath , versionDir )
5254
5355 if ( await manifestExists ( versionDirPath ) ) {
5456 return versionDirPath
@@ -231,7 +233,15 @@ class Browser {
231233 const webuiExtension = await this . session . loadExtension ( PATHS . WEBUI )
232234 webuiExtensionId = webuiExtension . id
233235
234- await loadExtensions ( this . session , PATHS . EXTENSIONS )
236+ const extensionsPath = app . isPackaged
237+ ? path . join ( app . getPath ( 'userData' ) , 'Extensions' )
238+ : PATHS . LOCAL_EXTENSIONS
239+ console . log ( `Browser.init: loading extensions from ${ extensionsPath } ` )
240+ try {
241+ await loadExtensions ( this . session , extensionsPath )
242+ } catch ( error ) {
243+ console . error ( 'Failed to load extensions\n' , error )
244+ }
235245
236246 this . createInitialWindow ( )
237247 }
0 commit comments