MCPcopy Index your code
hub / github.com/material-shell/material-shell / loadRegistry

Method loadRegistry

src/manager/stateManager.ts:27–64  ·  view source on GitHub ↗
(callback: (state: StateDict) => void)

Source from the content-addressed store, hash-verified

25 this.stateFile = Gio.file_new_for_path(REGISTRY_PATH);
26 }
27 loadRegistry(callback: (state: StateDict) => void) {
28 if (typeof callback !== 'function')
29 throw TypeError('`callback` must be a function');
30 const serializedState = global.get_persistent_state(
31 's',
32 'material-shell-state'
33 );
34 if (serializedState) {
35 try {
36 this.state = this.updateState(
37 JSON.parse(serializedState.deep_unpack())
38 );
39 } catch (e) {
40 this.state = {};
41 }
42 return callback(this.state);
43 }
44 if (GLib.file_test(REGISTRY_PATH, FileTest.EXISTS)) {
45 this.stateFile.load_contents_async(null, (obj, res) => {
46 const file = obj as unknown as Gio.File;
47 const [success, contents] = file.load_contents_finish(res);
48 if (success) {
49 try {
50 this.state = this.updateState(
51 JSON.parse(imports.byteArray.toString(contents))
52 );
53 } catch (e) {
54 Debug.log(e);
55 this.state = {};
56 }
57 }
58 callback(this.state);
59 });
60 } else {
61 this.state = {};
62 callback(this.state);
63 }
64 }
65
66 updateState(state: StateDict) {
67 if (state) {

Callers 1

enableMethod · 0.80

Calls 7

updateStateMethod · 0.95
get_persistent_stateMethod · 0.80
load_contents_asyncMethod · 0.80
load_contents_finishMethod · 0.80
parseMethod · 0.65
logMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected