2022-05-28 18:43:56 +02:00
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
import * as Store from 'electron-store';
|
|
|
|
import { Ace } from 'ace-builds';
|
2022-04-27 18:23:48 +02:00
|
|
|
const persistentStore = new Store({ name: 'settings' });
|
|
|
|
|
|
|
|
export const useApplicationStore = defineStore('application', {
|
|
|
|
state: () => ({
|
|
|
|
appName: 'Antares - SQL Client',
|
2022-05-28 18:43:56 +02:00
|
|
|
appVersion: process.env.PACKAGE_VERSION || '0',
|
|
|
|
cachedVersion: persistentStore.get('cached_version', '0') as string,
|
2022-04-27 18:23:48 +02:00
|
|
|
isLoading: false,
|
|
|
|
isNewModal: false,
|
|
|
|
isSettingModal: false,
|
|
|
|
isScratchpad: false,
|
|
|
|
selectedSettingTab: 'general',
|
|
|
|
selectedConection: {},
|
|
|
|
updateStatus: 'noupdate', // 'noupdate' | 'available' | 'checking' | 'nocheck' | 'downloading' | 'downloaded' | 'disabled'
|
|
|
|
downloadProgress: 0,
|
2022-05-28 18:43:56 +02:00
|
|
|
baseCompleter: [] as Ace.Completer[] // Needed to reset ace editor, due global-only ace completer
|
2022-04-27 18:23:48 +02:00
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
getBaseCompleter: state => state.baseCompleter,
|
|
|
|
getSelectedConnection: state => state.selectedConection,
|
|
|
|
getDownloadProgress: state => Number(state.downloadProgress.toFixed(1))
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
checkVersionUpdate () {
|
|
|
|
if (this.appVersion !== this.cachedVersion) {
|
|
|
|
this.showSettingModal('changelog');
|
|
|
|
this.cachedVersion = this.appVersion;
|
|
|
|
persistentStore.set('cached_version', this.cachedVersion);
|
|
|
|
}
|
|
|
|
},
|
2022-05-28 18:43:56 +02:00
|
|
|
setLoadingStatus (payload: boolean) {
|
2022-04-27 18:23:48 +02:00
|
|
|
this.isLoading = payload;
|
|
|
|
},
|
2022-06-04 18:37:16 +02:00
|
|
|
setBaseCompleters (payload: Ace.Completer[]) {
|
2022-04-27 18:23:48 +02:00
|
|
|
this.baseCompleter = payload;
|
|
|
|
},
|
|
|
|
// Modals
|
|
|
|
showNewConnModal () {
|
|
|
|
this.isNewModal = true;
|
|
|
|
},
|
|
|
|
hideNewConnModal () {
|
|
|
|
this.isNewModal = false;
|
|
|
|
},
|
2022-05-28 18:43:56 +02:00
|
|
|
showSettingModal (tab: string) {
|
2022-04-27 18:23:48 +02:00
|
|
|
this.selectedSettingTab = tab;
|
|
|
|
this.isSettingModal = true;
|
|
|
|
},
|
|
|
|
hideSettingModal () {
|
|
|
|
this.isSettingModal = false;
|
|
|
|
},
|
|
|
|
showScratchpad () {
|
|
|
|
this.isScratchpad = true;
|
|
|
|
},
|
|
|
|
hideScratchpad () {
|
|
|
|
this.isScratchpad = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|