bundled electron app starts without error

This commit is contained in:
Jan Prochazka 2021-12-16 13:25:57 +01:00
parent e636987f31
commit 588b8b23f9
17 changed files with 91 additions and 59 deletions

View File

@ -7,12 +7,14 @@
import PluginsProvider from './plugins/PluginsProvider.svelte';
import Screen from './Screen.svelte';
import { loadingPluginStore } from './stores';
import { loadingPluginStore, subscribeApiDependendStores } from './stores';
import { setAppLoaded } from './utility/appLoadManager';
import axiosInstance from './utility/axiosInstance';
import ErrorHandler from './utility/ErrorHandler.svelte';
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
import { shouldWaitForElectronInitialize } from './utility/getElectron';
import { subscribeConnectionPingers } from './utility/connectionsPinger';
import { subscribePermissionCompiler } from './utility/hasPermission';
let loadedApi = false;
@ -29,6 +31,13 @@
const connections = await axiosInstance().get('connections/list');
const config = await axiosInstance().get('config/get');
loadedApi = settings?.data && connections?.data && config?.data;
if (loadedApi) {
subscribeApiDependendStores();
subscribeConnectionPingers();
subscribePermissionCompiler();
}
if (!loadedApi) {
console.log('API not initialized correctly, trying again in 1s');
setTimeout(loadApi, 1000);

View File

@ -82,9 +82,9 @@
$: effect = useEffect(() => onJslId(jslid));
function onJslId(jslidVal) {
if (jslidVal) {
socket.on(`jsldata-stats-${jslidVal}`, handleJslDataStats);
socket().on(`jsldata-stats-${jslidVal}`, handleJslDataStats);
return () => {
socket.off(`jsldata-stats-${jslidVal}`, handleJslDataStats);
socket().off(`jsldata-stats-${jslidVal}`, handleJslDataStats);
};
}
}

View File

@ -67,9 +67,9 @@
function registerRunnerDone(rid) {
if (rid) {
socket.on(`runner-done-${rid}`, handleRunnerDone);
socket().on(`runner-done-${rid}`, handleRunnerDone);
return () => {
socket.off(`runner-done-${rid}`, handleRunnerDone);
socket().off(`runner-done-${rid}`, handleRunnerDone);
};
} else {
return () => {};

View File

@ -66,9 +66,9 @@
});
function onSession(sid) {
if (sid) {
socket.on(`session-recordset-${sid}`, handleResultSet);
socket().on(`session-recordset-${sid}`, handleResultSet);
return () => {
socket.off(`session-recordset-${sid}`, handleResultSet);
socket().off(`session-recordset-${sid}`, handleResultSet);
};
}
return () => {};

View File

@ -22,9 +22,9 @@
function registerRunnerDone(rid) {
if (rid) {
socket.on(`runner-done-${rid}`, handleRunnerDone);
socket().on(`runner-done-${rid}`, handleRunnerDone);
return () => {
socket.off(`runner-done-${rid}`, handleRunnerDone);
socket().off(`runner-done-${rid}`, handleRunnerDone);
};
} else {
return () => {};

View File

@ -30,9 +30,9 @@
$: effect = useEffect(() => {
if (eventName) {
socket.on(eventName, handleInfo);
socket().on(eventName, handleInfo);
return () => {
socket.off(eventName, handleInfo);
socket().off(eventName, handleInfo);
};
}
return () => {};

View File

@ -44,7 +44,7 @@ export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.fi
export const recentDatabases = writableWithStorage([], 'recentDatabases');
export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
export const pinnedTables = writableWithStorage([], 'pinnedTables');
export const commandsSettings = derived(useSettings(), (config: any) => (config || {}).commands || {});
export const commandsSettings = writable({});
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
export const commandsCustomized = derived([commands, commandsSettings], ([$commands, $commandsSettings]) =>
@ -130,15 +130,7 @@ activeTab.subscribe(value => {
});
export const getActiveTab = () => activeTabValue;
const currentConfigStore = useConfig();
let currentConfigValue = null;
currentConfigStore.subscribe(value => {
currentConfigValue = value;
invalidateCommands();
if (value.singleDatabase) {
currentDatabase.set(value.singleDatabase);
}
});
export const getCurrentConfig = () => currentConfigValue;
let recentDatabasesValue = null;
@ -161,10 +153,6 @@ currentDatabase.subscribe(value => {
export const getCurrentDatabase = () => currentDatabaseValue;
let currentSettingsValue = null;
useSettings().subscribe(value => {
currentSettingsValue = value;
invalidateCommands();
});
export const getCurrentSettings = () => currentSettingsValue || {};
let extensionsValue = null;
@ -178,3 +166,19 @@ openedConnections.subscribe(value => {
openedConnectionsValue = value;
});
export const getOpenedConnections = () => openedConnectionsValue;
export function subscribeApiDependendStores() {
useSettings().subscribe(value => {
currentSettingsValue = value;
commandsSettings.set((value || {}).commands || {});
invalidateCommands();
});
useConfig().subscribe(value => {
currentConfigValue = value;
invalidateCommands();
if (value.singleDatabase) {
currentDatabase.set(value.singleDatabase);
}
});
}

View File

@ -62,9 +62,9 @@
});
function onSession(sid) {
if (sid) {
socket.on(`session-done-${sid}`, handleSessionDone);
socket().on(`session-done-${sid}`, handleSessionDone);
return () => {
socket.off(`session-done-${sid}`, handleSessionDone);
socket().off(`session-done-${sid}`, handleSessionDone);
};
}
return () => {};

View File

@ -95,9 +95,9 @@
});
function onSession(sid) {
if (sid) {
socket.on(`session-done-${sid}`, handleSessionDone);
socket().on(`session-done-${sid}`, handleSessionDone);
return () => {
socket.off(`session-done-${sid}`, handleSessionDone);
socket().off(`session-done-${sid}`, handleSessionDone);
};
}
return () => {};

View File

@ -101,9 +101,9 @@
function registerRunnerDone(rid) {
if (rid) {
socket.on(`runner-done-${rid}`, handleRunnerDone);
socket().on(`runner-done-${rid}`, handleRunnerDone);
return () => {
socket.off(`runner-done-${rid}`, handleRunnerDone);
socket().off(`runner-done-${rid}`, handleRunnerDone);
};
} else {
return () => {};

View File

@ -15,15 +15,19 @@ const doDatabasePing = value => {
};
let openedConnectionsHandle = null;
openedConnections.subscribe(value => {
doServerPing(value);
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
});
let currentDatabaseHandle = null;
currentDatabase.subscribe(value => {
doDatabasePing(value);
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
});
export function subscribeConnectionPingers() {
openedConnections.subscribe(value => {
doServerPing(value);
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
});
currentDatabase.subscribe(value => {
doDatabasePing(value);
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
});
}

View File

@ -48,12 +48,12 @@ export async function exportElectronFile(dataName, reader, format) {
function handleRunnerDone() {
closeSnackbar(snackId);
socket.off(`runner-done-${runid}`, handleRunnerDone);
socket().off(`runner-done-${runid}`, handleRunnerDone);
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
else showSnackbarInfo(`Export ${dataName} finished`);
}
socket.on(`runner-done-${runid}`, handleRunnerDone);
socket().on(`runner-done-${runid}`, handleRunnerDone);
}
export async function saveFileToDisk(

View File

@ -16,14 +16,13 @@ class ElectronApi {
let apiInstance = null;
function initializeElectron(args) {
// console.log('Initialize electron with args:', args);
apiInstance = new ElectronApi(args);
if (window['dbgate_recreateAxiosInstance']) {
// console.log('Recreating axios instance');
window['dbgate_recreateAxiosInstance']();
}
if (window['dbgate_recreateSocket']) {
window['dbgate_recreateSocket']();
}
}
window['dbgate_initializeElectron'] = initializeElectron;

View File

@ -3,13 +3,14 @@ import { useConfig } from './metadataLoaders';
let compiled = null;
const config = useConfig();
config.subscribe(value => {
if (!value) return;
const { permissions } = value;
compiled = compilePermissions(permissions);
});
export default function hasPermission(tested) {
return testPermission(tested, compiled);
}
export function subscribePermissionCompiler() {
useConfig().subscribe(value => {
if (!value) return;
const { permissions } = value;
compiled = compilePermissions(permissions);
});
}

View File

@ -208,11 +208,11 @@ function useCore(loader, args) {
handleReload();
if (reloadTrigger && socket) {
for (const item of getAsArray(reloadTrigger)) {
socket.on(item, handleReload);
socket().on(item, handleReload);
}
return () => {
for (const item of getAsArray(reloadTrigger)) {
socket.off(item, handleReload);
socket().off(item, handleReload);
}
};
}

View File

@ -1,8 +1,23 @@
import io from 'socket.io-client';
import resolveApi from './resolveApi';
import { cacheClean } from './cache';
import { shouldWaitForElectronInitialize } from './getElectron';
const socket = io(resolveApi());
socket.on('clean-cache', reloadTrigger => cacheClean(reloadTrigger));
let socketInstance;
function recreateSocket() {
if (shouldWaitForElectronInitialize()) return;
socketInstance = io(resolveApi());
socketInstance.on('clean-cache', reloadTrigger => cacheClean(reloadTrigger));
}
window['dbgate_recreateSocket'] = recreateSocket;
recreateSocket();
function socket() {
return socketInstance;
}
export default socket;

View File

@ -39,9 +39,9 @@
$: setDebouncedFilter(filter);
onMount(() => {
socket.on('query-history-changed', reloadItems);
socket().on('query-history-changed', reloadItems);
return () => {
socket.off('query-history-changed', reloadItems);
socket().off('query-history-changed', reloadItems);
};
});
</script>