mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 19:13:59 +00:00
keyboard settings saved to server
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
const fs = require('fs-extra');
|
||||||
|
const path = require('path');
|
||||||
|
const { datadir } = require('../utility/directories');
|
||||||
|
const hasPermission = require('../utility/hasPermission');
|
||||||
|
const socket = require('../utility/socket');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
const currentVersion = require('../currentVersion');
|
const currentVersion = require('../currentVersion');
|
||||||
const platformInfo = require('../utility/platformInfo');
|
const platformInfo = require('../utility/platformInfo');
|
||||||
|
|
||||||
@@ -38,4 +45,29 @@ module.exports = {
|
|||||||
return platformInfo;
|
return platformInfo;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSettings_meta: 'get',
|
||||||
|
async getSettings() {
|
||||||
|
try {
|
||||||
|
return JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }));
|
||||||
|
} catch (err) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateSettings_meta: 'post',
|
||||||
|
async updateSettings(values) {
|
||||||
|
if (!hasPermission(`settings/change`)) return false;
|
||||||
|
const oldSettings = await this.getSettings();
|
||||||
|
try {
|
||||||
|
const updated = {
|
||||||
|
...oldSettings,
|
||||||
|
...values,
|
||||||
|
};
|
||||||
|
await fs.writeFile(path.join(datadir(), 'settings.json'), JSON.stringify(updated, undefined, 2));
|
||||||
|
socket.emitChanged(`settings-changed`);
|
||||||
|
return updated;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { openElectronFile } from '../utility/openElectronFile';
|
|||||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||||
import { getCurrentConfig, getCurrentDatabase } from '../stores';
|
import { getCurrentConfig, getCurrentDatabase } from '../stores';
|
||||||
import './recentDatabaseSwitch';
|
import './recentDatabaseSwitch';
|
||||||
|
import hasPermission from '../utility/hasPermission';
|
||||||
|
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
|
|
||||||
@@ -203,6 +204,7 @@ registerCommand({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (hasPermission('settings/change')) {
|
||||||
registerCommand({
|
registerCommand({
|
||||||
id: 'settings.commands',
|
id: 'settings.commands',
|
||||||
category: 'Settings',
|
category: 'Settings',
|
||||||
@@ -216,6 +218,7 @@ registerCommand({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function registerFileCommands({
|
export function registerFileCommands({
|
||||||
idPrefix,
|
idPrefix,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
import FormSubmit from '../forms/FormSubmit.svelte';
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
import FormTextField from '../forms/FormTextField.svelte';
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import { customKeyboardShortcuts } from '../stores';
|
import { commandsSettings } from '../stores';
|
||||||
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
import KeyboardModal from './KeyboardModal.svelte';
|
import KeyboardModal from './KeyboardModal.svelte';
|
||||||
import ModalBase from './ModalBase.svelte';
|
import ModalBase from './ModalBase.svelte';
|
||||||
import { closeCurrentModal, showModal } from './modalTools';
|
import { closeCurrentModal, showModal } from './modalTools';
|
||||||
@@ -41,13 +42,15 @@
|
|||||||
value="OK"
|
value="OK"
|
||||||
on:click={e => {
|
on:click={e => {
|
||||||
closeCurrentModal();
|
closeCurrentModal();
|
||||||
customKeyboardShortcuts.update(list => ({
|
axiosInstance.post('config/update-settings', {
|
||||||
...list,
|
commands: {
|
||||||
|
...$commandsSettings,
|
||||||
[command.id]: {
|
[command.id]: {
|
||||||
keyText: e.detail.keyText,
|
keyText: e.detail.keyText,
|
||||||
customKeyboardShortcut: true,
|
customKeyboardShortcut: true,
|
||||||
},
|
},
|
||||||
}));
|
},
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<FormStyledButton
|
<FormStyledButton
|
||||||
@@ -55,7 +58,9 @@
|
|||||||
value="Reset"
|
value="Reset"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
closeCurrentModal();
|
closeCurrentModal();
|
||||||
customKeyboardShortcuts.update(list => _.omit(list, [command.id]));
|
axiosInstance.post('config/update-settings', {
|
||||||
|
commands: _.omit($commandsSettings, [command.id]),
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<FormStyledButton type="button" value="Close" on:click={closeCurrentModal} />
|
<FormStyledButton type="button" value="Close" on:click={closeCurrentModal} />
|
||||||
|
|||||||
@@ -30,9 +30,12 @@
|
|||||||
const command = commands[item.command];
|
const command = commands[item.command];
|
||||||
if (command) {
|
if (command) {
|
||||||
return {
|
return {
|
||||||
text: command.name,
|
text: command.menuName || command.toolbarName || command.name,
|
||||||
keyText: command.keyText || command.keyTextFromGroup,
|
keyText: command.keyText || command.keyTextFromGroup,
|
||||||
onClick: command.onClick,
|
onClick: () => {
|
||||||
|
if (command.getSubCommands) visibleCommandPalette.set(command);
|
||||||
|
else if (command.onClick) command.onClick();
|
||||||
|
},
|
||||||
disabled: !command.enabled,
|
disabled: !command.enabled,
|
||||||
hideDisabled: item.hideDisabled,
|
hideDisabled: item.hideDisabled,
|
||||||
};
|
};
|
||||||
@@ -48,7 +51,7 @@
|
|||||||
import clickOutside from '../utility/clickOutside';
|
import clickOutside from '../utility/clickOutside';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { commands, commandsCustomized } from '../stores';
|
import { commandsCustomized, visibleCommandPalette } from '../stores';
|
||||||
import { extractMenuItems } from '../utility/contextMenu';
|
import { extractMenuItems } from '../utility/contextMenu';
|
||||||
|
|
||||||
export let items;
|
export let items;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ExtensionsDirectory } from 'dbgate-types';
|
|||||||
import invalidateCommands from './commands/invalidateCommands';
|
import invalidateCommands from './commands/invalidateCommands';
|
||||||
import getElectron from './utility/getElectron';
|
import getElectron from './utility/getElectron';
|
||||||
import { GlobalCommand } from './commands/registerCommand';
|
import { GlobalCommand } from './commands/registerCommand';
|
||||||
import { useConfig } from './utility/metadataLoaders';
|
import { useConfig, useSettings } from './utility/metadataLoaders';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
interface TabDefinition {
|
interface TabDefinition {
|
||||||
@@ -41,15 +41,15 @@ export const currentTheme = writableWithStorage('theme-light', 'currentTheme');
|
|||||||
export const activeTabId = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)?.tabid);
|
export const activeTabId = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected)?.tabid);
|
||||||
export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected));
|
export const activeTab = derived([openedTabs], ([$openedTabs]) => $openedTabs.find(x => x.selected));
|
||||||
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
export const recentDatabases = writableWithStorage([], 'recentDatabases');
|
||||||
export const customKeyboardShortcuts = writableWithStorage({}, 'customKeyboardShortcuts');
|
export const commandsSettings = derived(useSettings(), (config: any) => (config || {}).commands || {});
|
||||||
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
export const allResultsInOneTabDefault = writableWithStorage(false, 'allResultsInOneTabDefault');
|
||||||
export const commandsCustomized = derived(
|
export const commandsCustomized = derived(
|
||||||
[commands, customKeyboardShortcuts],
|
[commands, commandsSettings],
|
||||||
([$commands, $customKeyboardShortcuts]) =>
|
([$commands, $commandsSettings]) =>
|
||||||
_.mapValues($commands, (v, k) => ({
|
_.mapValues($commands, (v, k) => ({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
...v,
|
...v,
|
||||||
...$customKeyboardShortcuts[k],
|
...$commandsSettings[k],
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ const configLoader = () => ({
|
|||||||
reloadTrigger: 'config-changed',
|
reloadTrigger: 'config-changed',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const settingsLoader = () => ({
|
||||||
|
url: 'config/get-settings',
|
||||||
|
params: {},
|
||||||
|
reloadTrigger: 'settings-changed',
|
||||||
|
});
|
||||||
|
|
||||||
const platformInfoLoader = () => ({
|
const platformInfoLoader = () => ({
|
||||||
url: 'config/platform-info',
|
url: 'config/platform-info',
|
||||||
params: {},
|
params: {},
|
||||||
@@ -333,6 +339,13 @@ export function useConfig() {
|
|||||||
return useCore(configLoader, {});
|
return useCore(configLoader, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSettings() {
|
||||||
|
return getCore(settingsLoader, {});
|
||||||
|
}
|
||||||
|
export function useSettings() {
|
||||||
|
return useCore(settingsLoader, {});
|
||||||
|
}
|
||||||
|
|
||||||
export function getPlatformInfo() {
|
export function getPlatformInfo() {
|
||||||
return getCore(platformInfoLoader, {});
|
return getCore(platformInfoLoader, {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@
|
|||||||
const rect = domSettings.getBoundingClientRect();
|
const rect = domSettings.getBoundingClientRect();
|
||||||
const left = rect.right;
|
const left = rect.right;
|
||||||
const top = rect.top;
|
const top = rect.top;
|
||||||
const items = [{ command: 'settings.commands' }];
|
const items = [{ command: 'settings.commands' }, { command: 'theme.changeTheme' }];
|
||||||
currentDropDownMenu.set({ left, top, items });
|
currentDropDownMenu.set({ left, top, items });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user