Skip to content

Commit 6b8c258

Browse files
committed
escape the browser wip
* converting from Svelte to Mithril * convertnig from WebExtension to Electron
1 parent 3b211ca commit 6b8c258

File tree

426 files changed

+23171
-254380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

426 files changed

+23171
-254380
lines changed

app.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const { app, BrowserWindow } = require("electron")
2+
const path = require("path")
3+
4+
// Live Reload
5+
require("electron-reload")(__dirname, {
6+
electron: path.join(__dirname, "node_modules", ".bin", "electron"),
7+
awaitWriteFinish: true
8+
})
9+
10+
const createWindow = () => {
11+
// Create the browser window.
12+
const mainWindow = new BrowserWindow({
13+
width: 800,
14+
height: 600,
15+
webPreferences: {
16+
nodeIntegration: true,
17+
contextIsolation: false
18+
}
19+
})
20+
21+
// and load the index.html of the app.
22+
mainWindow.loadFile(path.join(__dirname, "ui/index.html"))
23+
24+
// Open the DevTools.
25+
mainWindow.webContents.openDevTools()
26+
27+
mainWindow.webContents.setWindowOpenHandler(details => {
28+
console.log("cd", details)
29+
return { action: "allow" }
30+
})
31+
}
32+
33+
// This method will be called when Electron has finished
34+
// initialization and is ready to create browser windows.
35+
// Some APIs can only be used after this event occurs.
36+
app.on("ready", createWindow)
37+
38+
// Quit when all windows are closed.
39+
app.on("window-all-closed", () => {
40+
// On OS X it is common for applications and their menu bar
41+
// to stay active until the user quits explicitly with Cmd + Q
42+
if (process.platform !== "darwin") {
43+
app.quit()
44+
}
45+
})
46+
47+
app.on("activate", () => {
48+
// On OS X it"s common to re-create a window in the app when the
49+
// dock icon is clicked and there are no other windows open.
50+
if (BrowserWindow.getAllWindows().length === 0) {
51+
createWindow()
52+
}
53+
})
54+
55+
// In this file you can include the rest of your app"s specific main process
56+
// code. You can also put them in separate files and import them here.

desktop/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
main.bundle.js
2+
package-lock.json
3+
electron-builder.env
4+
5+
builder/node_modules
6+
builder/package-lock.json
7+
installers
8+
node_modules

desktop/.noderifyrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"filter": [
3+
"electron",
4+
"fs/promises"
5+
],
6+
"ignoreMissing": true,
7+
"verbose": true
8+
}

desktop/builder/build-icons.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const sharp = require('sharp')
4+
const toIco = require('to-ico')
5+
const { convert: icnsConvert } = require('@fiahfy/icns-convert')
6+
7+
// TODO: replace with svg, using this for now as the icon
8+
// on mac comes out pixelated with the .svg
9+
const image = sharp(path.resolve(__dirname, 'icon.png'))
10+
const setupImage = sharp(path.resolve(__dirname, 'setup-icon.svg'))
11+
12+
const sizes = [16, 24, 32, 48, 64, 96, 128, 256]
13+
14+
console.log('Building Desktop Icons:')
15+
16+
// windows icons
17+
buildIcons(image, sizes, createIco, 'icon')
18+
buildIcons(setupImage, sizes, createIco, 'setup-icon')
19+
20+
// mac icons
21+
buildIcons(image, [...sizes, 512, 1024], createIcns, 'icon')
22+
buildIcons(setupImage, [...sizes, 512, 1024], createIcns, 'dmg-icon')
23+
24+
function makeIcon (size, image) {
25+
return image
26+
.resize(size, size)
27+
.png()
28+
.toBuffer()
29+
}
30+
31+
async function buildIcons (image, sizes, createIcon, fileName) {
32+
await Promise
33+
.all(sizes.map(size => makeIcon(size, image)))
34+
.then(bufs => {
35+
createIcon(bufs, fileName)
36+
console.log(`- ${fileName}`)
37+
})
38+
.catch(err => console.error('Error building icons', err))
39+
}
40+
41+
function createIco (bufs, fileName) {
42+
toIco(bufs)
43+
.then(buf => {
44+
fs.writeFileSync(path.join(__dirname, `win/${fileName}.ico`), buf)
45+
})
46+
.catch(err => console.error('createIco error:', err))
47+
}
48+
49+
function createIcns (bufs, fileName) {
50+
icnsConvert(bufs)
51+
.then(data => {
52+
fs.writeFileSync(path.join(__dirname, `mac/${fileName}.icns`), data)
53+
})
54+
.catch(err => console.error('createIcns error: ', err))
55+
}

