(callback: (state: StateDict) => void)
| 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) { |
no test coverage detected