mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 13:23:58 +00:00
bundled electron app starts without error
This commit is contained in:
@@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
||||||
import Screen from './Screen.svelte';
|
import Screen from './Screen.svelte';
|
||||||
import { loadingPluginStore } from './stores';
|
import { loadingPluginStore, subscribeApiDependendStores } from './stores';
|
||||||
import { setAppLoaded } from './utility/appLoadManager';
|
import { setAppLoaded } from './utility/appLoadManager';
|
||||||
import axiosInstance from './utility/axiosInstance';
|
import axiosInstance from './utility/axiosInstance';
|
||||||
import ErrorHandler from './utility/ErrorHandler.svelte';
|
import ErrorHandler from './utility/ErrorHandler.svelte';
|
||||||
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
||||||
import { shouldWaitForElectronInitialize } from './utility/getElectron';
|
import { shouldWaitForElectronInitialize } from './utility/getElectron';
|
||||||
|
import { subscribeConnectionPingers } from './utility/connectionsPinger';
|
||||||
|
import { subscribePermissionCompiler } from './utility/hasPermission';
|
||||||
|
|
||||||
let loadedApi = false;
|
let loadedApi = false;
|
||||||
|
|
||||||
@@ -29,6 +31,13 @@
|
|||||||
const connections = await axiosInstance().get('connections/list');
|
const connections = await axiosInstance().get('connections/list');
|
||||||
const config = await axiosInstance().get('config/get');
|
const config = await axiosInstance().get('config/get');
|
||||||
loadedApi = settings?.data && connections?.data && config?.data;
|
loadedApi = settings?.data && connections?.data && config?.data;
|
||||||
|
|
||||||
|
if (loadedApi) {
|
||||||
|
subscribeApiDependendStores();
|
||||||
|
subscribeConnectionPingers();
|
||||||
|
subscribePermissionCompiler();
|
||||||
|
}
|
||||||
|
|
||||||
if (!loadedApi) {
|
if (!loadedApi) {
|
||||||
console.log('API not initialized correctly, trying again in 1s');
|
console.log('API not initialized correctly, trying again in 1s');
|
||||||
setTimeout(loadApi, 1000);
|
setTimeout(loadApi, 1000);
|
||||||
|
|||||||
@@ -82,9 +82,9 @@
|
|||||||
$: effect = useEffect(() => onJslId(jslid));
|
$: effect = useEffect(() => onJslId(jslid));
|
||||||
function onJslId(jslidVal) {
|
function onJslId(jslidVal) {
|
||||||
if (jslidVal) {
|
if (jslidVal) {
|
||||||
socket.on(`jsldata-stats-${jslidVal}`, handleJslDataStats);
|
socket().on(`jsldata-stats-${jslidVal}`, handleJslDataStats);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`jsldata-stats-${jslidVal}`, handleJslDataStats);
|
socket().off(`jsldata-stats-${jslidVal}`, handleJslDataStats);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,9 @@
|
|||||||
|
|
||||||
function registerRunnerDone(rid) {
|
function registerRunnerDone(rid) {
|
||||||
if (rid) {
|
if (rid) {
|
||||||
socket.on(`runner-done-${rid}`, handleRunnerDone);
|
socket().on(`runner-done-${rid}`, handleRunnerDone);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`runner-done-${rid}`, handleRunnerDone);
|
socket().off(`runner-done-${rid}`, handleRunnerDone);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -66,9 +66,9 @@
|
|||||||
});
|
});
|
||||||
function onSession(sid) {
|
function onSession(sid) {
|
||||||
if (sid) {
|
if (sid) {
|
||||||
socket.on(`session-recordset-${sid}`, handleResultSet);
|
socket().on(`session-recordset-${sid}`, handleResultSet);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`session-recordset-${sid}`, handleResultSet);
|
socket().off(`session-recordset-${sid}`, handleResultSet);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
function registerRunnerDone(rid) {
|
function registerRunnerDone(rid) {
|
||||||
if (rid) {
|
if (rid) {
|
||||||
socket.on(`runner-done-${rid}`, handleRunnerDone);
|
socket().on(`runner-done-${rid}`, handleRunnerDone);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`runner-done-${rid}`, handleRunnerDone);
|
socket().off(`runner-done-${rid}`, handleRunnerDone);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
|
|
||||||
$: effect = useEffect(() => {
|
$: effect = useEffect(() => {
|
||||||
if (eventName) {
|
if (eventName) {
|
||||||
socket.on(eventName, handleInfo);
|
socket().on(eventName, handleInfo);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(eventName, handleInfo);
|
socket().off(eventName, handleInfo);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.fi
|
|||||||
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
||||||
export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
|
export const pinnedDatabases = writableWithStorage([], 'pinnedDatabases');
|
||||||
export const pinnedTables = writableWithStorage([], 'pinnedTables');
|
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 allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
||||||
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
|
export const archiveFilesAsDataSheets = writableWithStorage([], 'archiveFilesAsDataSheets');
|
||||||
export const commandsCustomized = derived([commands, commandsSettings], ([$commands, $commandsSettings]) =>
|
export const commandsCustomized = derived([commands, commandsSettings], ([$commands, $commandsSettings]) =>
|
||||||
@@ -130,15 +130,7 @@ activeTab.subscribe(value => {
|
|||||||
});
|
});
|
||||||
export const getActiveTab = () => activeTabValue;
|
export const getActiveTab = () => activeTabValue;
|
||||||
|
|
||||||
const currentConfigStore = useConfig();
|
|
||||||
let currentConfigValue = null;
|
let currentConfigValue = null;
|
||||||
currentConfigStore.subscribe(value => {
|
|
||||||
currentConfigValue = value;
|
|
||||||
invalidateCommands();
|
|
||||||
if (value.singleDatabase) {
|
|
||||||
currentDatabase.set(value.singleDatabase);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
export const getCurrentConfig = () => currentConfigValue;
|
export const getCurrentConfig = () => currentConfigValue;
|
||||||
|
|
||||||
let recentDatabasesValue = null;
|
let recentDatabasesValue = null;
|
||||||
@@ -161,10 +153,6 @@ currentDatabase.subscribe(value => {
|
|||||||
export const getCurrentDatabase = () => currentDatabaseValue;
|
export const getCurrentDatabase = () => currentDatabaseValue;
|
||||||
|
|
||||||
let currentSettingsValue = null;
|
let currentSettingsValue = null;
|
||||||
useSettings().subscribe(value => {
|
|
||||||
currentSettingsValue = value;
|
|
||||||
invalidateCommands();
|
|
||||||
});
|
|
||||||
export const getCurrentSettings = () => currentSettingsValue || {};
|
export const getCurrentSettings = () => currentSettingsValue || {};
|
||||||
|
|
||||||
let extensionsValue = null;
|
let extensionsValue = null;
|
||||||
@@ -178,3 +166,19 @@ openedConnections.subscribe(value => {
|
|||||||
openedConnectionsValue = value;
|
openedConnectionsValue = value;
|
||||||
});
|
});
|
||||||
export const getOpenedConnections = () => openedConnectionsValue;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,9 +62,9 @@
|
|||||||
});
|
});
|
||||||
function onSession(sid) {
|
function onSession(sid) {
|
||||||
if (sid) {
|
if (sid) {
|
||||||
socket.on(`session-done-${sid}`, handleSessionDone);
|
socket().on(`session-done-${sid}`, handleSessionDone);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`session-done-${sid}`, handleSessionDone);
|
socket().off(`session-done-${sid}`, handleSessionDone);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -95,9 +95,9 @@
|
|||||||
});
|
});
|
||||||
function onSession(sid) {
|
function onSession(sid) {
|
||||||
if (sid) {
|
if (sid) {
|
||||||
socket.on(`session-done-${sid}`, handleSessionDone);
|
socket().on(`session-done-${sid}`, handleSessionDone);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`session-done-${sid}`, handleSessionDone);
|
socket().off(`session-done-${sid}`, handleSessionDone);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -101,9 +101,9 @@
|
|||||||
|
|
||||||
function registerRunnerDone(rid) {
|
function registerRunnerDone(rid) {
|
||||||
if (rid) {
|
if (rid) {
|
||||||
socket.on(`runner-done-${rid}`, handleRunnerDone);
|
socket().on(`runner-done-${rid}`, handleRunnerDone);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off(`runner-done-${rid}`, handleRunnerDone);
|
socket().off(`runner-done-${rid}`, handleRunnerDone);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|||||||
@@ -15,15 +15,19 @@ const doDatabasePing = value => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let openedConnectionsHandle = null;
|
let openedConnectionsHandle = null;
|
||||||
openedConnections.subscribe(value => {
|
|
||||||
doServerPing(value);
|
|
||||||
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
|
|
||||||
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
let currentDatabaseHandle = null;
|
let currentDatabaseHandle = null;
|
||||||
currentDatabase.subscribe(value => {
|
|
||||||
doDatabasePing(value);
|
export function subscribeConnectionPingers() {
|
||||||
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
|
openedConnections.subscribe(value => {
|
||||||
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ export async function exportElectronFile(dataName, reader, format) {
|
|||||||
|
|
||||||
function handleRunnerDone() {
|
function handleRunnerDone() {
|
||||||
closeSnackbar(snackId);
|
closeSnackbar(snackId);
|
||||||
socket.off(`runner-done-${runid}`, handleRunnerDone);
|
socket().off(`runner-done-${runid}`, handleRunnerDone);
|
||||||
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
|
if (isCanceled) showSnackbarError(`Export ${dataName} canceled`);
|
||||||
else showSnackbarInfo(`Export ${dataName} finished`);
|
else showSnackbarInfo(`Export ${dataName} finished`);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on(`runner-done-${runid}`, handleRunnerDone);
|
socket().on(`runner-done-${runid}`, handleRunnerDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveFileToDisk(
|
export async function saveFileToDisk(
|
||||||
|
|||||||
@@ -16,14 +16,13 @@ class ElectronApi {
|
|||||||
let apiInstance = null;
|
let apiInstance = null;
|
||||||
|
|
||||||
function initializeElectron(args) {
|
function initializeElectron(args) {
|
||||||
// console.log('Initialize electron with args:', args);
|
|
||||||
|
|
||||||
apiInstance = new ElectronApi(args);
|
apiInstance = new ElectronApi(args);
|
||||||
if (window['dbgate_recreateAxiosInstance']) {
|
if (window['dbgate_recreateAxiosInstance']) {
|
||||||
// console.log('Recreating axios instance');
|
|
||||||
|
|
||||||
window['dbgate_recreateAxiosInstance']();
|
window['dbgate_recreateAxiosInstance']();
|
||||||
}
|
}
|
||||||
|
if (window['dbgate_recreateSocket']) {
|
||||||
|
window['dbgate_recreateSocket']();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window['dbgate_initializeElectron'] = initializeElectron;
|
window['dbgate_initializeElectron'] = initializeElectron;
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import { useConfig } from './metadataLoaders';
|
|||||||
|
|
||||||
let compiled = null;
|
let compiled = null;
|
||||||
|
|
||||||
const config = useConfig();
|
|
||||||
config.subscribe(value => {
|
|
||||||
if (!value) return;
|
|
||||||
const { permissions } = value;
|
|
||||||
compiled = compilePermissions(permissions);
|
|
||||||
});
|
|
||||||
|
|
||||||
export default function hasPermission(tested) {
|
export default function hasPermission(tested) {
|
||||||
return testPermission(tested, compiled);
|
return testPermission(tested, compiled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function subscribePermissionCompiler() {
|
||||||
|
useConfig().subscribe(value => {
|
||||||
|
if (!value) return;
|
||||||
|
const { permissions } = value;
|
||||||
|
compiled = compilePermissions(permissions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -208,11 +208,11 @@ function useCore(loader, args) {
|
|||||||
handleReload();
|
handleReload();
|
||||||
if (reloadTrigger && socket) {
|
if (reloadTrigger && socket) {
|
||||||
for (const item of getAsArray(reloadTrigger)) {
|
for (const item of getAsArray(reloadTrigger)) {
|
||||||
socket.on(item, handleReload);
|
socket().on(item, handleReload);
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
for (const item of getAsArray(reloadTrigger)) {
|
for (const item of getAsArray(reloadTrigger)) {
|
||||||
socket.off(item, handleReload);
|
socket().off(item, handleReload);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
import resolveApi from './resolveApi';
|
import resolveApi from './resolveApi';
|
||||||
import { cacheClean } from './cache';
|
import { cacheClean } from './cache';
|
||||||
|
import { shouldWaitForElectronInitialize } from './getElectron';
|
||||||
|
|
||||||
const socket = io(resolveApi());
|
let socketInstance;
|
||||||
socket.on('clean-cache', reloadTrigger => cacheClean(reloadTrigger));
|
|
||||||
|
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;
|
export default socket;
|
||||||
|
|||||||
@@ -39,9 +39,9 @@
|
|||||||
$: setDebouncedFilter(filter);
|
$: setDebouncedFilter(filter);
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
socket.on('query-history-changed', reloadItems);
|
socket().on('query-history-changed', reloadItems);
|
||||||
return () => {
|
return () => {
|
||||||
socket.off('query-history-changed', reloadItems);
|
socket().off('query-history-changed', reloadItems);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user