()
| 133 | isInit: ref(false), |
| 134 | |
| 135 | async init() { |
| 136 | const tempSettings = []; |
| 137 | for (const key in this.options) { |
| 138 | const store = await api.storage.get(`settings/${key}`); |
| 139 | if (typeof store !== 'undefined') { |
| 140 | this.options[key] = store; |
| 141 | tempSettings[key] = /(token|refresh)/i.test(key) && store ? '********' : store; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | try { |
| 146 | const chibiRepo = await (await ChibiListRepository.getInstance(true)).init(); |
| 147 | this.chibiList = chibiRepo.getList(); |
| 148 | } catch (e) { |
| 149 | con.error('Error loading chibi repo', e); |
| 150 | } |
| 151 | |
| 152 | con.log('Settings', tempSettings); |
| 153 | |
| 154 | let rateDebounce; |
| 155 | |
| 156 | api.storage.storageOnChanged((changes, namespace) => { |
| 157 | if (namespace === 'sync') { |
| 158 | for (const key in changes) { |
| 159 | const storageChange = changes[key]; |
| 160 | if (/^settings\//i.test(key)) { |
| 161 | this.options[key.replace('settings/', '')] = storageChange.newValue; |
| 162 | con.info(`Update ${key} option to ${JSON.stringify(storageChange.newValue, null, 2)}`); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | if (namespace === 'local' && changes.rateLimit) { |
| 167 | try { |
| 168 | clearTimeout(rateDebounce); |
| 169 | if (changes.rateLimit.newValue) { |
| 170 | con.log('Rate limited'); |
| 171 | if (!$('.type-rate').length) { |
| 172 | utils.flashm('Rate limited. Retrying in a moment', { |
| 173 | error: true, |
| 174 | type: 'rate', |
| 175 | permanent: true, |
| 176 | }); |
| 177 | } |
| 178 | } else { |
| 179 | rateDebounce = setTimeout(() => { |
| 180 | con.log('No Rate limited'); |
| 181 | $('.type-rate').remove(); |
| 182 | }, 5000); |
| 183 | } |
| 184 | } catch (e) { |
| 185 | con.error(e); |
| 186 | } |
| 187 | } |
| 188 | }); |
| 189 | |
| 190 | this.isInit.value = true; |
| 191 | |
| 192 | return this; |
nothing calls this directly
no test coverage detected