Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
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[];
MikesGlitch marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
Loading