desktop/builder/config.js

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// see https://www.electron.build/configuration/configuration
2+
3+
// NOTE
4+
// - this is a more optimized config which prunes un-needed files
5+
// - see config.simple.js for something easier, but makes things a few MB bigger
6+
7+
const fs = require("fs")
8+
const path = require("path")
9+
10+
module.exports = {
11+
appId: "org.patchfox.desktop",
12+
directories: {
13+
output: "installers"
14+
},
15+
16+
/* ADVANDCED SECTION: */
17+
18+
/* Only include needed files */
19+
// this is enabled by our noderify bundling
20+
files: [
21+
"!builder",
22+
"!installers",
23+
"!node_modules",
24+
25+
/* electron main process */
26+
"main.bundle.js",
27+
28+
/* UI files (referenced by main.bundle.js) */
29+
"../dist",
30+
31+
/* native bindings (dependencies of main.bundle.js) */
32+
"node_modules/node-gyp-build/index.js",
33+
34+
"node_modules/sodium-chloride/index.js",
35+
"node_modules/sodium-native/index.js",
36+
"node_modules/sodium-native/prebuilds/${platform}-${arch}/*", // eslint-disable-line
37+
38+
"node_modules/leveldown/index.js",
39+
"node_modules/leveldown/prebuilds/${platform}-${arch}/*", // eslint-disable-line
40+
41+
/* ssb-ahoy ui-window dependency */
42+
"node_modules/ssb-ahoy/electron/preload.js"
43+
],
44+
45+
// NOTE how to figure out what"s needed:
46+
// 1. run `npm run dist`
47+
// 2. try to launch the output (see dist/installers/*.AppImage etc)
48+
// 3. read the errors about what"s missing and add it above
49+
//
50+
// NOTE that we have to include ! (not) rules in files, otherwise
51+
// electron-builder auto-adds **/* (add everything!)
52+
53+
/* delete files from the pack! */
54+
afterPack (context) {
55+
fs.rmSync(path.join(context.appOutDir, "LICENSE.electron.txt"))
56+
fs.rmSync(path.join(context.appOutDir, "LICENSES.chromium.html"))
57+
// const ls = fs.readdirSync(context.appOutDir)
58+
// console.log(ls)
59+
},
60+
61+
publish: [{
62+
provider: "github",
63+
owner: "soapdog",
64+
repo: "patchfox",
65+
releaseType: "release"
66+
}],
67+
68+
...windows(),
69+
...linux(),
70+
...mac()
71+
}
72+
73+
function windows () {
74+
return {
75+
win: {
76+
icon: "builder/win/icon.ico"
77+
78+
/* Code Signing */
79+
// publisherName: ["Āhau NZ Limited"],
80+
// WARNING - this name must *exactly* match the subject/ "issued to" field on the Signing Certificate
81+
// otherwise in future if this name changes, auto-updating will fail D:
82+
83+
// certificateSubjectName: "Āhau NZ Limited", // The name of the subject of the signing certificate
84+
// NOTE - this field worked for code signing certificate, but not the EV signing
85+
// certificateSha1: "A5F49ED3D5EBBCA6EE093BF2A8AA93DA36BDBF56"
86+
// This is a way to be VERY specific about the exact certificate used. This worked well with EV signing cert.
87+
},
88+
nsis: {
89+
artifactName: "${name}-Windows-${version}.${ext}", // eslint-disable-line
90+
installerIcon: "builder/win/setup-icon.ico",
91+
include: "builder/win/add-missing-dll.nsh" // fixes missing VCRUNTIME140.dll
92+
// source: https://github.com/sodium-friends/sodium-native/issues/100
93+
}
94+
}
95+
}
96+
97+
function mac () {
98+
// N = this settings requires for Apple notarization
99+
// https://kilianvalkhof.com/2019/electron/notarizing-your-electron-application/
100+
101+
return {
102+
mac: {
103+
category: "public.app-category.social-networking",
104+
icon: "builder/mac/icon.icns",
105+
hardenedRuntime: true, // N
106+
gatekeeperAssess: false // N
107+
},
108+
dmg: {
109+
artifactName: "${name}-Mac-${version}.${ext}", // eslint-disable-line
110+
background: "builder/mac/background.png",
111+
icon: "builder/mac/dmg-icon.icns",
112+
sign: false // N
113+
},
114+
/* Code Signing */
115+
afterSign: "builder/mac/notarize.js" // N
116+
}
117+
}
118+
119+
function linux () {
120+
return {
121+
linux: {
122+
category: "Network",
123+
target: "AppImage"
124+
},
125+
appImage: {
126+
artifactName: "${name}-Linux-${version}-${arch}.${ext}" // eslint-disable-line
127+
}
128+
}
129+
}

