Skip to content

Commit

Permalink
:electron: server.js ➡️ server.ts (#2995)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikesGlitch authored Jul 7, 2024
1 parent f36c5e0 commit a28ea6b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
10 changes: 4 additions & 6 deletions packages/desktop-electron/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import NodeModule from 'module';
import Module from 'module';
import path from 'path';

import {
Expand All @@ -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';
Expand All @@ -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
Expand All @@ -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');
Expand Down
8 changes: 8 additions & 0 deletions packages/desktop-electron/modules.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 0 additions & 8 deletions packages/desktop-electron/server.html

This file was deleted.

15 changes: 0 additions & 15 deletions packages/desktop-electron/server.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/desktop-electron/server.ts
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 6 additions & 0 deletions upcoming-release-notes/2995.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---

Update Electron server file to use typescript

0 comments on commit a28ea6b

Please sign in to comment.