Skip to content

Commit 25de153

Browse files
committed
chore: copy some changes from mv3 branch
1 parent a869186 commit 25de153

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

packages/shell/browser/main.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ const { setupMenu } = require('./menu')
88
const { 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, '../../../../');
1112
const 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

1718
let 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
2931
async 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
}

packages/shell/browser/ui/new-tab.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ <h1>New Tab</h1>
2222
>https://github.com/samuelmaddock/electron-browser-shell</a
2323
>
2424
</li>
25-
<li><a href="https://app.getmetastream.com/">https://app.getmetastream.com/</a></li>
25+
<li><a href="https://permission.site">https://permission.site</a></li>
26+
<li><a href="https://samuelmaddock.com">https://samuelmaddock.com</a></li>
2627
</ul>
2728
</body>
2829
</html>

packages/shell/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"private": true,
1616
"dependencies": {
1717
"electron-chrome-context-menu": "^1.0.1",
18-
"electron-chrome-extensions": "^3.10.1",
18+
"electron-chrome-extensions": "^4.0.0",
1919
"electron-squirrel-startup": "^1.0.0"
2020
},
2121
"devDependencies": {

0 commit comments

Comments
 (0)