2023-08-18 15:57:31 +02:00
|
|
|
import { ShortcutRecord } from 'common/shortcuts';
|
2022-06-07 18:32:37 +02:00
|
|
|
import { ipcRenderer } from 'electron';
|
2022-05-28 18:43:56 +02:00
|
|
|
import * as Store from 'electron-store';
|
2023-08-18 15:57:31 +02:00
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
|
|
|
import { AvailableLocale, i18n } from '@/i18n';
|
2022-08-10 17:59:59 +02:00
|
|
|
|
2022-08-08 16:44:40 +02:00
|
|
|
const settingsStore = new Store({ name: 'settings' });
|
|
|
|
const shortcutsStore = new Store({ name: 'shortcuts' });
|
2022-04-30 00:47:37 +02:00
|
|
|
const isDarkTheme = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
const defaultAppTheme = isDarkTheme.matches ? 'dark' : 'light';
|
|
|
|
const defaultEditorTheme = isDarkTheme.matches ? 'twilight' : 'sqlserver';
|
|
|
|
|
2022-09-21 10:33:44 +02:00
|
|
|
export type EditorFontSize = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge';
|
2022-06-04 18:37:16 +02:00
|
|
|
export type ApplicationTheme = 'light' | 'dark';
|
2022-05-24 23:02:40 +02:00
|
|
|
|
2022-04-30 00:47:37 +02:00
|
|
|
export const useSettingsStore = defineStore('settings', {
|
|
|
|
state: () => ({
|
2022-08-08 16:44:40 +02:00
|
|
|
locale: settingsStore.get('locale', 'en-US') as AvailableLocale,
|
2023-07-31 10:55:05 +02:00
|
|
|
allowPrerelease: settingsStore.get('allow_prerelease', false) as boolean,
|
2022-08-08 16:44:40 +02:00
|
|
|
explorebarSize: settingsStore.get('explorebar_size', null) as number,
|
|
|
|
notificationsTimeout: settingsStore.get('notifications_timeout', 5) as number,
|
2023-02-23 08:51:33 +01:00
|
|
|
showTableSize: settingsStore.get('show_table_size', false) as boolean,
|
2022-08-08 16:44:40 +02:00
|
|
|
dataTabLimit: settingsStore.get('data_tab_limit', 1000) as number,
|
|
|
|
autoComplete: settingsStore.get('auto_complete', true) as boolean,
|
|
|
|
lineWrap: settingsStore.get('line_wrap', true) as boolean,
|
2022-12-18 15:59:58 +01:00
|
|
|
executeSelected: settingsStore.get('execute_selected', true) as boolean,
|
2022-08-08 16:44:40 +02:00
|
|
|
applicationTheme: settingsStore.get('application_theme', defaultAppTheme) as ApplicationTheme,
|
|
|
|
editorTheme: settingsStore.get('editor_theme', defaultEditorTheme) as string,
|
|
|
|
editorFontSize: settingsStore.get('editor_font_size', 'medium') as EditorFontSize,
|
|
|
|
restoreTabs: settingsStore.get('restore_tabs', true) as boolean,
|
|
|
|
disableBlur: settingsStore.get('disable_blur', false) as boolean,
|
2023-01-15 22:42:13 +01:00
|
|
|
shortcuts: shortcutsStore.get('shortcuts', []) as ShortcutRecord[],
|
|
|
|
defaultCopyType: settingsStore.get('default_copy_type', 'cell') as string
|
2022-04-30 00:47:37 +02:00
|
|
|
}),
|
|
|
|
actions: {
|
2022-08-05 13:06:08 +02:00
|
|
|
changeLocale (locale: AvailableLocale) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.locale = locale;
|
|
|
|
i18n.global.locale = locale;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('locale', this.locale);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changePageSize (limit: number) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.dataTabLimit = limit;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('data_tab_limit', this.dataTabLimit);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeAllowPrerelease (allow: boolean) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.allowPrerelease = allow;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('allow_prerelease', this.allowPrerelease);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
updateNotificationsTimeout (timeout: number) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.notificationsTimeout = timeout;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('notifications_timeout', this.notificationsTimeout);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2023-02-23 08:51:33 +01:00
|
|
|
changeShowTableSize (show: boolean) {
|
|
|
|
this.showTableSize = show;
|
|
|
|
settingsStore.set('show_table_size', this.showTableSize);
|
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeExplorebarSize (size: number) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.explorebarSize = size;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('explorebar_size', this.explorebarSize);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeAutoComplete (val: boolean) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.autoComplete = val;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('auto_complete', this.autoComplete);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeLineWrap (val: boolean) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.lineWrap = val;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('line_wrap', this.lineWrap);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-12-18 15:59:58 +01:00
|
|
|
changeExecuteSelected (val: boolean) {
|
|
|
|
this.executeSelected = val;
|
|
|
|
settingsStore.set('execute_selected', this.executeSelected);
|
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeApplicationTheme (theme: string) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.applicationTheme = theme;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('application_theme', this.applicationTheme);
|
2022-06-07 18:32:37 +02:00
|
|
|
ipcRenderer.send('refresh-theme-settings');
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeEditorTheme (theme: string) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.editorTheme = theme;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('editor_theme', this.editorTheme);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeEditorFontSize (size: EditorFontSize) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.editorFontSize = size;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('editor_font_size', this.editorFontSize);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeRestoreTabs (val: boolean) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.restoreTabs = val;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('restore_tabs', this.restoreTabs);
|
2022-04-30 00:47:37 +02:00
|
|
|
},
|
2022-05-24 23:02:40 +02:00
|
|
|
changeDisableBlur (val: boolean) {
|
2022-04-30 00:47:37 +02:00
|
|
|
this.disableBlur = val;
|
2022-08-08 16:44:40 +02:00
|
|
|
settingsStore.set('disable_blur', this.disableBlur);
|
2022-07-04 15:10:40 +02:00
|
|
|
},
|
2022-08-10 17:59:59 +02:00
|
|
|
updateShortcuts (shortcuts: ShortcutRecord[]) {
|
|
|
|
this.shortcuts = shortcuts;
|
2023-01-15 22:42:13 +01:00
|
|
|
},
|
|
|
|
changeDefaultCopyType (type: string) {
|
|
|
|
this.defaultCopyType = type;
|
|
|
|
settingsStore.set('default_copy_type', this.defaultCopyType);
|
2022-04-30 00:47:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|