Skip to content

Commit

Permalink
chore: copy some changes from mv3 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Nov 11, 2024
1 parent a869186 commit 25de153
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
22 changes: 16 additions & 6 deletions packages/shell/browser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const { setupMenu } = require('./menu')
const { buildChromeContextMenu } = require('electron-chrome-context-menu')

// https://www.electronforge.io/config/plugins/webpack#main-process-code
const ROOT_DIR = path.join(__dirname, '../../../../');
const PATHS = {
EXTENSIONS: path.join(__dirname, 'extensions'),
WEBUI: path.join(__dirname, 'ui'),
PRELOAD: path.join(__dirname, '../renderer/browser/preload.js'),
LOCAL_EXTENSIONS: path.join(ROOT_DIR, 'extensions'),
}

let webuiExtensionId
Expand All @@ -26,6 +27,7 @@ const manifestExists = async (dirPath) => {
}
}

const VERSION_REGEX = /^(?:\d+\.?){2,4}_\d+$/ // e.g. 2024.9.29.1273_0
async function loadExtensions(session, extensionsPath) {
const subDirectories = await fs.readdir(extensionsPath, {
withFileTypes: true,
Expand All @@ -45,10 +47,10 @@ async function loadExtensions(session, extensionsPath) {
withFileTypes: true,
})

const versionDirPath =
extSubDirs.length === 1 && extSubDirs[0].isDirectory()
? path.join(extPath, extSubDirs[0].name)
: null
const versionDir = extSubDirs.find(
(dir) => dir.isDirectory() && dir.name.match(VERSION_REGEX)
)?.name
const versionDirPath = path.join(extPath, versionDir)

if (await manifestExists(versionDirPath)) {
return versionDirPath
Expand Down Expand Up @@ -231,7 +233,15 @@ class Browser {
const webuiExtension = await this.session.loadExtension(PATHS.WEBUI)
webuiExtensionId = webuiExtension.id

await loadExtensions(this.session, PATHS.EXTENSIONS)
const extensionsPath = app.isPackaged
? path.join(app.getPath('userData'), 'Extensions')
: PATHS.LOCAL_EXTENSIONS
console.log(`Browser.init: loading extensions from ${extensionsPath}`)
try {
await loadExtensions(this.session, extensionsPath)
} catch (error) {
console.error('Failed to load extensions\n', error)
}

this.createInitialWindow()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/shell/browser/ui/new-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ <h1>New Tab</h1>
>https://github.com/samuelmaddock/electron-browser-shell</a
>
</li>
<li><a href="https://app.getmetastream.com/">https://app.getmetastream.com/</a></li>
<li><a href="https://permission.site">https://permission.site</a></li>
<li><a href="https://samuelmaddock.com">https://samuelmaddock.com</a></li>
</ul>
</body>
</html>
2 changes: 1 addition & 1 deletion packages/shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"private": true,
"dependencies": {
"electron-chrome-context-menu": "^1.0.1",
"electron-chrome-extensions": "^3.10.1",
"electron-chrome-extensions": "^4.0.0",
"electron-squirrel-startup": "^1.0.0"
},
"devDependencies": {
Expand Down

0 comments on commit 25de153

Please sign in to comment.