From ba236c57b9b4abdeeda4ae444182d5c031bb6c94 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Thu, 13 Jun 2024 20:44:23 +0100 Subject: [PATCH 01/47] ts electron start --- packages/desktop-electron/package.json | 11 +++++++---- packages/desktop-electron/tsconfig.dist.json | 19 +++++++++++++++++++ yarn.lock | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 packages/desktop-electron/tsconfig.dist.json diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 421923b50ad..2e5e73a1f26 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -7,10 +7,11 @@ "scripts": { "clean": "rm -rf dist", "update-client": "bin/update-client", - "build": "electron-builder", + "build": "yarn typecheck && electron-builder", + "typecheck": "tsc --noEmit --p tsconfig.dist.json", "watch": "cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "index.js", + "main": "dist/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -19,7 +20,8 @@ "!**/*.js.map", "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", - "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}" + "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", + "dist/index.js" ], "publish": { "provider": "github", @@ -65,6 +67,7 @@ "@electron/rebuild": "3.6.0", "cross-env": "^7.0.3", "electron": "30.0.6", - "electron-builder": "24.13.3" + "electron-builder": "24.13.3", + "typescript": "^5.0.2" } } diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json new file mode 100644 index 00000000000..8f3e63a5b9b --- /dev/null +++ b/packages/desktop-electron/tsconfig.dist.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + // Using ES2021 because that’s the newest version where + // the latest Node 16.x release supports all of the features + "target": "ES2021", + "module": "CommonJS", + "noEmit": false, + "declaration": true, + "outDir": "dist", + // "declarationDir": "@types", + // "paths": { + // "loot-core/src/*": ["./loot-core/*"], + // "loot-core/*": ["./@types/loot-core/*"], + // } + }, + "include": ["."], + "exclude": ["**/node_modules/*", "dist", "client-build"] // , "@types" +} diff --git a/yarn.lock b/yarn.lock index b8b91f59e6f..dc0aa5f1ca6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8494,6 +8494,7 @@ __metadata: loot-core: "npm:*" node-fetch: "npm:^2.7.0" promise-retry: "npm:^2.0.1" + typescript: "npm:^5.0.2" languageName: unknown linkType: soft From 21bb9bc75404dee26fd73de6bfe1779a63e9fee1 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Fri, 14 Jun 2024 16:48:55 +0100 Subject: [PATCH 02/47] bits --- .../desktop-electron/{index.js => index.ts} | 40 ++++---- packages/desktop-electron/package.json | 14 ++- packages/desktop-electron/tsconfig.dist.json | 2 +- yarn.lock | 92 +++++++++++++++++-- 4 files changed, 117 insertions(+), 31 deletions(-) rename packages/desktop-electron/{index.js => index.ts} (92%) diff --git a/packages/desktop-electron/index.js b/packages/desktop-electron/index.ts similarity index 92% rename from packages/desktop-electron/index.js rename to packages/desktop-electron/index.ts index 909a0cc7f8f..68aaade11d3 100644 --- a/packages/desktop-electron/index.js +++ b/packages/desktop-electron/index.ts @@ -1,11 +1,7 @@ -/* eslint-disable import/order */ -// (I have no idea why the imports are like this. Not touching them.) -const isDev = require('electron-is-dev'); -const fs = require('fs'); +import fs from 'fs'; +import path from 'path'; -require('module').globalPaths.push(__dirname + '/..'); - -const { +import { app, ipcMain, BrowserWindow, @@ -14,8 +10,17 @@ const { shell, protocol, utilityProcess, -} = require('electron'); -const promiseRetry = require('promise-retry'); +} from 'electron'; +import isDev from 'electron-is-dev'; +import promiseRetry from 'promise-retry'; + +import about from './about'; +import getMenu from './menu'; +import updater from './updater'; + +require('module').globalPaths.push(__dirname + '/..'); + +console.info('dirname entry', __dirname); // This allows relative URLs to be resolved to app:// which makes // local assets load correctly @@ -25,14 +30,8 @@ protocol.registerSchemesAsPrivileged([ global.fetch = require('node-fetch'); -const about = require('./about'); -const getMenu = require('./menu'); -const updater = require('./updater'); - require('./security'); -const path = require('path'); - require('./setRequireHook'); if (!isDev || !process.env.ACTUAL_DOCUMENT_DIR) { @@ -113,7 +112,7 @@ async function createWindow() { nodeIntegrationInWorker: false, nodeIntegrationInSubFrames: false, contextIsolation: true, - enableRemoteModule: false, + // enableRemoteModule: false, preload: __dirname + '/preload.js', }, }); @@ -132,6 +131,7 @@ async function createWindow() { promiseRetry(retry => win.loadURL('http://localhost:3001/').catch(retry)); }, 3000); } else { + console.info('loading url app://actual/', 'dirname', __dirname); win.loadURL(`app://actual/`); } @@ -187,7 +187,7 @@ function isExternalUrl(url) { return !url.includes('localhost:') && !url.includes('app://'); } -function updateMenu(budgetId) { +function updateMenu(budgetId?) { const isBudgetOpen = !!budgetId; const menu = getMenu(isDev, createWindow); const file = menu.items.filter(item => item.label === 'File')[0]; @@ -196,7 +196,9 @@ function updateMenu(budgetId) { .filter(item => item.label === 'Load Backup...') .forEach(item => { item.enabled = isBudgetOpen; - item.budgetId = budgetId; + // remove eslint disable and figure out how to pass this if it's even right to do so + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (item as any).budgetId = budgetId; }); const tools = menu.items.filter(item => item.label === 'Tools')[0]; @@ -312,7 +314,7 @@ ipcMain.handle( (event, { title, defaultPath, fileContents }) => { const fileLocation = dialog.showSaveDialogSync({ title, defaultPath }); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (fileLocation) { fs.writeFile(fileLocation, fileContents, error => { return reject(error); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 2e5e73a1f26..d7ce3d0d3d7 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -7,11 +7,12 @@ "scripts": { "clean": "rm -rf dist", "update-client": "bin/update-client", - "build": "yarn typecheck && electron-builder", - "typecheck": "tsc --noEmit --p tsconfig.dist.json", - "watch": "cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." + "build": "yarn build:dist && electron-builder", + "build:dist": "rm -rf electron-dist && tsc --p tsconfig.dist.json && yarn copy-assets", + "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html electron-dist", + "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "dist/index.js", + "main": "electron-dist/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -21,7 +22,8 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "dist/index.js" + "electron-dist", + "client-build" ], "publish": { "provider": "github", @@ -65,6 +67,8 @@ "devDependencies": { "@electron/notarize": "2.2.0", "@electron/rebuild": "3.6.0", + "@types/copyfiles": "^2", + "copyfiles": "^2.4.1", "cross-env": "^7.0.3", "electron": "30.0.6", "electron-builder": "24.13.3", diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 8f3e63a5b9b..6890223365a 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -7,7 +7,7 @@ "module": "CommonJS", "noEmit": false, "declaration": true, - "outDir": "dist", + "outDir": "electron-dist", // "declarationDir": "@types", // "paths": { // "loot-core/src/*": ["./loot-core/*"], diff --git a/yarn.lock b/yarn.lock index dc0aa5f1ca6..670db2c173e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5266,6 +5266,13 @@ __metadata: languageName: node linkType: hard +"@types/copyfiles@npm:^2": + version: 2.4.4 + resolution: "@types/copyfiles@npm:2.4.4" + checksum: 0513199240828feda5f6ed04c69d6a642c47e6ab66b81214716807f948ed3e865e9b3d2b69f75cbcc6fbe2154630755c47ca473b3913f0a831179366c709a8cc + languageName: node + linkType: hard + "@types/d3-array@npm:^3.0.3": version: 3.0.4 resolution: "@types/d3-array@npm:3.0.4" @@ -7829,6 +7836,24 @@ __metadata: languageName: node linkType: hard +"copyfiles@npm:^2.4.1": + version: 2.4.1 + resolution: "copyfiles@npm:2.4.1" + dependencies: + glob: "npm:^7.0.5" + minimatch: "npm:^3.0.3" + mkdirp: "npm:^1.0.4" + noms: "npm:0.0.0" + through2: "npm:^2.0.1" + untildify: "npm:^4.0.0" + yargs: "npm:^16.1.0" + bin: + copyfiles: copyfiles + copyup: copyfiles + checksum: 17070f88cbeaf62a9355341cb2521bacd48069e1ac8e7f95a3f69c848c53646f16ff0f94807a789e0f3eedc11407ec8d3980a13ab62e2add6ef81d0a5900fd85 + languageName: node + linkType: hard + "core-js-compat@npm:^3.31.0, core-js-compat@npm:^3.34.0": version: 3.36.0 resolution: "core-js-compat@npm:3.36.0" @@ -8485,6 +8510,8 @@ __metadata: dependencies: "@electron/notarize": "npm:2.2.0" "@electron/rebuild": "npm:3.6.0" + "@types/copyfiles": "npm:^2" + copyfiles: "npm:^2.4.1" cross-env: "npm:^7.0.3" electron: "npm:30.0.6" electron-builder: "npm:24.13.3" @@ -10513,7 +10540,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.1.1, glob@npm:^7.1.2, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": +"glob@npm:^7.0.5, glob@npm:^7.1.1, glob@npm:^7.1.2, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -11037,7 +11064,7 @@ __metadata: languageName: node linkType: hard -"inherits@npm:2, inherits@npm:^2.0.3, inherits@npm:^2.0.4, inherits@npm:~2.0.3, inherits@npm:~2.0.4": +"inherits@npm:2, inherits@npm:^2.0.1, inherits@npm:^2.0.3, inherits@npm:^2.0.4, inherits@npm:~2.0.1, inherits@npm:~2.0.3, inherits@npm:~2.0.4": version: 2.0.4 resolution: "inherits@npm:2.0.4" checksum: cd45e923bee15186c07fa4c89db0aace24824c482fb887b528304694b2aa6ff8a898da8657046a5dcf3e46cd6db6c61629551f9215f208d7c3f157cf9b290521 @@ -11602,6 +11629,13 @@ __metadata: languageName: node linkType: hard +"isarray@npm:0.0.1": + version: 0.0.1 + resolution: "isarray@npm:0.0.1" + checksum: 49191f1425681df4a18c2f0f93db3adb85573bcdd6a4482539d98eac9e705d8961317b01175627e860516a2fc45f8f9302db26e5a380a97a520e272e2a40a8d4 + languageName: node + linkType: hard + "isarray@npm:^2.0.5": version: 2.0.5 resolution: "isarray@npm:2.0.5" @@ -13816,7 +13850,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": +"minimatch@npm:^3.0.3, minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": version: 3.1.2 resolution: "minimatch@npm:3.1.2" dependencies: @@ -14241,6 +14275,16 @@ __metadata: languageName: node linkType: hard +"noms@npm:0.0.0": + version: 0.0.0 + resolution: "noms@npm:0.0.0" + dependencies: + inherits: "npm:^2.0.1" + readable-stream: "npm:~1.0.31" + checksum: a05f056dabf764c86472b6b5aad10455f3adcb6971f366cdf36a72b559b29310a940e316bca30802f2804fdd41707941366224f4cba80c4f53071512245bf200 + languageName: node + linkType: hard + "nopt@npm:^6.0.0": version: 6.0.0 resolution: "nopt@npm:6.0.0" @@ -15729,7 +15773,7 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:^2.3.0, readable-stream@npm:^2.3.5": +"readable-stream@npm:^2.3.0, readable-stream@npm:^2.3.5, readable-stream@npm:~2.3.6": version: 2.3.8 resolution: "readable-stream@npm:2.3.8" dependencies: @@ -15755,6 +15799,18 @@ __metadata: languageName: node linkType: hard +"readable-stream@npm:~1.0.31": + version: 1.0.34 + resolution: "readable-stream@npm:1.0.34" + dependencies: + core-util-is: "npm:~1.0.0" + inherits: "npm:~2.0.1" + isarray: "npm:0.0.1" + string_decoder: "npm:~0.10.x" + checksum: 20537fca5a8ffd4af0f483be1cce0e981ed8cbb1087e0c762e2e92ae77f1005627272cebed8422f28047b465056aa1961fefd24baf532ca6a3616afea6811ae0 + languageName: node + linkType: hard + "readdirp@npm:~3.6.0": version: 3.6.0 resolution: "readdirp@npm:3.6.0" @@ -16991,6 +17047,13 @@ __metadata: languageName: node linkType: hard +"string_decoder@npm:~0.10.x": + version: 0.10.31 + resolution: "string_decoder@npm:0.10.31" + checksum: cc43e6b1340d4c7843da0e37d4c87a4084c2342fc99dcf6563c3ec273bb082f0cbd4ebf25d5da19b04fb16400d393885fda830be5128e1c416c73b5a6165f175 + languageName: node + linkType: hard + "string_decoder@npm:~1.1.1": version: 1.1.1 resolution: "string_decoder@npm:1.1.1" @@ -17446,6 +17509,16 @@ __metadata: languageName: node linkType: hard +"through2@npm:^2.0.1": + version: 2.0.5 + resolution: "through2@npm:2.0.5" + dependencies: + readable-stream: "npm:~2.3.6" + xtend: "npm:~4.0.1" + checksum: cd71f7dcdc7a8204fea003a14a433ef99384b7d4e31f5497e1f9f622b3cf3be3691f908455f98723bdc80922a53af7fa10c3b7abbe51c6fd3d536dbc7850e2c4 + languageName: node + linkType: hard + "through@npm:^2.3.8": version: 2.3.8 resolution: "through@npm:2.3.8" @@ -18178,6 +18251,13 @@ __metadata: languageName: node linkType: hard +"untildify@npm:^4.0.0": + version: 4.0.0 + resolution: "untildify@npm:4.0.0" + checksum: 39ced9c418a74f73f0a56e1ba4634b4d959422dff61f4c72a8e39f60b99380c1b45ed776fbaa0a4101b157e4310d873ad7d114e8534ca02609b4916bb4187fb9 + languageName: node + linkType: hard + "upath@npm:^1.2.0": version: 1.2.0 resolution: "upath@npm:1.2.0" @@ -19198,7 +19278,7 @@ __metadata: languageName: node linkType: hard -"xtend@npm:^4.0.0": +"xtend@npm:^4.0.0, xtend@npm:~4.0.1": version: 4.0.2 resolution: "xtend@npm:4.0.2" checksum: ac5dfa738b21f6e7f0dd6e65e1b3155036d68104e67e5d5d1bde74892e327d7e5636a076f625599dc394330a731861e87343ff184b0047fef1360a7ec0a5a36a @@ -19270,7 +19350,7 @@ __metadata: languageName: node linkType: hard -"yargs@npm:^16.2.0": +"yargs@npm:^16.1.0, yargs@npm:^16.2.0": version: 16.2.0 resolution: "yargs@npm:16.2.0" dependencies: From 376efc61a6db25c2ccae0875499de7c862564957 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Fri, 14 Jun 2024 16:51:11 +0100 Subject: [PATCH 03/47] remove comments --- packages/desktop-electron/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 68aaade11d3..36d3236d691 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -20,8 +20,6 @@ import updater from './updater'; require('module').globalPaths.push(__dirname + '/..'); -console.info('dirname entry', __dirname); - // This allows relative URLs to be resolved to app:// which makes // local assets load correctly protocol.registerSchemesAsPrivileged([ @@ -131,7 +129,6 @@ async function createWindow() { promiseRetry(retry => win.loadURL('http://localhost:3001/').catch(retry)); }, 3000); } else { - console.info('loading url app://actual/', 'dirname', __dirname); win.loadURL(`app://actual/`); } From 152a68f0418223144b3821fb8427f11259da6df2 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sat, 15 Jun 2024 23:05:05 +0100 Subject: [PATCH 04/47] it works now --- .gitignore | 1 + packages/desktop-electron/index.ts | 37 ++++++++++++++------ packages/desktop-electron/package.json | 8 ++--- packages/desktop-electron/tsconfig.dist.json | 9 ++--- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index f4243f680bc..3b418063afc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ node_modules packages/api/dist packages/api/@types packages/crdt/dist +packages/desktop-electron/build packages/desktop-electron/client-build packages/desktop-electron/.electron-symbols packages/desktop-electron/dist diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 36d3236d691..7cc1c737a08 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -10,6 +10,7 @@ import { shell, protocol, utilityProcess, + net, } from 'electron'; import isDev from 'electron-is-dev'; import promiseRetry from 'promise-retry'; @@ -224,33 +225,49 @@ app.on('ready', async () => { // Install an `app://` protocol that always returns the base HTML // file no matter what URL it is. This allows us to use react-router // on the frontend - protocol.registerFileProtocol('app', (request, callback) => { + console.info('ready, trying to load file protocol app'); + protocol.handle('app', (request) => { if (request.method !== 'GET') { - callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h + console.info('error', -322); + + // callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h return null; } const parsedUrl = new URL(request.url); if (parsedUrl.protocol !== 'app:') { - callback({ error: -302 }); // UNKNOWN_URL_SCHEME + console.info('error', -302); + // callback({ error: -302 }); // UNKNOWN_URL_SCHEME return; } if (parsedUrl.host !== 'actual') { - callback({ error: -105 }); // NAME_NOT_RESOLVED + console.info('error', -105); + // callback({ error: -105 }); // NAME_NOT_RESOLVED return; } const pathname = parsedUrl.pathname; + console.info('pathname', pathname); if (pathname.startsWith('/static')) { - callback({ - path: path.normalize(`${__dirname}/client-build${pathname}`), - }); + console.info('static', 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`)); + return net.fetch( + 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`), + ); + + // callback({ + // path: path.normalize(`${__dirname}/client-build${pathname}`), + // }); } else { - callback({ - path: path.normalize(`${__dirname}/client-build/index.html`), - }); + console.info('else', 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`)); + return net.fetch( + 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`), + ); + + // callback({ + // path: path.normalize(`${__dirname}/client-build/index.html`), + // }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index d7ce3d0d3d7..a84cdda8ca1 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,11 +8,11 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "rm -rf electron-dist && tsc --p tsconfig.dist.json && yarn copy-assets", - "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html electron-dist", + "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-assets", + "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "electron-dist/index.js", + "main": "build/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -22,7 +22,7 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "electron-dist", + "build", "client-build" ], "publish": { diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 6890223365a..b0b99b3abf3 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -7,13 +7,8 @@ "module": "CommonJS", "noEmit": false, "declaration": true, - "outDir": "electron-dist", - // "declarationDir": "@types", - // "paths": { - // "loot-core/src/*": ["./loot-core/*"], - // "loot-core/*": ["./@types/loot-core/*"], - // } + "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "dist", "client-build"] // , "@types" + "exclude": ["**/node_modules/*", "dist", "client-build", "build"] } From f3ad072cc2e33296b3d3a8b42099e77bf5870611 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 20:24:05 +0100 Subject: [PATCH 05/47] reverting some bits to minimise changes in this pr --- packages/desktop-electron/index.ts | 36 +++++++++--------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 7cc1c737a08..48e6e8f62d0 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -225,49 +225,33 @@ app.on('ready', async () => { // Install an `app://` protocol that always returns the base HTML // file no matter what URL it is. This allows us to use react-router // on the frontend - console.info('ready, trying to load file protocol app'); - protocol.handle('app', (request) => { + protocol.registerFileProtocol('app', (request, callback) => { if (request.method !== 'GET') { - console.info('error', -322); - - // callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h + callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h return null; } const parsedUrl = new URL(request.url); if (parsedUrl.protocol !== 'app:') { - console.info('error', -302); - // callback({ error: -302 }); // UNKNOWN_URL_SCHEME + callback({ error: -302 }); // UNKNOWN_URL_SCHEME return; } if (parsedUrl.host !== 'actual') { - console.info('error', -105); - // callback({ error: -105 }); // NAME_NOT_RESOLVED + callback({ error: -105 }); // NAME_NOT_RESOLVED return; } const pathname = parsedUrl.pathname; - console.info('pathname', pathname); if (pathname.startsWith('/static')) { - console.info('static', 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`)); - return net.fetch( - 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`), - ); - - // callback({ - // path: path.normalize(`${__dirname}/client-build${pathname}`), - // }); + callback({ + path: path.normalize(`${__dirname}/client-build${pathname}`), + }); } else { - console.info('else', 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`)); - return net.fetch( - 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`), - ); - - // callback({ - // path: path.normalize(`${__dirname}/client-build/index.html`), - // }); + callback({ + path: path.normalize(`${__dirname}/client-build/index.html`), + }); } }); From feae66a3ecc1cf7efa2e84e04e6af2aa80de0d49 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 20:48:08 +0100 Subject: [PATCH 06/47] some types --- packages/desktop-electron/index.ts | 41 +++++++++++--------- packages/desktop-electron/tsconfig.dist.json | 2 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 48e6e8f62d0..89d12214d1c 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -10,7 +10,7 @@ import { shell, protocol, utilityProcess, - net, + UtilityProcess, } from 'electron'; import isDev from 'electron-is-dev'; import promiseRetry from 'promise-retry'; @@ -46,10 +46,10 @@ const WindowState = require('./window-state.js'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. -let clientWin; -let serverProcess; +let clientWin: BrowserWindow | null; +let serverProcess: UtilityProcess | null; -updater.onEvent((type, data) => { +updater.onEvent((type: string, data) => { // Notify both the app and the about window if (clientWin) { clientWin.webContents.send(type, data); @@ -146,9 +146,11 @@ async function createWindow() { }); win.on('focus', async () => { - const url = clientWin.webContents.getURL(); - if (url.includes('app://') || url.includes('localhost:')) { - clientWin.webContents.executeJavaScript('__actionsForMenu.focused()'); + if (clientWin) { + const url = clientWin.webContents.getURL(); + if (url.includes('app://') || url.includes('localhost:')) { + clientWin.webContents.executeJavaScript('__actionsForMenu.focused()'); + } } }); @@ -181,15 +183,15 @@ async function createWindow() { clientWin = win; } -function isExternalUrl(url) { +function isExternalUrl(url: string) { return !url.includes('localhost:') && !url.includes('app://'); } -function updateMenu(budgetId?) { +function updateMenu(budgetId?: string) { const isBudgetOpen = !!budgetId; const menu = getMenu(isDev, createWindow); const file = menu.items.filter(item => item.label === 'File')[0]; - const fileItems = file.submenu.items; + const fileItems = file.submenu?.items || []; fileItems .filter(item => item.label === 'Load Backup...') .forEach(item => { @@ -200,12 +202,12 @@ function updateMenu(budgetId?) { }); const tools = menu.items.filter(item => item.label === 'Tools')[0]; - tools.submenu.items.forEach(item => { + tools.submenu?.items.forEach(item => { item.enabled = isBudgetOpen; }); const edit = menu.items.filter(item => item.label === 'Edit')[0]; - const editItems = edit.submenu.items; + const editItems = edit.submenu?.items || []; editItems .filter(item => item.label === 'Undo' || item.label === 'Redo') .map(item => (item.enabled = isBudgetOpen)); @@ -344,8 +346,10 @@ ipcMain.on('screenshot', () => { const width = 1100; // This is for the main screenshot inside the frame - clientWin.setSize(width, Math.floor(width * (427 / 623))); - // clientWin.setSize(width, Math.floor(width * (495 / 700))); + if (clientWin) { + clientWin.setSize(width, Math.floor(width * (427 / 623))); + // clientWin.setSize(width, Math.floor(width * (495 / 700))); + } } }); @@ -372,8 +376,9 @@ ipcMain.on('update-menu', (event, budgetId) => { ipcMain.on('set-theme', theme => { const obj = { theme }; - - clientWin.webContents.executeJavaScript( - `window.__actionsForMenu && window.__actionsForMenu.saveGlobalPrefs(${obj})`, - ); + if (clientWin) { + clientWin.webContents.executeJavaScript( + `window.__actionsForMenu && window.__actionsForMenu.saveGlobalPrefs(${obj})`, + ); + } }); diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index b0b99b3abf3..9cd86881b8d 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -10,5 +10,5 @@ "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "dist", "client-build", "build"] + "exclude": ["**/node_modules/*", "client-build"] } From da030a93cc11654cfe9b9ee9121b811ae2d899bf Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:07:16 +0100 Subject: [PATCH 07/47] updates --- packages/desktop-electron/index.ts | 4 ++-- packages/desktop-electron/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 89d12214d1c..7302e2d6baf 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -248,11 +248,11 @@ app.on('ready', async () => { if (pathname.startsWith('/static')) { callback({ - path: path.normalize(`${__dirname}/client-build${pathname}`), + path: path.normalize(`${__dirname}/../client-build${pathname}`), }); } else { callback({ - path: path.normalize(`${__dirname}/client-build/index.html`), + path: path.normalize(`${__dirname}/../client-build/index.html`), }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index a84cdda8ca1..087ca10b45b 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,8 +8,8 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-assets", - "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html build", + "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "rm -rf build && copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 44cab82500facd339a0fcb9f28e71840da336181 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:08:49 +0100 Subject: [PATCH 08/47] add release notes --- upcoming-release-notes/2880.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/2880.md diff --git a/upcoming-release-notes/2880.md b/upcoming-release-notes/2880.md new file mode 100644 index 00000000000..ac153818e7f --- /dev/null +++ b/upcoming-release-notes/2880.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Start refactoring desktop-electron package to typescript From fe6ab8a3ff3b8524da3626dd9936d18631979ed0 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:12:36 +0100 Subject: [PATCH 09/47] fix type --- packages/desktop-electron/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 7302e2d6baf..208b7ffc4cf 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -49,7 +49,7 @@ const WindowState = require('./window-state.js'); let clientWin: BrowserWindow | null; let serverProcess: UtilityProcess | null; -updater.onEvent((type: string, data) => { +updater.onEvent((type: string, data: Record | string) => { // Notify both the app and the about window if (clientWin) { clientWin.webContents.send(type, data); From 955e26dd31cee1748659f6f7149e26d3e5e7d157 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:33:06 +0100 Subject: [PATCH 10/47] ensuring the build is removed when cleaning --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 087ca10b45b..14f042694c5 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -5,7 +5,7 @@ "description": "A simple and powerful personal finance system", "version": "24.6.0", "scripts": { - "clean": "rm -rf dist", + "clean": "rm -rf dist && rm -rf build", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", From 4aedf0b6b83ee8652fe0024d7f77691c454e91b5 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:34:08 +0100 Subject: [PATCH 11/47] removed modules --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 208b7ffc4cf..657fb4e440c 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -111,7 +111,6 @@ async function createWindow() { nodeIntegrationInWorker: false, nodeIntegrationInSubFrames: false, contextIsolation: true, - // enableRemoteModule: false, preload: __dirname + '/preload.js', }, }); From 78dd41f11075ae28260d447b0676acc8f51a89e9 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:49:33 +0100 Subject: [PATCH 12/47] fix the scripts --- packages/desktop-electron/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 14f042694c5..ff2a1e65b9c 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,8 +8,8 @@ "clean": "rm -rf dist && rm -rf build", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "rm -rf build && copyfiles --exclude 'client-build/**/*' **/*.html build", + "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From e4ae91a279f6616581b40346e2f07ebe1098ce3a Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:55:51 +0100 Subject: [PATCH 13/47] update release notes --- upcoming-release-notes/2880.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upcoming-release-notes/2880.md b/upcoming-release-notes/2880.md index ac153818e7f..d6e6b7480b3 100644 --- a/upcoming-release-notes/2880.md +++ b/upcoming-release-notes/2880.md @@ -3,4 +3,4 @@ category: Maintenance authors: [MikesGlitch] --- -Start refactoring desktop-electron package to typescript +Refactoring desktop-electron package to use typescript From f9c040d68ebbe2371c4b82b72ae6e0e2f0010aa1 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:35:59 +0100 Subject: [PATCH 14/47] fix missing icons --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index ff2a1e65b9c..3154176a187 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From bddb0a9dba9fe0155c875e30c3ef2c3aefe50fba Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:40:00 +0100 Subject: [PATCH 15/47] copy the dir damnit --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 3154176a187..9c2f9a00ccb 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build -r", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 761bf9a030aeb105a024a88096932a27f247c5b3 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:48:45 +0100 Subject: [PATCH 16/47] copyfiles to the rescue --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 9c2f9a00ccb..909ccee0659 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build -r", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From aff758ad7e763b6fd94a5037565fa11735ddbb79 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 23:05:12 +0100 Subject: [PATCH 17/47] comment --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 657fb4e440c..4224f591c80 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -195,7 +195,6 @@ function updateMenu(budgetId?: string) { .filter(item => item.label === 'Load Backup...') .forEach(item => { item.enabled = isBudgetOpen; - // remove eslint disable and figure out how to pass this if it's even right to do so // eslint-disable-next-line @typescript-eslint/no-explicit-any (item as any).budgetId = budgetId; }); From fabdeb9b8da29c92098c67326eece2354090687a Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 23:05:53 +0100 Subject: [PATCH 18/47] remove old code --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 4224f591c80..fba501f6d9d 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -346,7 +346,6 @@ ipcMain.on('screenshot', () => { // This is for the main screenshot inside the frame if (clientWin) { clientWin.setSize(width, Math.floor(width * (427 / 623))); - // clientWin.setSize(width, Math.floor(width * (495 / 700))); } } }); From b69a2da4a45be78476e3e8d8848fe23e0334bcd2 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Tue, 18 Jun 2024 16:37:38 +0100 Subject: [PATCH 19/47] update to build a dist folder instead of client-build outside the folder --- .gitignore | 1 - packages/desktop-electron/bin/update-client | 13 +++++++------ packages/desktop-electron/index.ts | 4 ++-- packages/desktop-electron/package.json | 10 +++++++--- packages/desktop-electron/tsconfig.dist.json | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3b418063afc..ec8f4f1d720 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,6 @@ packages/api/dist packages/api/@types packages/crdt/dist packages/desktop-electron/build -packages/desktop-electron/client-build packages/desktop-electron/.electron-symbols packages/desktop-electron/dist packages/desktop-electron/loot-core diff --git a/packages/desktop-electron/bin/update-client b/packages/desktop-electron/bin/update-client index 3560b0bcf08..778b79386e9 100755 --- a/packages/desktop-electron/bin/update-client +++ b/packages/desktop-electron/bin/update-client @@ -2,12 +2,13 @@ ROOT=`dirname $0`/.. -rm -rf ${ROOT}/client-build -cp -r ${ROOT}/../desktop-client/build ${ROOT}/client-build +rm -rf ${ROOT}/build +mkdir -p ${ROOT}/build +cp -r ${ROOT}/../desktop-client/build ${ROOT}/build/client-build # Remove the embedded backend for the browser version. Will improve # this process -rm -rf ${ROOT}/client-build/data -rm -rf ${ROOT}/client-build/*kcab.* -rm -rf ${ROOT}/client-build/*.wasm -rm -rf ${ROOT}/client-build/*.map +rm -rf ${ROOT}/build/client-build/data +rm -rf ${ROOT}/build/client-build/*kcab.* +rm -rf ${ROOT}/build/client-build/*.wasm +rm -rf ${ROOT}/build/client-build/*.map diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index fba501f6d9d..ba1893469f9 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -246,11 +246,11 @@ app.on('ready', async () => { if (pathname.startsWith('/static')) { callback({ - path: path.normalize(`${__dirname}/../client-build${pathname}`), + path: path.normalize(`${__dirname}/client-build${pathname}`), }); } else { callback({ - path: path.normalize(`${__dirname}/../client-build/index.html`), + path: path.normalize(`${__dirname}/client-build/index.html`), }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 909ccee0659..412ee5b0211 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -5,11 +5,16 @@ "description": "A simple and powerful personal finance system", "version": "24.6.0", "scripts": { - "clean": "rm -rf dist && rm -rf build", + "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", +<<<<<<< Updated upstream "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", +======= + "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", +>>>>>>> Stashed changes "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", @@ -22,8 +27,7 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "build", - "client-build" + "build" ], "publish": { "provider": "github", diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 9cd86881b8d..5a0ba042c52 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -10,5 +10,5 @@ "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "client-build"] + "exclude": ["**/node_modules/*", "build/**/*"] } From 965826ddd444cc9193b131fcb25fd15ce9c8c245 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Tue, 18 Jun 2024 16:48:54 +0100 Subject: [PATCH 20/47] fix merge --- packages/desktop-electron/package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 412ee5b0211..5761aead126 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,13 +8,8 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", -<<<<<<< Updated upstream - "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", -======= "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", ->>>>>>> Stashed changes "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From e78dd760f1b1c0cf07722decee9085a82f964049 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Tue, 18 Jun 2024 18:37:20 +0100 Subject: [PATCH 21/47] icons too. Forgotten after changup --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 5761aead126..458f0615913 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", + "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html icons/**/* build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 66fd34b3ccb73016f0e38a2427df4c087735fec4 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Thu, 13 Jun 2024 20:44:23 +0100 Subject: [PATCH 22/47] ts electron start --- packages/desktop-electron/package.json | 11 +++++++---- packages/desktop-electron/tsconfig.dist.json | 19 +++++++++++++++++++ yarn.lock | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 packages/desktop-electron/tsconfig.dist.json diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 421923b50ad..2e5e73a1f26 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -7,10 +7,11 @@ "scripts": { "clean": "rm -rf dist", "update-client": "bin/update-client", - "build": "electron-builder", + "build": "yarn typecheck && electron-builder", + "typecheck": "tsc --noEmit --p tsconfig.dist.json", "watch": "cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "index.js", + "main": "dist/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -19,7 +20,8 @@ "!**/*.js.map", "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", - "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}" + "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", + "dist/index.js" ], "publish": { "provider": "github", @@ -65,6 +67,7 @@ "@electron/rebuild": "3.6.0", "cross-env": "^7.0.3", "electron": "30.0.6", - "electron-builder": "24.13.3" + "electron-builder": "24.13.3", + "typescript": "^5.0.2" } } diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json new file mode 100644 index 00000000000..8f3e63a5b9b --- /dev/null +++ b/packages/desktop-electron/tsconfig.dist.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + // Using ES2021 because that’s the newest version where + // the latest Node 16.x release supports all of the features + "target": "ES2021", + "module": "CommonJS", + "noEmit": false, + "declaration": true, + "outDir": "dist", + // "declarationDir": "@types", + // "paths": { + // "loot-core/src/*": ["./loot-core/*"], + // "loot-core/*": ["./@types/loot-core/*"], + // } + }, + "include": ["."], + "exclude": ["**/node_modules/*", "dist", "client-build"] // , "@types" +} diff --git a/yarn.lock b/yarn.lock index b8b91f59e6f..dc0aa5f1ca6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8494,6 +8494,7 @@ __metadata: loot-core: "npm:*" node-fetch: "npm:^2.7.0" promise-retry: "npm:^2.0.1" + typescript: "npm:^5.0.2" languageName: unknown linkType: soft From 0aaa2d2d545cd4c6a28585ff9739270e51a82c3e Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Fri, 14 Jun 2024 16:48:55 +0100 Subject: [PATCH 23/47] bits --- .../desktop-electron/{index.js => index.ts} | 40 ++++---- packages/desktop-electron/package.json | 14 ++- packages/desktop-electron/tsconfig.dist.json | 2 +- yarn.lock | 92 +++++++++++++++++-- 4 files changed, 117 insertions(+), 31 deletions(-) rename packages/desktop-electron/{index.js => index.ts} (92%) diff --git a/packages/desktop-electron/index.js b/packages/desktop-electron/index.ts similarity index 92% rename from packages/desktop-electron/index.js rename to packages/desktop-electron/index.ts index 909a0cc7f8f..68aaade11d3 100644 --- a/packages/desktop-electron/index.js +++ b/packages/desktop-electron/index.ts @@ -1,11 +1,7 @@ -/* eslint-disable import/order */ -// (I have no idea why the imports are like this. Not touching them.) -const isDev = require('electron-is-dev'); -const fs = require('fs'); +import fs from 'fs'; +import path from 'path'; -require('module').globalPaths.push(__dirname + '/..'); - -const { +import { app, ipcMain, BrowserWindow, @@ -14,8 +10,17 @@ const { shell, protocol, utilityProcess, -} = require('electron'); -const promiseRetry = require('promise-retry'); +} from 'electron'; +import isDev from 'electron-is-dev'; +import promiseRetry from 'promise-retry'; + +import about from './about'; +import getMenu from './menu'; +import updater from './updater'; + +require('module').globalPaths.push(__dirname + '/..'); + +console.info('dirname entry', __dirname); // This allows relative URLs to be resolved to app:// which makes // local assets load correctly @@ -25,14 +30,8 @@ protocol.registerSchemesAsPrivileged([ global.fetch = require('node-fetch'); -const about = require('./about'); -const getMenu = require('./menu'); -const updater = require('./updater'); - require('./security'); -const path = require('path'); - require('./setRequireHook'); if (!isDev || !process.env.ACTUAL_DOCUMENT_DIR) { @@ -113,7 +112,7 @@ async function createWindow() { nodeIntegrationInWorker: false, nodeIntegrationInSubFrames: false, contextIsolation: true, - enableRemoteModule: false, + // enableRemoteModule: false, preload: __dirname + '/preload.js', }, }); @@ -132,6 +131,7 @@ async function createWindow() { promiseRetry(retry => win.loadURL('http://localhost:3001/').catch(retry)); }, 3000); } else { + console.info('loading url app://actual/', 'dirname', __dirname); win.loadURL(`app://actual/`); } @@ -187,7 +187,7 @@ function isExternalUrl(url) { return !url.includes('localhost:') && !url.includes('app://'); } -function updateMenu(budgetId) { +function updateMenu(budgetId?) { const isBudgetOpen = !!budgetId; const menu = getMenu(isDev, createWindow); const file = menu.items.filter(item => item.label === 'File')[0]; @@ -196,7 +196,9 @@ function updateMenu(budgetId) { .filter(item => item.label === 'Load Backup...') .forEach(item => { item.enabled = isBudgetOpen; - item.budgetId = budgetId; + // remove eslint disable and figure out how to pass this if it's even right to do so + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (item as any).budgetId = budgetId; }); const tools = menu.items.filter(item => item.label === 'Tools')[0]; @@ -312,7 +314,7 @@ ipcMain.handle( (event, { title, defaultPath, fileContents }) => { const fileLocation = dialog.showSaveDialogSync({ title, defaultPath }); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (fileLocation) { fs.writeFile(fileLocation, fileContents, error => { return reject(error); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 2e5e73a1f26..d7ce3d0d3d7 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -7,11 +7,12 @@ "scripts": { "clean": "rm -rf dist", "update-client": "bin/update-client", - "build": "yarn typecheck && electron-builder", - "typecheck": "tsc --noEmit --p tsconfig.dist.json", - "watch": "cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." + "build": "yarn build:dist && electron-builder", + "build:dist": "rm -rf electron-dist && tsc --p tsconfig.dist.json && yarn copy-assets", + "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html electron-dist", + "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "dist/index.js", + "main": "electron-dist/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -21,7 +22,8 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "dist/index.js" + "electron-dist", + "client-build" ], "publish": { "provider": "github", @@ -65,6 +67,8 @@ "devDependencies": { "@electron/notarize": "2.2.0", "@electron/rebuild": "3.6.0", + "@types/copyfiles": "^2", + "copyfiles": "^2.4.1", "cross-env": "^7.0.3", "electron": "30.0.6", "electron-builder": "24.13.3", diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 8f3e63a5b9b..6890223365a 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -7,7 +7,7 @@ "module": "CommonJS", "noEmit": false, "declaration": true, - "outDir": "dist", + "outDir": "electron-dist", // "declarationDir": "@types", // "paths": { // "loot-core/src/*": ["./loot-core/*"], diff --git a/yarn.lock b/yarn.lock index dc0aa5f1ca6..670db2c173e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5266,6 +5266,13 @@ __metadata: languageName: node linkType: hard +"@types/copyfiles@npm:^2": + version: 2.4.4 + resolution: "@types/copyfiles@npm:2.4.4" + checksum: 0513199240828feda5f6ed04c69d6a642c47e6ab66b81214716807f948ed3e865e9b3d2b69f75cbcc6fbe2154630755c47ca473b3913f0a831179366c709a8cc + languageName: node + linkType: hard + "@types/d3-array@npm:^3.0.3": version: 3.0.4 resolution: "@types/d3-array@npm:3.0.4" @@ -7829,6 +7836,24 @@ __metadata: languageName: node linkType: hard +"copyfiles@npm:^2.4.1": + version: 2.4.1 + resolution: "copyfiles@npm:2.4.1" + dependencies: + glob: "npm:^7.0.5" + minimatch: "npm:^3.0.3" + mkdirp: "npm:^1.0.4" + noms: "npm:0.0.0" + through2: "npm:^2.0.1" + untildify: "npm:^4.0.0" + yargs: "npm:^16.1.0" + bin: + copyfiles: copyfiles + copyup: copyfiles + checksum: 17070f88cbeaf62a9355341cb2521bacd48069e1ac8e7f95a3f69c848c53646f16ff0f94807a789e0f3eedc11407ec8d3980a13ab62e2add6ef81d0a5900fd85 + languageName: node + linkType: hard + "core-js-compat@npm:^3.31.0, core-js-compat@npm:^3.34.0": version: 3.36.0 resolution: "core-js-compat@npm:3.36.0" @@ -8485,6 +8510,8 @@ __metadata: dependencies: "@electron/notarize": "npm:2.2.0" "@electron/rebuild": "npm:3.6.0" + "@types/copyfiles": "npm:^2" + copyfiles: "npm:^2.4.1" cross-env: "npm:^7.0.3" electron: "npm:30.0.6" electron-builder: "npm:24.13.3" @@ -10513,7 +10540,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.1.1, glob@npm:^7.1.2, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": +"glob@npm:^7.0.5, glob@npm:^7.1.1, glob@npm:^7.1.2, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -11037,7 +11064,7 @@ __metadata: languageName: node linkType: hard -"inherits@npm:2, inherits@npm:^2.0.3, inherits@npm:^2.0.4, inherits@npm:~2.0.3, inherits@npm:~2.0.4": +"inherits@npm:2, inherits@npm:^2.0.1, inherits@npm:^2.0.3, inherits@npm:^2.0.4, inherits@npm:~2.0.1, inherits@npm:~2.0.3, inherits@npm:~2.0.4": version: 2.0.4 resolution: "inherits@npm:2.0.4" checksum: cd45e923bee15186c07fa4c89db0aace24824c482fb887b528304694b2aa6ff8a898da8657046a5dcf3e46cd6db6c61629551f9215f208d7c3f157cf9b290521 @@ -11602,6 +11629,13 @@ __metadata: languageName: node linkType: hard +"isarray@npm:0.0.1": + version: 0.0.1 + resolution: "isarray@npm:0.0.1" + checksum: 49191f1425681df4a18c2f0f93db3adb85573bcdd6a4482539d98eac9e705d8961317b01175627e860516a2fc45f8f9302db26e5a380a97a520e272e2a40a8d4 + languageName: node + linkType: hard + "isarray@npm:^2.0.5": version: 2.0.5 resolution: "isarray@npm:2.0.5" @@ -13816,7 +13850,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": +"minimatch@npm:^3.0.3, minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": version: 3.1.2 resolution: "minimatch@npm:3.1.2" dependencies: @@ -14241,6 +14275,16 @@ __metadata: languageName: node linkType: hard +"noms@npm:0.0.0": + version: 0.0.0 + resolution: "noms@npm:0.0.0" + dependencies: + inherits: "npm:^2.0.1" + readable-stream: "npm:~1.0.31" + checksum: a05f056dabf764c86472b6b5aad10455f3adcb6971f366cdf36a72b559b29310a940e316bca30802f2804fdd41707941366224f4cba80c4f53071512245bf200 + languageName: node + linkType: hard + "nopt@npm:^6.0.0": version: 6.0.0 resolution: "nopt@npm:6.0.0" @@ -15729,7 +15773,7 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:^2.3.0, readable-stream@npm:^2.3.5": +"readable-stream@npm:^2.3.0, readable-stream@npm:^2.3.5, readable-stream@npm:~2.3.6": version: 2.3.8 resolution: "readable-stream@npm:2.3.8" dependencies: @@ -15755,6 +15799,18 @@ __metadata: languageName: node linkType: hard +"readable-stream@npm:~1.0.31": + version: 1.0.34 + resolution: "readable-stream@npm:1.0.34" + dependencies: + core-util-is: "npm:~1.0.0" + inherits: "npm:~2.0.1" + isarray: "npm:0.0.1" + string_decoder: "npm:~0.10.x" + checksum: 20537fca5a8ffd4af0f483be1cce0e981ed8cbb1087e0c762e2e92ae77f1005627272cebed8422f28047b465056aa1961fefd24baf532ca6a3616afea6811ae0 + languageName: node + linkType: hard + "readdirp@npm:~3.6.0": version: 3.6.0 resolution: "readdirp@npm:3.6.0" @@ -16991,6 +17047,13 @@ __metadata: languageName: node linkType: hard +"string_decoder@npm:~0.10.x": + version: 0.10.31 + resolution: "string_decoder@npm:0.10.31" + checksum: cc43e6b1340d4c7843da0e37d4c87a4084c2342fc99dcf6563c3ec273bb082f0cbd4ebf25d5da19b04fb16400d393885fda830be5128e1c416c73b5a6165f175 + languageName: node + linkType: hard + "string_decoder@npm:~1.1.1": version: 1.1.1 resolution: "string_decoder@npm:1.1.1" @@ -17446,6 +17509,16 @@ __metadata: languageName: node linkType: hard +"through2@npm:^2.0.1": + version: 2.0.5 + resolution: "through2@npm:2.0.5" + dependencies: + readable-stream: "npm:~2.3.6" + xtend: "npm:~4.0.1" + checksum: cd71f7dcdc7a8204fea003a14a433ef99384b7d4e31f5497e1f9f622b3cf3be3691f908455f98723bdc80922a53af7fa10c3b7abbe51c6fd3d536dbc7850e2c4 + languageName: node + linkType: hard + "through@npm:^2.3.8": version: 2.3.8 resolution: "through@npm:2.3.8" @@ -18178,6 +18251,13 @@ __metadata: languageName: node linkType: hard +"untildify@npm:^4.0.0": + version: 4.0.0 + resolution: "untildify@npm:4.0.0" + checksum: 39ced9c418a74f73f0a56e1ba4634b4d959422dff61f4c72a8e39f60b99380c1b45ed776fbaa0a4101b157e4310d873ad7d114e8534ca02609b4916bb4187fb9 + languageName: node + linkType: hard + "upath@npm:^1.2.0": version: 1.2.0 resolution: "upath@npm:1.2.0" @@ -19198,7 +19278,7 @@ __metadata: languageName: node linkType: hard -"xtend@npm:^4.0.0": +"xtend@npm:^4.0.0, xtend@npm:~4.0.1": version: 4.0.2 resolution: "xtend@npm:4.0.2" checksum: ac5dfa738b21f6e7f0dd6e65e1b3155036d68104e67e5d5d1bde74892e327d7e5636a076f625599dc394330a731861e87343ff184b0047fef1360a7ec0a5a36a @@ -19270,7 +19350,7 @@ __metadata: languageName: node linkType: hard -"yargs@npm:^16.2.0": +"yargs@npm:^16.1.0, yargs@npm:^16.2.0": version: 16.2.0 resolution: "yargs@npm:16.2.0" dependencies: From 0569f49f0e07e5e4400ce23aa30568e2fe055dd3 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Fri, 14 Jun 2024 16:51:11 +0100 Subject: [PATCH 24/47] remove comments --- packages/desktop-electron/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 68aaade11d3..36d3236d691 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -20,8 +20,6 @@ import updater from './updater'; require('module').globalPaths.push(__dirname + '/..'); -console.info('dirname entry', __dirname); - // This allows relative URLs to be resolved to app:// which makes // local assets load correctly protocol.registerSchemesAsPrivileged([ @@ -131,7 +129,6 @@ async function createWindow() { promiseRetry(retry => win.loadURL('http://localhost:3001/').catch(retry)); }, 3000); } else { - console.info('loading url app://actual/', 'dirname', __dirname); win.loadURL(`app://actual/`); } From acb22b8d283d67547eaae8c1a19a2491d0e76b61 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sat, 15 Jun 2024 23:05:05 +0100 Subject: [PATCH 25/47] it works now --- .gitignore | 1 + packages/desktop-electron/index.ts | 37 ++++++++++++++------ packages/desktop-electron/package.json | 8 ++--- packages/desktop-electron/tsconfig.dist.json | 9 ++--- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index f4243f680bc..3b418063afc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ node_modules packages/api/dist packages/api/@types packages/crdt/dist +packages/desktop-electron/build packages/desktop-electron/client-build packages/desktop-electron/.electron-symbols packages/desktop-electron/dist diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 36d3236d691..7cc1c737a08 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -10,6 +10,7 @@ import { shell, protocol, utilityProcess, + net, } from 'electron'; import isDev from 'electron-is-dev'; import promiseRetry from 'promise-retry'; @@ -224,33 +225,49 @@ app.on('ready', async () => { // Install an `app://` protocol that always returns the base HTML // file no matter what URL it is. This allows us to use react-router // on the frontend - protocol.registerFileProtocol('app', (request, callback) => { + console.info('ready, trying to load file protocol app'); + protocol.handle('app', (request) => { if (request.method !== 'GET') { - callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h + console.info('error', -322); + + // callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h return null; } const parsedUrl = new URL(request.url); if (parsedUrl.protocol !== 'app:') { - callback({ error: -302 }); // UNKNOWN_URL_SCHEME + console.info('error', -302); + // callback({ error: -302 }); // UNKNOWN_URL_SCHEME return; } if (parsedUrl.host !== 'actual') { - callback({ error: -105 }); // NAME_NOT_RESOLVED + console.info('error', -105); + // callback({ error: -105 }); // NAME_NOT_RESOLVED return; } const pathname = parsedUrl.pathname; + console.info('pathname', pathname); if (pathname.startsWith('/static')) { - callback({ - path: path.normalize(`${__dirname}/client-build${pathname}`), - }); + console.info('static', 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`)); + return net.fetch( + 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`), + ); + + // callback({ + // path: path.normalize(`${__dirname}/client-build${pathname}`), + // }); } else { - callback({ - path: path.normalize(`${__dirname}/client-build/index.html`), - }); + console.info('else', 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`)); + return net.fetch( + 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`), + ); + + // callback({ + // path: path.normalize(`${__dirname}/client-build/index.html`), + // }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index d7ce3d0d3d7..a84cdda8ca1 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,11 +8,11 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "rm -rf electron-dist && tsc --p tsconfig.dist.json && yarn copy-assets", - "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html electron-dist", + "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-assets", + "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, - "main": "electron-dist/index.js", + "main": "build/index.js", "build": { "appId": "com.actualbudget.actual", "files": [ @@ -22,7 +22,7 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "electron-dist", + "build", "client-build" ], "publish": { diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 6890223365a..b0b99b3abf3 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -7,13 +7,8 @@ "module": "CommonJS", "noEmit": false, "declaration": true, - "outDir": "electron-dist", - // "declarationDir": "@types", - // "paths": { - // "loot-core/src/*": ["./loot-core/*"], - // "loot-core/*": ["./@types/loot-core/*"], - // } + "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "dist", "client-build"] // , "@types" + "exclude": ["**/node_modules/*", "dist", "client-build", "build"] } From 0068630a8f5dc03dc0994f231d300e251337385a Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 20:24:05 +0100 Subject: [PATCH 26/47] reverting some bits to minimise changes in this pr --- packages/desktop-electron/index.ts | 36 +++++++++--------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 7cc1c737a08..48e6e8f62d0 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -225,49 +225,33 @@ app.on('ready', async () => { // Install an `app://` protocol that always returns the base HTML // file no matter what URL it is. This allows us to use react-router // on the frontend - console.info('ready, trying to load file protocol app'); - protocol.handle('app', (request) => { + protocol.registerFileProtocol('app', (request, callback) => { if (request.method !== 'GET') { - console.info('error', -322); - - // callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h + callback({ error: -322 }); // METHOD_NOT_SUPPORTED from chromium/src/net/base/net_error_list.h return null; } const parsedUrl = new URL(request.url); if (parsedUrl.protocol !== 'app:') { - console.info('error', -302); - // callback({ error: -302 }); // UNKNOWN_URL_SCHEME + callback({ error: -302 }); // UNKNOWN_URL_SCHEME return; } if (parsedUrl.host !== 'actual') { - console.info('error', -105); - // callback({ error: -105 }); // NAME_NOT_RESOLVED + callback({ error: -105 }); // NAME_NOT_RESOLVED return; } const pathname = parsedUrl.pathname; - console.info('pathname', pathname); if (pathname.startsWith('/static')) { - console.info('static', 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`)); - return net.fetch( - 'file:///' + path.normalize(`${__dirname}/../client-build${pathname}`), - ); - - // callback({ - // path: path.normalize(`${__dirname}/client-build${pathname}`), - // }); + callback({ + path: path.normalize(`${__dirname}/client-build${pathname}`), + }); } else { - console.info('else', 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`)); - return net.fetch( - 'file:///' + path.normalize(`${__dirname}/../client-build/index.html`), - ); - - // callback({ - // path: path.normalize(`${__dirname}/client-build/index.html`), - // }); + callback({ + path: path.normalize(`${__dirname}/client-build/index.html`), + }); } }); From b27224a975f9a8cdc7447be4cb0d49fcf924f2f8 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 20:48:08 +0100 Subject: [PATCH 27/47] some types --- packages/desktop-electron/index.ts | 41 +++++++++++--------- packages/desktop-electron/tsconfig.dist.json | 2 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 48e6e8f62d0..89d12214d1c 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -10,7 +10,7 @@ import { shell, protocol, utilityProcess, - net, + UtilityProcess, } from 'electron'; import isDev from 'electron-is-dev'; import promiseRetry from 'promise-retry'; @@ -46,10 +46,10 @@ const WindowState = require('./window-state.js'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. -let clientWin; -let serverProcess; +let clientWin: BrowserWindow | null; +let serverProcess: UtilityProcess | null; -updater.onEvent((type, data) => { +updater.onEvent((type: string, data) => { // Notify both the app and the about window if (clientWin) { clientWin.webContents.send(type, data); @@ -146,9 +146,11 @@ async function createWindow() { }); win.on('focus', async () => { - const url = clientWin.webContents.getURL(); - if (url.includes('app://') || url.includes('localhost:')) { - clientWin.webContents.executeJavaScript('__actionsForMenu.focused()'); + if (clientWin) { + const url = clientWin.webContents.getURL(); + if (url.includes('app://') || url.includes('localhost:')) { + clientWin.webContents.executeJavaScript('__actionsForMenu.focused()'); + } } }); @@ -181,15 +183,15 @@ async function createWindow() { clientWin = win; } -function isExternalUrl(url) { +function isExternalUrl(url: string) { return !url.includes('localhost:') && !url.includes('app://'); } -function updateMenu(budgetId?) { +function updateMenu(budgetId?: string) { const isBudgetOpen = !!budgetId; const menu = getMenu(isDev, createWindow); const file = menu.items.filter(item => item.label === 'File')[0]; - const fileItems = file.submenu.items; + const fileItems = file.submenu?.items || []; fileItems .filter(item => item.label === 'Load Backup...') .forEach(item => { @@ -200,12 +202,12 @@ function updateMenu(budgetId?) { }); const tools = menu.items.filter(item => item.label === 'Tools')[0]; - tools.submenu.items.forEach(item => { + tools.submenu?.items.forEach(item => { item.enabled = isBudgetOpen; }); const edit = menu.items.filter(item => item.label === 'Edit')[0]; - const editItems = edit.submenu.items; + const editItems = edit.submenu?.items || []; editItems .filter(item => item.label === 'Undo' || item.label === 'Redo') .map(item => (item.enabled = isBudgetOpen)); @@ -344,8 +346,10 @@ ipcMain.on('screenshot', () => { const width = 1100; // This is for the main screenshot inside the frame - clientWin.setSize(width, Math.floor(width * (427 / 623))); - // clientWin.setSize(width, Math.floor(width * (495 / 700))); + if (clientWin) { + clientWin.setSize(width, Math.floor(width * (427 / 623))); + // clientWin.setSize(width, Math.floor(width * (495 / 700))); + } } }); @@ -372,8 +376,9 @@ ipcMain.on('update-menu', (event, budgetId) => { ipcMain.on('set-theme', theme => { const obj = { theme }; - - clientWin.webContents.executeJavaScript( - `window.__actionsForMenu && window.__actionsForMenu.saveGlobalPrefs(${obj})`, - ); + if (clientWin) { + clientWin.webContents.executeJavaScript( + `window.__actionsForMenu && window.__actionsForMenu.saveGlobalPrefs(${obj})`, + ); + } }); diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index b0b99b3abf3..9cd86881b8d 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -10,5 +10,5 @@ "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "dist", "client-build", "build"] + "exclude": ["**/node_modules/*", "client-build"] } From 65ee3067f377a5add3fca7b1a03d854880595d8f Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:07:16 +0100 Subject: [PATCH 28/47] updates --- packages/desktop-electron/index.ts | 4 ++-- packages/desktop-electron/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 89d12214d1c..7302e2d6baf 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -248,11 +248,11 @@ app.on('ready', async () => { if (pathname.startsWith('/static')) { callback({ - path: path.normalize(`${__dirname}/client-build${pathname}`), + path: path.normalize(`${__dirname}/../client-build${pathname}`), }); } else { callback({ - path: path.normalize(`${__dirname}/client-build/index.html`), + path: path.normalize(`${__dirname}/../client-build/index.html`), }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index a84cdda8ca1..087ca10b45b 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,8 +8,8 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-assets", - "copy-assets": "copyfiles --exclude 'client-build/**/*' **/*.html build", + "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "rm -rf build && copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From b7861e45e2c14847fb9aca971e5e3a12ef7250ac Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:08:49 +0100 Subject: [PATCH 29/47] add release notes --- upcoming-release-notes/2880.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/2880.md diff --git a/upcoming-release-notes/2880.md b/upcoming-release-notes/2880.md new file mode 100644 index 00000000000..ac153818e7f --- /dev/null +++ b/upcoming-release-notes/2880.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Start refactoring desktop-electron package to typescript From 2a25d20b1a4ae91b9cb87628d5af304bbd58ab0f Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:12:36 +0100 Subject: [PATCH 30/47] fix type --- packages/desktop-electron/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 7302e2d6baf..208b7ffc4cf 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -49,7 +49,7 @@ const WindowState = require('./window-state.js'); let clientWin: BrowserWindow | null; let serverProcess: UtilityProcess | null; -updater.onEvent((type: string, data) => { +updater.onEvent((type: string, data: Record | string) => { // Notify both the app and the about window if (clientWin) { clientWin.webContents.send(type, data); From ab82c2bd4e29375e2d44934fef53a1f530c74b49 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:33:06 +0100 Subject: [PATCH 31/47] ensuring the build is removed when cleaning --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 087ca10b45b..14f042694c5 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -5,7 +5,7 @@ "description": "A simple and powerful personal finance system", "version": "24.6.0", "scripts": { - "clean": "rm -rf dist", + "clean": "rm -rf dist && rm -rf build", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", From 3f4c20d6a03423465149a846cc67eeec9e35838a Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:34:08 +0100 Subject: [PATCH 32/47] removed modules --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 208b7ffc4cf..657fb4e440c 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -111,7 +111,6 @@ async function createWindow() { nodeIntegrationInWorker: false, nodeIntegrationInSubFrames: false, contextIsolation: true, - // enableRemoteModule: false, preload: __dirname + '/preload.js', }, }); From 6d8ee914b61ae2880f16859e175b260f614ac811 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:49:33 +0100 Subject: [PATCH 33/47] fix the scripts --- packages/desktop-electron/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 14f042694c5..ff2a1e65b9c 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,8 +8,8 @@ "clean": "rm -rf dist && rm -rf build", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", - "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "rm -rf build && copyfiles --exclude 'client-build/**/*' **/*.html build", + "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 1b669469a0289390b12573cdf1f0d6990783eceb Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Sun, 16 Jun 2024 21:55:51 +0100 Subject: [PATCH 34/47] update release notes --- upcoming-release-notes/2880.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upcoming-release-notes/2880.md b/upcoming-release-notes/2880.md index ac153818e7f..d6e6b7480b3 100644 --- a/upcoming-release-notes/2880.md +++ b/upcoming-release-notes/2880.md @@ -3,4 +3,4 @@ category: Maintenance authors: [MikesGlitch] --- -Start refactoring desktop-electron package to typescript +Refactoring desktop-electron package to use typescript From ff39d5408f6329a3bb66866c9399c58c5ac4b1d6 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:35:59 +0100 Subject: [PATCH 35/47] fix missing icons --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index ff2a1e65b9c..3154176a187 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From ff34566de6865bb50f32d9473bb1a64ed8434a23 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:40:00 +0100 Subject: [PATCH 36/47] copy the dir damnit --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 3154176a187..9c2f9a00ccb 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build -r", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 7a855f355195e46298f71a6d623a912f0d4128b1 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 22:48:45 +0100 Subject: [PATCH 37/47] copyfiles to the rescue --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 9c2f9a00ccb..909ccee0659 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html build && cp icons build -r", + "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 4d2532a55501264b413b25c2c9b7ce16b1a29162 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 23:05:12 +0100 Subject: [PATCH 38/47] comment --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 657fb4e440c..4224f591c80 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -195,7 +195,6 @@ function updateMenu(budgetId?: string) { .filter(item => item.label === 'Load Backup...') .forEach(item => { item.enabled = isBudgetOpen; - // remove eslint disable and figure out how to pass this if it's even right to do so // eslint-disable-next-line @typescript-eslint/no-explicit-any (item as any).budgetId = budgetId; }); From 3d6c72bc6d801976783230fe597f0459ee7bfe9c Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 16 Jun 2024 23:05:53 +0100 Subject: [PATCH 39/47] remove old code --- packages/desktop-electron/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 4224f591c80..fba501f6d9d 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -346,7 +346,6 @@ ipcMain.on('screenshot', () => { // This is for the main screenshot inside the frame if (clientWin) { clientWin.setSize(width, Math.floor(width * (427 / 623))); - // clientWin.setSize(width, Math.floor(width * (495 / 700))); } } }); From a77377064eb8305b423e01aeb61f2ad1e7e14855 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Tue, 18 Jun 2024 16:37:38 +0100 Subject: [PATCH 40/47] update to build a dist folder instead of client-build outside the folder --- .gitignore | 1 - packages/desktop-electron/bin/update-client | 13 +++++++------ packages/desktop-electron/index.ts | 4 ++-- packages/desktop-electron/package.json | 10 +++++++--- packages/desktop-electron/tsconfig.dist.json | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3b418063afc..ec8f4f1d720 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,6 @@ packages/api/dist packages/api/@types packages/crdt/dist packages/desktop-electron/build -packages/desktop-electron/client-build packages/desktop-electron/.electron-symbols packages/desktop-electron/dist packages/desktop-electron/loot-core diff --git a/packages/desktop-electron/bin/update-client b/packages/desktop-electron/bin/update-client index 3560b0bcf08..778b79386e9 100755 --- a/packages/desktop-electron/bin/update-client +++ b/packages/desktop-electron/bin/update-client @@ -2,12 +2,13 @@ ROOT=`dirname $0`/.. -rm -rf ${ROOT}/client-build -cp -r ${ROOT}/../desktop-client/build ${ROOT}/client-build +rm -rf ${ROOT}/build +mkdir -p ${ROOT}/build +cp -r ${ROOT}/../desktop-client/build ${ROOT}/build/client-build # Remove the embedded backend for the browser version. Will improve # this process -rm -rf ${ROOT}/client-build/data -rm -rf ${ROOT}/client-build/*kcab.* -rm -rf ${ROOT}/client-build/*.wasm -rm -rf ${ROOT}/client-build/*.map +rm -rf ${ROOT}/build/client-build/data +rm -rf ${ROOT}/build/client-build/*kcab.* +rm -rf ${ROOT}/build/client-build/*.wasm +rm -rf ${ROOT}/build/client-build/*.map diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index fba501f6d9d..ba1893469f9 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -246,11 +246,11 @@ app.on('ready', async () => { if (pathname.startsWith('/static')) { callback({ - path: path.normalize(`${__dirname}/../client-build${pathname}`), + path: path.normalize(`${__dirname}/client-build${pathname}`), }); } else { callback({ - path: path.normalize(`${__dirname}/../client-build/index.html`), + path: path.normalize(`${__dirname}/client-build/index.html`), }); } }); diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 909ccee0659..412ee5b0211 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -5,11 +5,16 @@ "description": "A simple and powerful personal finance system", "version": "24.6.0", "scripts": { - "clean": "rm -rf dist && rm -rf build", + "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", +<<<<<<< Updated upstream "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", +======= + "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", + "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", +>>>>>>> Stashed changes "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", @@ -22,8 +27,7 @@ "!node_modules/@jlongster/sql.js", "!node_modules/absurd-sql", "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", - "build", - "client-build" + "build" ], "publish": { "provider": "github", diff --git a/packages/desktop-electron/tsconfig.dist.json b/packages/desktop-electron/tsconfig.dist.json index 9cd86881b8d..5a0ba042c52 100644 --- a/packages/desktop-electron/tsconfig.dist.json +++ b/packages/desktop-electron/tsconfig.dist.json @@ -10,5 +10,5 @@ "outDir": "build", }, "include": ["."], - "exclude": ["**/node_modules/*", "client-build"] + "exclude": ["**/node_modules/*", "build/**/*"] } From 9d0d9e65d06b4c222af30fdd4753781e50787077 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Tue, 18 Jun 2024 16:48:54 +0100 Subject: [PATCH 41/47] fix merge --- packages/desktop-electron/package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 412ee5b0211..5761aead126 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -8,13 +8,8 @@ "clean": "rm -rf dist", "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", -<<<<<<< Updated upstream - "build:dist": "rm -rf build && tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'client-build/**/*' **/*.html icons/**/* build", -======= "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", ->>>>>>> Stashed changes "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From f320daeeeec2ee3740b007302eeccfa494e17202 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Tue, 18 Jun 2024 18:37:20 +0100 Subject: [PATCH 42/47] icons too. Forgotten after changup --- packages/desktop-electron/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 5761aead126..458f0615913 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -9,7 +9,7 @@ "update-client": "bin/update-client", "build": "yarn build:dist && electron-builder", "build:dist": "tsc --p tsconfig.dist.json && yarn copy-static-html", - "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html build", + "copy-static-html": "copyfiles --exclude 'build/**/*' **/*.html icons/**/* build", "watch": "yarn build:dist && cross-env ACTUAL_DOCUMENT_DIR=\"../../data\" ACTUAL_DATA_DIR=\"../../data\" electron ." }, "main": "build/index.js", From 84967fd53b2f60a559c55c6eeb0e3fb31b2879f7 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Sun, 23 Jun 2024 18:10:37 +0100 Subject: [PATCH 43/47] remove requires --- packages/desktop-electron/index.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index ba1893469f9..2d8f9d83035 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -1,4 +1,5 @@ import fs from 'fs'; +import NodeModule from 'module'; import path from 'path'; import { @@ -18,8 +19,20 @@ import promiseRetry from 'promise-retry'; import about from './about'; import getMenu from './menu'; import updater from './updater'; +import { + get as getWindowState, + listen as listenToWindowState, +} from './window-state'; + +import './setRequireHook'; + +import './security'; + +const Module: typeof NodeModule & { globalPaths: string[] } = + // eslint-disable-next-line @typescript-eslint/no-explicit-any + NodeModule as unknown as any; -require('module').globalPaths.push(__dirname + '/..'); +Module.globalPaths.push(__dirname + '/..'); // This allows relative URLs to be resolved to app:// which makes // local assets load correctly @@ -29,10 +42,6 @@ protocol.registerSchemesAsPrivileged([ global.fetch = require('node-fetch'); -require('./security'); - -require('./setRequireHook'); - if (!isDev || !process.env.ACTUAL_DOCUMENT_DIR) { process.env.ACTUAL_DOCUMENT_DIR = app.getPath('documents'); } @@ -41,9 +50,6 @@ if (!isDev || !process.env.ACTUAL_DATA_DIR) { process.env.ACTUAL_DATA_DIR = app.getPath('userData'); } -// eslint-disable-next-line import/extensions -const WindowState = require('./window-state.js'); - // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let clientWin: BrowserWindow | null; @@ -97,7 +103,7 @@ function createBackgroundProcess() { } async function createWindow() { - const windowState = await WindowState.get(); + const windowState = await getWindowState(); // Create the browser window. const win = new BrowserWindow({ @@ -120,7 +126,7 @@ async function createWindow() { win.webContents.openDevTools(); } - const unlistenToState = WindowState.listen(win, windowState); + const unlistenToState = listenToWindowState(win, windowState); if (isDev) { win.loadURL(`file://${__dirname}/loading.html`); From b434fd54dbeea956fd0f35ddf52ef2873ab16457 Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Thu, 27 Jun 2024 17:23:33 +0100 Subject: [PATCH 44/47] cleaning up menu --- packages/desktop-electron/index.ts | 6 ++---- packages/desktop-electron/menu.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 3713692c194..46b126559dc 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -194,15 +194,13 @@ function isExternalUrl(url: string) { function updateMenu(budgetId?: string) { const isBudgetOpen = !!budgetId; - const menu = getMenu(isDev, createWindow); + const menu = getMenu(isDev, createWindow, budgetId); const file = menu.items.filter(item => item.label === 'File')[0]; const fileItems = file.submenu?.items || []; fileItems .filter(item => item.label === 'Load Backup...') .forEach(item => { item.enabled = isBudgetOpen; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (item as any).budgetId = budgetId; }); const tools = menu.items.filter(item => item.label === 'Tools')[0]; @@ -373,7 +371,7 @@ ipcMain.on('apply-update', () => { updater.apply(); }); -ipcMain.on('update-menu', (event, budgetId) => { +ipcMain.on('update-menu', (event, budgetId?: string) => { updateMenu(budgetId); }); diff --git a/packages/desktop-electron/menu.js b/packages/desktop-electron/menu.js index fc274511851..d590d50ce6b 100644 --- a/packages/desktop-electron/menu.js +++ b/packages/desktop-electron/menu.js @@ -1,6 +1,6 @@ const { Menu, ipcMain, app, shell } = require('electron'); -function getMenu(isDev, createWindow) { +function getMenu(isDev, createWindow, budgetId = undefined) { const template = [ { label: 'File', @@ -12,7 +12,7 @@ function getMenu(isDev, createWindow) { if (focusedWindow) { if (focusedWindow.webContents.getTitle() === 'Actual') { focusedWindow.webContents.executeJavaScript( - `__actionsForMenu.replaceModal('load-backup', { budgetId: '${item.budgetId}' })`, + `__actionsForMenu.replaceModal('load-backup', { budgetId: '${budgetId}' })`, ); } } From b924d0502b8235ce44c7a926464560f7dae314ff Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Thu, 27 Jun 2024 17:28:59 +0100 Subject: [PATCH 45/47] extra safety --- packages/desktop-electron/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/menu.js b/packages/desktop-electron/menu.js index d590d50ce6b..c97399b4141 100644 --- a/packages/desktop-electron/menu.js +++ b/packages/desktop-electron/menu.js @@ -9,7 +9,7 @@ function getMenu(isDev, createWindow, budgetId = undefined) { label: 'Load Backup...', enabled: false, click(item, focusedWindow) { - if (focusedWindow) { + if (focusedWindow && budgetId) { if (focusedWindow.webContents.getTitle() === 'Actual') { focusedWindow.webContents.executeJavaScript( `__actionsForMenu.replaceModal('load-backup', { budgetId: '${budgetId}' })`, From 18f902e2432102ac9b794f5725784cd7c02cf50e Mon Sep 17 00:00:00 2001 From: mikesglitch Date: Thu, 27 Jun 2024 18:32:25 +0100 Subject: [PATCH 46/47] satisfy the type --- packages/desktop-electron/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/desktop-electron/menu.js b/packages/desktop-electron/menu.js index c97399b4141..37d290c2666 100644 --- a/packages/desktop-electron/menu.js +++ b/packages/desktop-electron/menu.js @@ -1,6 +1,6 @@ const { Menu, ipcMain, app, shell } = require('electron'); -function getMenu(isDev, createWindow, budgetId = undefined) { +function getMenu(isDev, createWindow, budgetId) { const template = [ { label: 'File', From d8561609c719cbcb1423b748a3ed9fb51b33abe8 Mon Sep 17 00:00:00 2001 From: Mike Clark Date: Wed, 3 Jul 2024 21:01:33 +0100 Subject: [PATCH 47/47] keep client-build in gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ec8f4f1d720..25e14cb305c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ node_modules packages/api/dist packages/api/@types packages/crdt/dist +packages/desktop-electron/client-build packages/desktop-electron/build packages/desktop-electron/.electron-symbols packages/desktop-electron/dist