:electron: server.js ➡️ server.ts (#2995)

This commit is contained in:
Michael Clark
2024-07-07 13:31:26 +01:00
committed by GitHub
parent f36c5e002b
commit a28ea6be8f
6 changed files with 38 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
import fs from 'fs';
import NodeModule from 'module';
import Module from 'module';
import path from 'path';
import {
@@ -14,6 +14,8 @@ import {
UtilityProcess,
} from 'electron';
import isDev from 'electron-is-dev';
// @ts-strict-ignore
import fetch from 'node-fetch';
import promiseRetry from 'promise-retry';
import { getMenu } from './menu';
@@ -26,10 +28,6 @@ import './setRequireHook';
import './security';
const Module: typeof NodeModule & { globalPaths: string[] } =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
NodeModule as unknown as any;
Module.globalPaths.push(__dirname + '/..');
// This allows relative URLs to be resolved to app:// which makes
@@ -38,7 +36,7 @@ protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { standard: true } },
]);
global.fetch = require('node-fetch');
global.fetch = fetch;
if (!isDev || !process.env.ACTUAL_DOCUMENT_DIR) {
process.env.ACTUAL_DOCUMENT_DIR = app.getPath('documents');

View File

@@ -0,0 +1,8 @@
declare module 'module' {
const globalPaths: string[];
}
// bundles not available until we build them
declare module 'loot-core/lib-dist/bundle.desktop.js' {
const initApp: (isDev: boolean) => void;
}

View File

@@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script src="server.js"></script>
</head>
<body>
</body>
</html>

View File

@@ -1,15 +0,0 @@
require('./setRequireHook');
require('module').globalPaths.push(__dirname + '/..');
global.fetch = require('node-fetch');
// Lazy load backend code
function getBackend() {
// eslint-disable-next-line import/extensions
return require('loot-core/lib-dist/bundle.desktop.js');
}
const isDev = false;
// Start the app
getBackend().initApp(isDev);

View File

@@ -0,0 +1,20 @@
import Module from 'module';
// @ts-strict-ignore
import fetch from 'node-fetch';
import './setRequireHook';
Module.globalPaths.push(__dirname + '/..');
global.fetch = fetch;
const lazyLoadBackend = async (isDev: boolean) => {
// eslint-disable-next-line import/extensions
const bundle = await import('loot-core/lib-dist/bundle.desktop.js');
bundle.initApp(isDev);
};
const isDev = false;
// Start the app
lazyLoadBackend(isDev);

View File

@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---
Update Electron server file to use typescript