Skip to content
Snippets Groups Projects
Unverified Commit 3743a328 authored by Michael Clark's avatar Michael Clark Committed by GitHub
Browse files

: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
parent 6c87d859
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,8 @@ global.Actual = {
window.location.reload();
},
restartElectronServer: () => {},
openFileDialog: async ({ filters = [] }) => {
return new Promise(resolve => {
let createdElement = false;
......
// @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?.();
};
}
// @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;
}
};
......@@ -15,6 +15,7 @@ declare global {
opts: Parameters<import('electron').Dialog['showOpenDialogSync']>[0],
) => Promise<string[]>;
relaunch: () => void;
restartElectronServer: () => void;
};
__navigate?: import('react-router').NavigateFunction;
......
---
category: Maintenance
authors: [MikesGlitch]
---
Restart server silently when adding self signed cert and add some logs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment