()
| 84 | } |
| 85 | |
| 86 | static async commitItems() { |
| 87 | const storageLocation = |
| 88 | UserSettings.items.storageLocation || StorageLocation.Local; |
| 89 | |
| 90 | if (storageLocation === StorageLocation.Local) { |
| 91 | await chrome.storage[storageLocation].set({ |
| 92 | // JSON.parse(JSON.stringify()) strips functions (e.g. getItem, setItem, ...) which may have been added to the object. |
| 93 | // Without this, a crash may occur as chrome.storage throws an error when trying to serialize a function. |
| 94 | UserSettings: JSON.parse(JSON.stringify(UserSettings.items)), |
| 95 | }); |
| 96 | } else { |
| 97 | const { syncableSettings, localSettings } = UserSettings.splitSettings( |
| 98 | UserSettings.items |
| 99 | ); |
| 100 | |
| 101 | await Promise.all([ |
| 102 | chrome.storage[StorageLocation.Local].set({ |
| 103 | UserSettings: JSON.parse(JSON.stringify(localSettings)), |
| 104 | }), |
| 105 | chrome.storage[StorageLocation.Sync].set({ |
| 106 | UserSettings: JSON.parse(JSON.stringify(syncableSettings)), |
| 107 | }), |
| 108 | ]); |
| 109 | } |
| 110 | |
| 111 | await UserSettings.updateItems(); |
| 112 | } |
| 113 | |
| 114 | static async removeItem(key: keyof UserSettingsData) { |
| 115 | const localSettings = await UserSettings.getStorageData( |
no test coverage detected