mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 19:14:22 -05:00
:electron: Restart server silently when adding self signed cert and add some logs (#3431)
* restart server silently on add self signed cert and add some logging * release notes * fix name * updating names to be more specific * removing setloading * feedback
This commit is contained in:
@@ -51,6 +51,8 @@ global.Actual = {
|
||||
window.location.reload();
|
||||
},
|
||||
|
||||
restartElectronServer: () => {},
|
||||
|
||||
openFileDialog: async ({ filters = [] }) => {
|
||||
return new Promise(resolve => {
|
||||
let createdElement = false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-strict-ignore
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Trans, useTranslation } from 'react-i18next';
|
||||
|
||||
import {
|
||||
@@ -34,8 +34,15 @@ export function ConfigServer() {
|
||||
}, [currentUrl]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const restartElectronServer = useCallback(() => {
|
||||
globalThis.window.Actual.restartElectronServer();
|
||||
setError(null);
|
||||
}, []);
|
||||
|
||||
const [_serverSelfSignedCert, setServerSelfSignedCert] = useGlobalPref(
|
||||
'serverSelfSignedCert',
|
||||
restartElectronServer,
|
||||
);
|
||||
|
||||
function getErrorMessage(error: string) {
|
||||
@@ -101,7 +108,6 @@ export function ConfigServer() {
|
||||
|
||||
if (selfSignedCertificateLocation) {
|
||||
setServerSelfSignedCert(selfSignedCertificateLocation[0]);
|
||||
globalThis.window.Actual.relaunch(); // relaunch to use the certificate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,21 @@ type SetGlobalPrefAction<K extends keyof GlobalPrefs> = (
|
||||
|
||||
export function useGlobalPref<K extends keyof GlobalPrefs>(
|
||||
prefName: K,
|
||||
onSaveGlobalPrefs?: () => void,
|
||||
): [GlobalPrefs[K], SetGlobalPrefAction<K>] {
|
||||
const dispatch = useDispatch();
|
||||
const setGlobalPref = useCallback<SetGlobalPrefAction<K>>(
|
||||
value => {
|
||||
dispatch(saveGlobalPrefs({ [prefName]: value } as GlobalPrefs));
|
||||
dispatch(
|
||||
saveGlobalPrefs(
|
||||
{
|
||||
[prefName]: value,
|
||||
} as GlobalPrefs,
|
||||
onSaveGlobalPrefs,
|
||||
),
|
||||
);
|
||||
},
|
||||
[prefName, dispatch],
|
||||
[prefName, dispatch, onSaveGlobalPrefs],
|
||||
);
|
||||
const globalPref = useSelector(
|
||||
(state: State) => state.prefs.global?.[prefName] as GlobalPrefs[K],
|
||||
|
||||
@@ -297,6 +297,12 @@ ipcMain.on('get-bootstrap-data', event => {
|
||||
event.returnValue = payload;
|
||||
});
|
||||
|
||||
ipcMain.handle('restart-server', () => {
|
||||
serverProcess.kill();
|
||||
serverProcess = null;
|
||||
createBackgroundProcess();
|
||||
});
|
||||
|
||||
ipcMain.handle('relaunch', () => {
|
||||
app.relaunch();
|
||||
app.exit();
|
||||
|
||||
@@ -34,6 +34,10 @@ contextBridge.exposeInMainWorld('Actual', {
|
||||
ipcRenderer.invoke('relaunch');
|
||||
},
|
||||
|
||||
restartElectronServer: () => {
|
||||
ipcRenderer.invoke('restart-server');
|
||||
},
|
||||
|
||||
openFileDialog: (opts: OpenFileDialogPayload) => {
|
||||
return ipcRenderer.invoke('open-file-dialog', opts);
|
||||
},
|
||||
|
||||
@@ -48,12 +48,16 @@ export function loadGlobalPrefs() {
|
||||
};
|
||||
}
|
||||
|
||||
export function saveGlobalPrefs(prefs: prefs.GlobalPrefs) {
|
||||
export function saveGlobalPrefs(
|
||||
prefs: prefs.GlobalPrefs,
|
||||
onSaveGlobalPrefs?: () => void,
|
||||
) {
|
||||
return async (dispatch: Dispatch) => {
|
||||
await send('save-global-prefs', prefs);
|
||||
dispatch({
|
||||
type: constants.MERGE_GLOBAL_PREFS,
|
||||
globalPrefs: prefs,
|
||||
});
|
||||
onSaveGlobalPrefs?.();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
// @ts-strict-ignore
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
export const fetch = (input: RequestInfo | URL, options?: RequestInit) => {
|
||||
return nodeFetch(input, {
|
||||
...options,
|
||||
headers: {
|
||||
...options?.headers,
|
||||
origin: 'app://actual',
|
||||
},
|
||||
});
|
||||
export const fetch = async (
|
||||
input: RequestInfo | URL,
|
||||
options?: RequestInit,
|
||||
) => {
|
||||
try {
|
||||
return await nodeFetch(input, {
|
||||
...options,
|
||||
headers: {
|
||||
...options?.headers,
|
||||
origin: 'app://actual',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error); // log error
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
1
packages/loot-core/typings/window.d.ts
vendored
1
packages/loot-core/typings/window.d.ts
vendored
@@ -15,6 +15,7 @@ declare global {
|
||||
opts: Parameters<import('electron').Dialog['showOpenDialogSync']>[0],
|
||||
) => Promise<string[]>;
|
||||
relaunch: () => void;
|
||||
restartElectronServer: () => void;
|
||||
};
|
||||
|
||||
__navigate?: import('react-router').NavigateFunction;
|
||||
|
||||
6
upcoming-release-notes/3431.md
Normal file
6
upcoming-release-notes/3431.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Maintenance
|
||||
authors: [MikesGlitch]
|
||||
---
|
||||
|
||||
Restart server silently when adding self signed cert and add some logs
|
||||
Reference in New Issue
Block a user