mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-15 04:53:00 +08:00
⛅ Sync 2026-10-11 13:16:00
This commit is contained in:
1 parent
705dadd362
commit
e6d1b4e2d7
105 files changed
+26511
-50
No files matched your search
@@ -0,0 +1,28 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
'use strict';
|
||||
'require baseclass';
|
||||
|
||||
const STORAGE_KEY = 'luci-device-manager-view';
|
||||
const DEFAULT_STATE = { tab: 'online', group: 'all' };
|
||||
|
||||
// Storage access and JSON parsing can throw synchronously; isolate them in promises.
|
||||
return baseclass.extend({
|
||||
load: function() {
|
||||
return Promise.resolve().then(() => window.localStorage.getItem(STORAGE_KEY)).then(raw => {
|
||||
const state = raw ? JSON.parse(raw) : null;
|
||||
if (!state || typeof state !== 'object') return Object.assign({}, DEFAULT_STATE);
|
||||
const result = {
|
||||
tab: typeof state.tab === 'string' ? state.tab : 'online',
|
||||
group: typeof state.group === 'string' ? state.group : 'all'
|
||||
};
|
||||
if (typeof state.maskInfo === 'boolean') result.maskInfo = state.maskInfo;
|
||||
return result;
|
||||
}).catch(() => Object.assign({}, DEFAULT_STATE));
|
||||
},
|
||||
save: function(tab, group, maskInfo) {
|
||||
const payload = { tab: tab || 'online', group: group || 'all' };
|
||||
if (typeof maskInfo === 'boolean') payload.maskInfo = maskInfo;
|
||||
return Promise.resolve().then(() => window.localStorage.setItem(STORAGE_KEY,
|
||||
JSON.stringify(payload))).catch(() => {});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user