|
51 | 51 | saveScreenshot: false
|
52 | 52 | };
|
53 | 53 | let validationInterval: NodeJS.Timeout;
|
| 54 | + let missingPermissions = false; |
54 | 55 |
|
55 | 56 | $: $updatedUrl = $currentTab.url;
|
56 | 57 |
|
|
85 | 86 | };
|
86 | 87 | }
|
87 | 88 |
|
| 89 | + async function handleGrimoireApiUrlChange() { |
| 90 | + storage.set('configuration', configuration); |
| 91 | +
|
| 92 | + logger.debug('handleGrimoireApiUrlChange', 'Configuration changed', configuration); |
| 93 | + showToast.success('Configuration saved! 🪶'); |
| 94 | +
|
| 95 | + return onValidateGrimoireApiUrl(); |
| 96 | + } |
| 97 | +
|
88 | 98 | async function fetchUserData() {
|
89 | 99 | const categoriesAndTags = await sendToBackground<
|
90 | 100 | {
|
|
120 | 130 | return true;
|
121 | 131 | }
|
122 | 132 |
|
| 133 | + async function requestPermissions() { |
| 134 | + return chrome.permissions |
| 135 | + .request({ |
| 136 | + origins: ['<all_urls>'] |
| 137 | + }) |
| 138 | + .then((granted) => { |
| 139 | + if (granted) { |
| 140 | + logger.debug('requestPermissions', 'Necessary permission granted'); |
| 141 | + missingPermissions = false; |
| 142 | + } else { |
| 143 | + logger.error('requestPermissions', 'Necessary permission denied'); |
| 144 | + } |
| 145 | + }); |
| 146 | + } |
| 147 | +
|
123 | 148 | onMount(async () => {
|
124 | 149 | logger.debug('popup.onMount', 'init');
|
125 | 150 |
|
| 151 | + missingPermissions = !(await chrome.permissions.contains({ |
| 152 | + origins: ['<all_urls>'] |
| 153 | + })); |
| 154 | +
|
| 155 | + if (missingPermissions) { |
| 156 | + $status = { |
| 157 | + ...$status, |
| 158 | + isGrimoireApiReachable: false |
| 159 | + }; |
| 160 | +
|
| 161 | + return; |
| 162 | + } |
| 163 | +
|
126 | 164 | const theme = await storage.get('theme');
|
127 | 165 | token = await storage.get('token');
|
128 | 166 | configuration = (await storage.get('configuration')) || {
|
|
178 | 216 |
|
179 | 217 | logger.debug('onMount', 'validationInterval', 'initiating');
|
180 | 218 |
|
181 |
| - validationInterval = setInterval(() => { |
182 |
| - onValidateGrimoireApiUrl(); |
183 |
| - }, 5000); |
| 219 | + // validationInterval = setInterval(() => { |
| 220 | + // onValidateGrimoireApiUrl(); |
| 221 | + // }, 5000); |
184 | 222 | });
|
185 | 223 |
|
186 | 224 | onDestroy(() => {
|
187 |
| - clearInterval(validationInterval); |
| 225 | + // clearInterval(validationInterval); |
188 | 226 | });
|
189 | 227 |
|
190 | 228 | async function signIn() {
|
|
227 | 265 | </script>
|
228 | 266 |
|
229 | 267 | <div class="drawer drawer-end min-h-max min-w-80 max-w-80">
|
230 |
| - {#if !$status.isGrimoireApiReachable} |
| 268 | + {#if missingPermissions} |
| 269 | + <div class="container flex flex-col min-w-80 max-w-80 min-h-96 p-8"> |
| 270 | + <h2 class="text-xl font-semibold text-center mt-1 mb-4">Permissions required</h2> |
| 271 | + Before we continue, please grant this extension the necessary permissions. |
| 272 | + <h3 class="text-lg font-semibold mt-1 mb-4">They will allow us to:</h3> |
| 273 | + <ul class="list-disc list-inside"> |
| 274 | + <li>connect to your Grimoire instance</li> |
| 275 | + <li>take screenshots of webpages</li> |
| 276 | + </ul> |
| 277 | + |
| 278 | + <button class="btn btn-secondary btn-sm w-full max-w-xs my-4" on:click={requestPermissions}> |
| 279 | + Request permissions |
| 280 | + </button> |
| 281 | + </div> |
| 282 | + {:else if !$status.isGrimoireApiReachable} |
231 | 283 | <div class="container flex flex-col min-w-80 max-w-80 min-h-96 p-8">
|
232 | 284 | <h2 class="text-2xl font-semibold text-center mt-1 mb-4">Sign in</h2>
|
233 | 285 | <p class="text-accent text-center mb-4">
|
|
247 | 299 | bind:value={configuration.grimoireApiUrl}
|
248 | 300 | on:keyup={(e) => {
|
249 | 301 | if (e.key === 'Enter') {
|
250 |
| - onValidateGrimoireApiUrl(); |
| 302 | + handleGrimoireApiUrlChange(); |
251 | 303 | }
|
252 | 304 | }}
|
253 | 305 | />
|
|
256 | 308 | {/if}
|
257 | 309 | <button
|
258 | 310 | class="btn btn-primary btn-sm w-full max-w-xs my-4"
|
259 |
| - on:click={() => onValidateGrimoireApiUrl()}>Try to connect</button |
| 311 | + on:click={() => handleGrimoireApiUrlChange()}>Try to connect</button |
260 | 312 | >
|
261 | 313 | </div>
|
262 | 314 | {:else if !token}
|
|
0 commit comments