desktop/builder/icon.png

33.1 KB
Loading

desktop/builder/icon.svg

+23
Loading

desktop/builder/mac/background.png

9.11 KB
Loading
14 KB
Loading

desktop/builder/mac/dmg-icon.icns

571 KB
Binary file not shown.

desktop/builder/mac/icon.icns

243 KB
Binary file not shown.

desktop/builder/mac/notarize.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { notarize } = require('electron-notarize')
2+
const { appId } = require('../config.js')
3+
4+
const appleId = process.env.APPLE_ID
5+
6+
exports.default = async function notarizing (context) {
7+
const { electronPlatformName, appOutDir } = context
8+
if (electronPlatformName !== 'darwin') return
9+
10+
if (!appleId) throw new Error('electron builder require env APPLE_ID')
11+
12+
const appName = context.packager.appInfo.productFilename
13+
14+
console.log('Starting notarization...')
15+
16+
return await notarize({ // eslint-disable-line
17+
appBundleId: appId,
18+
appPath: `${appOutDir}/${appName}.app`,
19+
appleId,
20+
// appleIdPassword: `@keychain:"Application Loader: ${appleId}"`
21+
appleIdPassword: process.env.APPLE_ID_PASS
22+
})
23+
}

desktop/builder/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "builder-tools",
3+
"version": "1.0.0",
4+
"description": "this is just here for building icons",
5+
"scripts": {
6+
"build:icons": "node build-icons.js"
7+
},
8+
"devDependencies": {
9+
"@fiahfy/icns-convert": "0.0.8",
10+
"sharp": "^0.23.4",
11+
"to-ico": "^1.1.5"
12+
}
13+
}

desktop/builder/setup-icon.svg

+25
Loading
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
!macro customInstall
2+
3+
!define REDIST_NAME "$\"Microsoft Visual C++ 2015-2019 Redistributable (x64) 14.26.28720.03$\""
4+
!define REDIST_SETUP_URL "https://download.visualstudio.microsoft.com/download/pr/d60aa805-26e9-47df-b4e3-cd6fcc392333/7D7105C52FCD6766BEEE1AE162AA81E278686122C1E44890712326634D0B055E/VC_redist.x64.exe"
5+
!define REDIST_SETUP_FILE "$TEMP\vcredist140-x64-installer.exe"
6+
7+
ClearErrors
8+
9+
ReadRegDword $R0 HKLM "SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\X64" "Installed"
10+
IfErrors 0 +2
11+
DetailPrint "Installing ${REDIST_NAME}..."
12+
StrCmp $R0 "1" 0 +3
13+
DetailPrint "${REDIST_NAME} is already installed. Skipping."
14+
Goto End
15+
16+
DetailPrint "Downloading ${REDIST_NAME} Setup (from ${REDIST_SETUP_URL} to ${REDIST_SETUP_FILE}) ..."
17+
NSISdl::download /TIMEOUT=30000 "${REDIST_SETUP_URL}" "${REDIST_SETUP_FILE}"
18+
19+
Pop $R0 ; get the return value
20+
StrCmp $R0 "success" OnSuccessDownload
21+
22+
Pop $R0 ; get the return value
23+
StrCmp $R0 "success" +2
24+
MessageBox MB_OK "Could not download ${REDIST_NAME} (from ${REDIST_SETUP_URL} to ${REDIST_SETUP_FILE}). Please install it manually."
25+
Goto End
26+
27+
OnSuccessDownload:
28+
DetailPrint "Running ${REDIST_NAME} Setup (${REDIST_SETUP_FILE} executable)..."
29+
ExecWait '"${REDIST_SETUP_FILE}" /norestart'
30+
DetailPrint "Finished ${REDIST_NAME} Setup"
31+
Delete "${REDIST_SETUP_FILE}"
32+
33+
End:
34+
35+
!macroend

desktop/builder/win/icon.ico

389 KB
Binary file not shown.

desktop/builder/win/setup-icon.ico

389 KB
Binary file not shown.

desktop/electron-builder.env.template

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
APPLE_ID_PASS=asdl-tyan-osla-ttyb
3+
4+
CSC_LINK=build/win/csc.pfx
5+
CSC_KEY_PASSWORD=anliushfdxbaejhbrsajxhelaser
6+
7+
GH_TOKEN=sadsdfsadfsdfsdfsdfsdfsdfsdf

0 commit comments

Comments
 (0)