diff --git a/package.json b/package.json index 97a159df9..11caab743 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "publish": "quasar build --mode electron --publish always", "publish-win": "quasar build --mode electron -T win32 --publish always", "publish-linux": "quasar build --mode electron -T linux --publish always", - "test": "vitest run ./test/vitest" + "test": "vitest run ./test/vitest", + "typecheck": "tsc" }, "dependencies": { "@node-steam/vdf": "^2.1.0", @@ -52,7 +53,6 @@ "js-yaml": "^4.1.1", "lodash.debounce": "^4.0.8", "moment": "^2.29.1", - "node-ipc": "^12.0.0", "quasar": "^2.18.6", "quill": "^1.3.7", "sanitize-filename": "^1.6.3", @@ -100,6 +100,7 @@ "sass": "^1.70.0", "sass-loader": "^16.0.5", "sinon": "^11.1.1", + "tsc": "^2.0.4", "tsx": "^4.20.5", "typescript": "^5.9.2", "vite-plugin-node-polyfills": "^0.23.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b5688e2db..fc3d6192c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -89,9 +89,6 @@ importers: moment: specifier: ^2.29.1 version: 2.30.1 - node-ipc: - specifier: ^12.0.0 - version: 12.0.0 quasar: specifier: ^2.18.6 version: 2.19.1 @@ -228,6 +225,9 @@ importers: sinon: specifier: ^11.1.1 version: 11.1.2 + tsc: + specifier: ^2.0.4 + version: 2.0.4 tsx: specifier: ^4.20.5 version: 4.21.0 @@ -1990,9 +1990,6 @@ packages: resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} engines: {node: '>= 12'} - cliui@7.0.4: - resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} - cliui@8.0.1: resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} engines: {node: '>=12'} @@ -2112,10 +2109,6 @@ packages: resolution: {integrity: sha512-7Vv6asjS4gMOuILabD3l739tsaxFQmC+a7pLZm02zyvs8p977bL3zEgq3yDk5rn9B0PbYgIv++jmHcuUab4RhA==} engines: {node: '>=18'} - copyfiles@2.4.1: - resolution: {integrity: sha512-fereAvAvxDrQDOXybk3Qu3dPbOoKoysFMWtkY3mv5BsL8//OSZVL5DCLYqgRfY5cWirgRzlC+WSrxp6Bo3eNZg==} - hasBin: true - core-js@3.49.0: resolution: {integrity: sha512-es1U2+YTtzpwkxVLwAFdSpaIMyQaq0PBgm3YD1W3Qpsn1NAmO3KSgZfu+oGSWVu6NvLHoHCV/aYcsE5wiB7ALg==} @@ -2312,10 +2305,6 @@ packages: eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} - easy-stack@1.0.1: - resolution: {integrity: sha512-wK2sCs4feiiJeFXn3zvY0p41mdU5VUgbgs1rNsc/y5ngFUijdWd+iIN8eoyuZHKB8xN6BL4PdWmzqFmxNg6V2w==} - engines: {node: '>=6.0.0'} - editorconfig@1.0.7: resolution: {integrity: sha512-e0GOtq/aTQhVdNyDU9e02+wz9oDDM+SIOQxWME2QRjzRX5yyLAuHDE+0aE8vHb9XRC8XD37eO2u57+F09JqFhw==} engines: {node: '>=14'} @@ -2479,10 +2468,6 @@ packages: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} - event-pubsub@5.0.3: - resolution: {integrity: sha512-2QiHxshejKgJrYMzSI9MEHrvhmzxBL+eLyiM5IiyjDBySkgwS2+tdtnO3gbx8pEisu/yOFCIhfCb63gCEu0yBQ==} - engines: {node: '>=13.0.0'} - event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -3001,9 +2986,6 @@ packages: resolution: {integrity: sha512-e6rvdUCiQCAuumZslxRJWR/Doq4VpPR82kqclvcS0efgt430SlGIk05vdCN58+VrzgtIcfNODjozVielycD4Sw==} engines: {node: '>=16'} - isarray@0.0.1: - resolution: {integrity: sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==} - isarray@1.0.0: resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==} @@ -3057,14 +3039,6 @@ packages: resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==} engines: {node: '>=14'} - js-message@1.0.7: - resolution: {integrity: sha512-efJLHhLjIyKRewNS9EGZ4UpI8NguuL6fKkhRxVuMmrGV2xN/0APGdQYwLFky5w9naebSZ0OwAGp0G6/2Cg90rA==} - engines: {node: '>=0.6.0'} - - js-queue@2.0.2: - resolution: {integrity: sha512-pbKLsbCfi7kriM3s1J4DDCo7jQkI58zPLHi0heXPzPlj0hjUsm+FesPUbE0DSbIVIK503A36aUBoCN7eMFedkA==} - engines: {node: '>=1.0.0'} - js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -3482,10 +3456,6 @@ packages: node-int64@0.4.0: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} - node-ipc@12.0.0: - resolution: {integrity: sha512-QHJ2gAJiqA3cM7cQiRjLsfCOBRB0TwQ6axYD4FSllQWipEbP6i7Se1dP8EzPKk5J1nCe27W69eqPmCoKyQ61Vg==} - engines: {node: '>=14'} - node-mock-http@1.0.4: resolution: {integrity: sha512-8DY+kFsDkNXy1sJglUfuODx1/opAGJGyrTuFqEoN90oRc2Vk0ZbD4K2qmKXBBEhZQzdKHIVfEJpDU8Ak2NJEvQ==} @@ -3496,9 +3466,6 @@ packages: resolution: {integrity: sha512-X75ZN8DCLftGM5iKwoYLA3rjnrAEs97MkzvSd4q2746Tgpg8b8XWiBGiBG4ZpgcAqBgtgPHTiAc8ZMCvZuikDw==} engines: {node: '>=10'} - noms@0.0.0: - resolution: {integrity: sha512-lNDU9VJaOPxUmXcLb+HQFeUgQQPtMI24Gt6hgfuMHRJgMRHMF/qZ4HJD3GDru4sSw9IQl2jPjAYnQrdIeLbwow==} - nopt@7.2.1: resolution: {integrity: sha512-taM24ViiimT/XntxbPyJQzCG+p4EKOpgD3mxFwW38mGjVUrfERQOeY4EDHjdnptttfHuHQXFx+lTP08Q+mLa/w==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} @@ -3823,9 +3790,6 @@ packages: resolution: {integrity: sha512-BNg9EN3DD3GsDXX7Aa8O4p92sryjkmzYYgmgTAc6CA4uGLEDzFfxOxugu21akOxpcXHiEgsYkC6nPsQvLLLmEg==} hasBin: true - readable-stream@1.0.34: - resolution: {integrity: sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==} - readable-stream@2.3.8: resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==} @@ -4338,9 +4302,6 @@ packages: resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} engines: {node: '>=18'} - string_decoder@0.10.31: - resolution: {integrity: sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==} - string_decoder@1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} @@ -4362,14 +4323,6 @@ packages: strip-literal@3.1.0: resolution: {integrity: sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg==} - strong-type@0.1.6: - resolution: {integrity: sha512-eJe5caH6Pi5oMMeQtIoBPpvNu/s4jiyb63u5tkHNnQXomK+puyQ5i+Z5iTLBr/xUz/pIcps0NSfzzFI34+gAXg==} - engines: {node: '>=12.0.0'} - - strong-type@1.1.0: - resolution: {integrity: sha512-X5Z6riticuH5GnhUyzijfDi1SoXas8ODDyN7K8lJeQK+Jfi4dKdoJGL4CXTskY/ATBcN+rz5lROGn1tAUkOX7g==} - engines: {node: '>=12.21.0'} - sumchecker@3.0.1: resolution: {integrity: sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==} engines: {node: '>= 8.0'} @@ -4432,9 +4385,6 @@ packages: text-decoder@1.2.7: resolution: {integrity: sha512-vlLytXkeP4xvEq2otHeJfSQIRyWxo/oZGEbXrtEEF9Hnmrdly59sUbzZ/QgyWuLYHctCHxFF4tRQZNQ9k60ExQ==} - through2@2.0.5: - resolution: {integrity: sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==} - timers-browserify@2.0.12: resolution: {integrity: sha512-9phl76Cqm6FhSX9Xe1ZUAMLtm1BLkKj2Qd5ApyWkXzsMRaA7dgr81kf4wJmQf/hAvg8EEyJxDo3du/0KlhPiKQ==} engines: {node: '>=0.6.0'} @@ -4506,6 +4456,11 @@ packages: typescript: optional: true + tsc@2.0.4: + resolution: {integrity: sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. + hasBin: true + tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -4595,10 +4550,6 @@ packages: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} - untildify@4.0.0: - resolution: {integrity: sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==} - engines: {node: '>=8'} - unzip-crx-3@0.2.0: resolution: {integrity: sha512-0+JiUq/z7faJ6oifVB5nSwt589v1KCduqIJupNVDoWSXZtWDmjDGO3RAEOvwJ07w90aoXoP4enKsR7ecMrJtWQ==} @@ -4926,10 +4877,6 @@ packages: engines: {node: '>= 14.6'} hasBin: true - yargs-parser@20.2.9: - resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==} - engines: {node: '>=10'} - yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} @@ -4938,10 +4885,6 @@ packages: resolution: {integrity: sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==} engines: {node: ^20.19.0 || ^22.12.0 || >=23} - yargs@16.2.0: - resolution: {integrity: sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==} - engines: {node: '>=10'} - yargs@17.7.2: resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} engines: {node: '>=12'} @@ -6108,12 +6051,6 @@ snapshots: dependencies: '@types/node': 20.19.37 - '@types/glob@7.2.0': - dependencies: - '@types/minimatch': 6.0.0 - '@types/node': 20.19.37 - optional: true - '@types/har-format@1.2.16': {} '@types/http-cache-semantics@4.2.0': {} @@ -6152,12 +6089,6 @@ snapshots: dependencies: undici-types: 7.18.2 - '@types/plist@3.0.5': - dependencies: - '@types/node': 20.19.37 - xmlbuilder: 15.1.1 - optional: true - '@types/qs@6.15.0': {} '@types/quill@2.0.14': @@ -6898,12 +6829,6 @@ snapshots: cli-width@4.1.0: {} - cliui@7.0.4: - dependencies: - string-width: 4.2.3 - strip-ansi: 6.0.1 - wrap-ansi: 7.0.0 - cliui@8.0.1: dependencies: string-width: 4.2.3 @@ -7012,16 +6937,6 @@ snapshots: dependencies: is-what: 5.5.0 - copyfiles@2.4.1: - dependencies: - glob: 7.2.3 - minimatch: 3.1.5 - mkdirp: 1.0.4 - noms: 0.0.0 - through2: 2.0.5 - untildify: 4.0.0 - yargs: 16.2.0 - core-js@3.49.0: {} core-util-is@1.0.3: {} @@ -7238,8 +7153,6 @@ snapshots: eastasianwidth@0.2.0: {} - easy-stack@1.0.1: {} - editorconfig@1.0.7: dependencies: '@one-ini/wasm': 0.1.1 @@ -7498,11 +7411,6 @@ snapshots: etag@1.8.1: {} - event-pubsub@5.0.3: - dependencies: - copyfiles: 2.4.1 - strong-type: 0.1.6 - event-target-shim@5.0.1: {} eventemitter3@2.0.3: {} @@ -8075,8 +7983,6 @@ snapshots: dependencies: is-inside-container: 1.0.0 - isarray@0.0.1: {} - isarray@1.0.0: {} isarray@2.0.5: {} @@ -8119,12 +8025,6 @@ snapshots: js-cookie@3.0.5: {} - js-message@1.0.7: {} - - js-queue@2.0.2: - dependencies: - easy-stack: 1.0.1 - js-tokens@4.0.0: {} js-tokens@9.0.1: {} @@ -8493,13 +8393,6 @@ snapshots: node-int64@0.4.0: {} - node-ipc@12.0.0: - dependencies: - event-pubsub: 5.0.3 - js-message: 1.0.7 - js-queue: 2.0.2 - strong-type: 1.1.0 - node-mock-http@1.0.4: {} node-releases@2.0.36: {} @@ -8534,11 +8427,6 @@ snapshots: util: 0.12.5 vm-browserify: 1.1.2 - noms@0.0.0: - dependencies: - inherits: 2.0.4 - readable-stream: 1.0.34 - nopt@7.2.1: dependencies: abbrev: 2.0.0 @@ -8884,13 +8772,6 @@ snapshots: transitivePeerDependencies: - supports-color - readable-stream@1.0.34: - dependencies: - core-util-is: 1.0.3 - inherits: 2.0.4 - isarray: 0.0.1 - string_decoder: 0.10.31 - readable-stream@2.3.8: dependencies: core-util-is: 1.0.3 @@ -9470,8 +9351,6 @@ snapshots: get-east-asian-width: 1.5.0 strip-ansi: 7.2.0 - string_decoder@0.10.31: {} - string_decoder@1.1.1: dependencies: safe-buffer: 5.1.2 @@ -9494,10 +9373,6 @@ snapshots: dependencies: js-tokens: 9.0.1 - strong-type@0.1.6: {} - - strong-type@1.1.0: {} - sumchecker@3.0.1: dependencies: debug: 4.4.3 @@ -9584,11 +9459,6 @@ snapshots: transitivePeerDependencies: - react-native-b4a - through2@2.0.5: - dependencies: - readable-stream: 2.3.8 - xtend: 4.0.2 - timers-browserify@2.0.12: dependencies: setimmediate: 1.0.5 @@ -9644,6 +9514,8 @@ snapshots: optionalDependencies: typescript: 5.9.3 + tsc@2.0.4: {} + tslib@1.14.1: {} tslib@2.8.1: {} @@ -9720,8 +9592,6 @@ snapshots: unpipe@1.0.0: {} - untildify@4.0.0: {} - unzip-crx-3@0.2.0: dependencies: jszip: 3.10.1 @@ -10041,22 +9911,10 @@ snapshots: yaml@2.8.3: {} - yargs-parser@20.2.9: {} - yargs-parser@21.1.1: {} yargs-parser@22.0.0: {} - yargs@16.2.0: - dependencies: - cliui: 7.0.4 - escalade: 3.2.0 - get-caller-file: 2.0.5 - require-directory: 2.1.1 - string-width: 4.2.3 - y18n: 5.0.8 - yargs-parser: 20.2.9 - yargs@17.7.2: dependencies: cliui: 8.0.1 diff --git a/quasar.config.ts b/quasar.config.ts index 4b6449be1..12f20aa3c 100644 --- a/quasar.config.ts +++ b/quasar.config.ts @@ -2,8 +2,10 @@ // https://v2.quasar.dev/quasar-cli-vite/quasar-config-file import { defineConfig } from '#q-app/wrappers'; +import { ExtendViteConfHandler } from '@quasar/app-vite'; +import { QuasarContext } from '@quasar/app-vite/types/configuration/context'; -export default defineConfig((ctx) => { +export default defineConfig((ctx: QuasarContext) => { const skipPackaging = process.env.SKIP_PACKING === 'true'; return { @@ -68,7 +70,7 @@ export default defineConfig((ctx) => { cssMinify: 'esbuild', minify: 'esbuild', - extendViteConf (viteConf) { + extendViteConf (viteConf: any) { // Force Vite to use esbuild for CSS, overriding any defaults viteConf.build!.cssMinify = 'esbuild'; }, @@ -106,7 +108,7 @@ export default defineConfig((ctx) => { '/_local': { target: 'http://localhost:1337', changeOrigin: true, - rewrite: (path) => path.replace(/^\/_local/, ''), + rewrite: (path: string) => path.replace(/^\/_local/, ''), }, }, }, @@ -274,5 +276,5 @@ export default defineConfig((ctx) => { */ extraScripts: [], }, - }; + } as any; }); diff --git a/src-electron/electron-main.ts b/src-electron/electron-main.ts index d407246f2..2ce060a57 100644 --- a/src-electron/electron-main.ts +++ b/src-electron/electron-main.ts @@ -2,12 +2,12 @@ import { app, BrowserWindow, ipcMain, nativeTheme, protocol } from 'electron'; import { Listeners } from './ipcListeners'; import { Persist } from './window-state-persist'; import path from 'path'; -import ipcServer from 'node-ipc'; import fs from 'fs'; import { fileURLToPath } from 'url'; import 'app/src-electron/ipc/init-ipc'; import { hookIpc } from 'app/src-electron/ipc/init-ipc'; +// @ts-ignore app.allowRendererProcessReuse = true; try { @@ -24,14 +24,15 @@ try { const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file const __dirname = path.dirname(__filename); +const anyGlobal: any = global; if (process.env.PROD) { - global.__statics = __dirname; - global.__statics = path.join(__dirname, 'statics').replace(/\\/g, '\\\\'); - global.__assets = path.join(__dirname, 'assets').replace(/\\/g, '\\\\'); + anyGlobal.__statics = __dirname; + anyGlobal.__statics = path.join(__dirname, 'statics').replace(/\\/g, '\\\\'); + anyGlobal.__assets = path.join(__dirname, 'assets').replace(/\\/g, '\\\\'); } -let mainWindow; +let mainWindow: BrowserWindow | null = null; async function createWindow() { @@ -45,7 +46,7 @@ async function createWindow() { height: windowSize.height, useContentSize: true, icon: path.resolve(__dirname, 'icons/icon.png'), - autoHideMenuBar: process.env.PROD, + autoHideMenuBar: !!process.env.PROD, webPreferences: { preload: path.resolve( fileURLToPath(new URL('.', import.meta.url)), @@ -79,34 +80,35 @@ async function createWindow() { }); } -app.on('ready', async () => { - await createWindow(); - let reqLockSuccess = app.requestSingleInstanceLock(); - if (!reqLockSuccess) { - // If this isn't the single instance, - // connect to r2mm IPC and send the install parameter. - ipcServer.connectTo('r2mm', () => { - for (let i = 0; i < process.argv.length; i++) { - if (process.argv[i].toLowerCase().search('ror2mm://') >= 0) { - ipcServer.of.r2mm.emit('install', process.argv[i]); - break; - } - } - app.quit(); - }); +const extractInstallUrl = (argv: string[]): string | null => + argv.find((arg) => arg.toLowerCase().includes('ror2mm://')) ?? null; + +function dispatchInstallUrl(url: string | null) { + if (!url || !mainWindow) return; + const { webContents } = mainWindow; + if (webContents.isLoading()) { + webContents.once('did-finish-load', () => ipcMain.emit('install-via-thunderstore', url)); } else { - ipcServer.config.id = 'r2mm'; - ipcServer.serve( - '/tmp/app.r2mm', - () => { - ipcServer.server.on('install', (res) => { - ipcMain.emit('install-via-thunderstore', res); - }); - } - ); - ipcServer.server.start(); + ipcMain.emit('install-via-thunderstore', url); } -}); +} + +if (!app.requestSingleInstanceLock()) { + app.quit(); +} else { + app.on('second-instance', (_event, argv) => { + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); + } + dispatchInstallUrl(extractInstallUrl(argv)); + }); + + app.on('ready', async () => { + await createWindow(); + dispatchInstallUrl(extractInstallUrl(process.argv)); + }); +} protocol.registerSchemesAsPrivileged([ { @@ -125,7 +127,7 @@ app.whenReady().then(() => { if (fs.existsSync(pathname)) { callback(pathname); } else { - callback(path.join(global.__statics, 'unknown.png')); + callback(path.join(anyGlobal.__statics, 'unknown.png')); } }); diff --git a/src-electron/ipcListeners.ts b/src-electron/ipcListeners.ts index 41ef0ee1d..6aa81ddb0 100644 --- a/src-electron/ipcListeners.ts +++ b/src-electron/ipcListeners.ts @@ -6,6 +6,7 @@ import path from 'path'; let browserWindow: BrowserWindow; let app: App; +const anyGlobal: any = global; export class Listeners { constructor(window: BrowserWindow, electronApp: App) { @@ -54,7 +55,7 @@ ipcMain.on('restart', () => { ipcMain.on('get-assets-path', () => { if (process.env.PROD) { - browserWindow.webContents.send('receive-assets-path', global.__statics); + browserWindow.webContents.send('receive-assets-path', anyGlobal.__statics); } else { browserWindow.webContents.send('receive-assets-path', 'src/statics/'); } diff --git a/src-electron/window-state-persist.ts b/src-electron/window-state-persist.ts index 9897cd7b8..518d86061 100644 --- a/src-electron/window-state-persist.ts +++ b/src-electron/window-state-persist.ts @@ -1,12 +1,18 @@ import yaml from 'yaml'; import path from 'path'; import fs from 'fs-extra'; +import { App, BrowserWindow } from 'electron/main'; -let resizeTimeout = undefined; +let resizeTimeout: NodeJS.Timeout | undefined = undefined; + +type SizeType = { + defaultWidth: number; + defaultHeight: number; +} export class Persist { - static getSize(app, { defaultWidth, defaultHeight }) { + static getSize(app: App, { defaultWidth, defaultHeight }: SizeType) { const configFilePath = path.join(app.getPath('appData'), 'r2modmanPlus-local', 'config', 'window-state.yml'); if (fs.existsSync(configFilePath)) { try { @@ -31,7 +37,7 @@ export class Persist { }; } - static handle(window, app) { + static handle(window: BrowserWindow, app: App) { window.on('resize', () => { if (resizeTimeout !== undefined) { clearTimeout(resizeTimeout); @@ -52,7 +58,7 @@ export class Persist { } resizeTimeout = setTimeout(() => { const winSize = window.getSize(); - const previousSize = this.getSize(app, {defaultWidth: winSize[0], defaultHeight: winSize[1]}); + const previousSize = this.getSize(app, {defaultWidth: winSize[0], defaultHeight: winSize[1]} as SizeType); const yamlString = yaml.stringify({ 'windowWidth': previousSize.width, 'windowHeight': previousSize.height, @@ -77,7 +83,7 @@ export class Persist { }); } - static saveState(app, state) { + static saveState(app: App, state: string) { const configPath = path.join(app.getPath('appData'), 'r2modmanPlus-local', 'config'); const configFilePath = path.join(configPath, 'window-state.yml'); try {