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,
|
getSettings_meta: true,
|
||||||
async getSettings() {
|
async getSettings() {
|
||||||
try {
|
const res = await lock.acquire('settings', async () => {
|
||||||
return this.fillMissingSettings(
|
return await this.loadSettings();
|
||||||
JSON.parse(await fs.readFile(path.join(datadir(), 'settings.json'), { encoding: 'utf-8' }))
|
});
|
||||||
);
|
return res;
|
||||||
} catch (err) {
|
|
||||||
return this.fillMissingSettings({});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
fillMissingSettings(value) {
|
fillMissingSettings(value) {
|
||||||
@ -79,12 +76,21 @@ module.exports = {
|
|||||||
return res;
|
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,
|
updateSettings_meta: true,
|
||||||
async updateSettings(values, req) {
|
async updateSettings(values, req) {
|
||||||
if (!hasPermission(`settings/change`, req)) return false;
|
if (!hasPermission(`settings/change`, req)) return false;
|
||||||
|
|
||||||
const res = await lock.acquire('update', async () => {
|
const res = await lock.acquire('settings', async () => {
|
||||||
const currentValue = await this.getSettings();
|
const currentValue = await this.loadSettings();
|
||||||
try {
|
try {
|
||||||
const updated = {
|
const updated = {
|
||||||
...currentValue,
|
...currentValue,
|
||||||
|
@ -29,7 +29,11 @@ export function writableWithStorage<T>(defaultValue: T, storageName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function writableSettingsValue<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 {
|
return {
|
||||||
...res,
|
...res,
|
||||||
set: value => apiCall('config/update-settings', { [storageName]: value }),
|
set: value => apiCall('config/update-settings', { [storageName]: value }),
|
||||||
|
@ -189,25 +189,29 @@ async function getCore(loader, args) {
|
|||||||
function useCore(loader, args) {
|
function useCore(loader, args) {
|
||||||
const { url, params, reloadTrigger, transform, onLoaded } = loader(args);
|
const { url, params, reloadTrigger, transform, onLoaded } = loader(args);
|
||||||
const cacheKey = stableStringify({ url, ...params });
|
const cacheKey = stableStringify({ url, ...params });
|
||||||
let closed = false;
|
let openedCount = 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe: onChange => {
|
subscribe: onChange => {
|
||||||
async function handleReload() {
|
async function handleReload() {
|
||||||
const res = await getCore(loader, args);
|
const res = await getCore(loader, args);
|
||||||
if (!closed) {
|
if (openedCount > 0) {
|
||||||
onChange(res);
|
onChange(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
openedCount += 1;
|
||||||
handleReload();
|
handleReload();
|
||||||
|
|
||||||
if (reloadTrigger) {
|
if (reloadTrigger) {
|
||||||
subscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
subscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
||||||
return () => {
|
return () => {
|
||||||
closed = true;
|
openedCount -= 1;
|
||||||
unsubscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
unsubscribeCacheChange(reloadTrigger, cacheKey, handleReload);
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
return () => {
|
||||||
|
openedCount -= 1;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user