mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
fixed changing editor theme #300
This commit is contained in:
parent
bef8cdbee4
commit
1f8ef8e20e
@ -59,13 +59,10 @@ module.exports = {
|
||||
|
||||
getSettings_meta: true,
|
||||
async getSettings() {
|
||||
try {
|
||||
return this.fillMissingSettings(
|
||||
JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }))
|
||||
);
|
||||
} catch (err) {
|
||||
return this.fillMissingSettings({});
|
||||
}
|
||||
const res = await lock.acquire('settings', async () => {
|
||||
return await this.loadSettings();
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
fillMissingSettings(value) {
|
||||
@ -79,12 +76,21 @@ module.exports = {
|
||||
return res;
|
||||
},
|
||||
|
||||
async loadSettings() {
|
||||
try {
|
||||
const settingsText = await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' });
|
||||
return this.fillMissingSettings(JSON.parse(settingsText));
|
||||
} catch (err) {
|
||||
return this.fillMissingSettings({});
|
||||
}
|
||||
},
|
||||
|
||||
updateSettings_meta: true,
|
||||
async updateSettings(values, req) {
|
||||
if (!hasPermission(`settings/change`, req)) return false;
|
||||
|
||||
const res = await lock.acquire('update', async () => {
|
||||
const currentValue = await this.getSettings();
|
||||
const res = await lock.acquire('settings', async () => {
|
||||
const currentValue = await this.loadSettings();
|
||||
try {
|
||||
const updated = {
|
||||
...currentValue,
|
||||
|
@ -29,7 +29,11 @@ export function writableWithStorage<T>(defaultValue: T, storageName) {
|
||||
}
|
||||
|
||||
export function writableSettingsValue<T>(defaultValue: T, storageName) {
|
||||
const res = derived(useSettings(), $settings => ($settings || {})[storageName] ?? defaultValue);
|
||||
const res = derived(useSettings(), $settings => {
|
||||
const obj = $settings || {};
|
||||
// console.log('GET SETTINGS', $settings, storageName, obj[storageName]);
|
||||
return obj[storageName] ?? defaultValue;
|
||||
});
|
||||
return {
|
||||
...res,
|
||||
set: value => apiCall('config/update-settings', { [storageName]: value }),
|
||||
|
@ -189,25 +189,29 @@ async function getCore(loader, args) {
|
||||
function useCore(loader, args) {
|
||||
const { url, params, reloadTrigger, transform, onLoaded } = loader(args);
|
||||
const cacheKey = stableStringify({ url, ...params });
|
||||
let closed = false;
|
||||
let openedCount = 0;
|
||||
|
||||
return {
|
||||
subscribe: onChange => {
|
||||
async function handleReload() {
|
||||
const res = await getCore(loader, args);
|
||||
if (!closed) {
|
||||
if (openedCount > 0) {
|
||||
onChange(res);
|
||||
}
|
||||
}
|
||||
|
||||
openedCount += 1;
|
||||
handleReload();
|
||||
|
||||
if (reloadTrigger) {
|
||||
subscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
||||
return () => {
|
||||
closed = true;
|
||||
openedCount -= 1;
|
||||
unsubscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
||||
};
|
||||
} else {
|
||||
return () => {
|
||||
openedCount -= 1;
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user