mirror of
https://github.com/morgan9e/dash-to-panel
synced 2026-04-14 00:04:17 +09:00
Add simple cache for json settings
This commit is contained in:
@@ -210,12 +210,18 @@ export const PanelManager = class {
|
||||
'changed::panel-anchors',
|
||||
'changed::stockgs-keep-top-panel',
|
||||
],
|
||||
() => this._reset(),
|
||||
(settings,settingChanged) => {
|
||||
PanelSettings.clearCache(settingChanged)
|
||||
this._reset()
|
||||
}
|
||||
],
|
||||
[
|
||||
SETTINGS,
|
||||
'changed::panel-element-positions',
|
||||
() => this._updatePanelElementPositions(),
|
||||
() => {
|
||||
PanelSettings.clearCache('panel-element-positions')
|
||||
this._updatePanelElementPositions()
|
||||
}
|
||||
],
|
||||
[
|
||||
SETTINGS,
|
||||
|
||||
@@ -17,10 +17,30 @@
|
||||
|
||||
import * as Pos from './panelPositions.js'
|
||||
|
||||
// cache is a different object in the settings dialog (gjs process)
|
||||
// and in gnome-shell (gnome-shell process)
|
||||
let cache = {}
|
||||
|
||||
export function clearCache(setting) {
|
||||
if (setting) {
|
||||
cache[setting] = null
|
||||
return
|
||||
}
|
||||
|
||||
cache = {}
|
||||
}
|
||||
|
||||
/** Return object representing a settings value that is stored as JSON. */
|
||||
export function getSettingsJson(settings, setting) {
|
||||
try {
|
||||
return JSON.parse(settings.get_string(setting))
|
||||
if (cache[setting])
|
||||
return cache[setting]
|
||||
|
||||
let res = JSON.parse(settings.get_string(setting))
|
||||
|
||||
cache[setting] = res
|
||||
|
||||
return res
|
||||
} catch (e) {
|
||||
console.log('Error parsing positions: ' + e.message)
|
||||
}
|
||||
@@ -30,6 +50,7 @@ export function setSettingsJson(settings, setting, value) {
|
||||
try {
|
||||
const json = JSON.stringify(value)
|
||||
settings.set_string(setting, json)
|
||||
cache[setting] = value
|
||||
} catch (e) {
|
||||
console.log('Error serializing setting: ' + e.message)
|
||||
}
|
||||
|
||||
@@ -473,9 +473,10 @@ const Preferences = class {
|
||||
monitors.forEach(
|
||||
(m) => (panelElementPositionsSettings[m] = newPanelElementPositions),
|
||||
)
|
||||
this._settings.set_string(
|
||||
PanelSettings.setSettingsJson(
|
||||
this._settings,
|
||||
'panel-element-positions',
|
||||
JSON.stringify(panelElementPositionsSettings),
|
||||
panelElementPositionsSettings,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user