diff --git a/package.json b/package.json index 7023ac3b5..e04666cee 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ ], "devDependencies": { "@types/chrome": "0.0.74", + "@types/extract-zip": "1.6.2", "@types/gsap": "1.19.2", "@types/leveldown": "4.0.0", "@types/levelup": "3.1.0", @@ -72,6 +73,7 @@ "electron-builder": "20.28.4", "electron-react-devtools": "0.5.3", "electron-updater": "3.1.2", + "extract-zip": "1.6.7", "gsap": "2.0.2", "levelup": "3.1.1", "mobx": "5.5.0", diff --git a/src/main/index.ts b/src/main/index.ts index 72336059f..a57b4413e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -12,6 +12,7 @@ import { runExtensionsService, runWebRequestService, } from '@/services/main'; +import extract from 'extract-zip'; ipcMain.setMaxListeners(0); @@ -71,6 +72,18 @@ if (shouldQuit) { } } + if (!existsSync(resolve(getPath('extensions'), 'uBlock0.chromium'))) { + extract( + resolve(__dirname, 'static/extensions/ublock.zip'), + { dir: getPath('extensions') }, + err => { + if (err) console.error(err); + + loadExtensions(mainWindow); + }, + ); + } + mainWindow = createWindow(); loadExtensions(mainWindow); diff --git a/src/shared/utils/main/extensions.ts b/src/shared/utils/main/extensions.ts index 9d9cf290d..d13748e02 100644 --- a/src/shared/utils/main/extensions.ts +++ b/src/shared/utils/main/extensions.ts @@ -97,6 +97,10 @@ export const loadExtensions = async (window: BrowserWindow) => { const id = dir; + if (global.extensions[id]) { + return; + } + global.extensions[id] = manifest; const extensionStoragePath = getPath( diff --git a/src/shared/utils/main/window.ts b/src/shared/utils/main/window.ts index 6db8551c4..264d16c29 100644 --- a/src/shared/utils/main/window.ts +++ b/src/shared/utils/main/window.ts @@ -1,6 +1,7 @@ import { BrowserWindow, app } from 'electron'; import { readFileSync, writeFileSync, existsSync } from 'fs'; -import { join } from 'path'; +import { join, resolve } from 'path'; +import os from 'os'; import { getPath } from '@/utils/paths'; import { WindowState } from '@/interfaces/main'; @@ -22,7 +23,7 @@ export const createWindow = () => { } let windowData: Electron.BrowserWindowConstructorOptions = { - frame: process.env.ENV === 'dev', + frame: process.env.ENV === 'dev' || os.platform() === 'darwin', minWidth: 400, minHeight: 450, width: 900, @@ -32,6 +33,7 @@ export const createWindow = () => { webPreferences: { plugins: true, }, + icon: resolve(__dirname, 'static/app-icons/icon.png'), }; // Merge bounds from the last window state to the current window options. @@ -67,8 +69,6 @@ export const createWindow = () => { writeFileSync(windowDataPath, JSON.stringify(windowState)); }); - window.webContents.openDevTools({ mode: 'detach' }); - if (process.env.ENV === 'dev') { window.webContents.openDevTools({ mode: 'detach' }); window.loadURL('http://localhost:8080/app.html'); diff --git a/static/extensions/ublock.zip.REMOVED.git-id b/static/extensions/ublock.zip.REMOVED.git-id new file mode 100644 index 000000000..c8be52aad --- /dev/null +++ b/static/extensions/ublock.zip.REMOVED.git-id @@ -0,0 +1 @@ +341023d54ef7964ebd56bc4bbd54931d432d4220 \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index ae81e9893..39e23b0f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -43,6 +43,10 @@ version "1.2.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86" +"@types/extract-zip@1.6.2": + version "1.6.2" + resolved "https://registry.yarnpkg.com/@types/extract-zip/-/extract-zip-1.6.2.tgz#5c7eb441c41136167a42b88b64051e6260c29e86" + "@types/filesystem@*": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.29.tgz#ee3748eb5be140dcf980c3bd35f11aec5f7a3748" @@ -1908,7 +1912,7 @@ extglob@^2.0.4: snapdragon "^0.8.1" to-regex "^3.0.1" -extract-zip@^1.0.3: +extract-zip@1.6.7, extract-zip@^1.0.3: version "1.6.7" resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-1.6.7.tgz#a840b4b8af6403264c8db57f4f1a74333ef81fe9" dependencies: