mirror of
https://github.com/MadeBaruna/paimon-moe.git
synced 2025-01-07 02:59:39 +01:00
Add error handler for gdrive
This commit is contained in:
parent
a714eeabe4
commit
0e94c1533c
3 changed files with 21 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { onMount, getContext, setContext } from 'svelte';
|
import { onMount, getContext, setContext } from 'svelte';
|
||||||
import { driveSignedIn, driveLoading, saveId, synced } from '../stores/dataSync';
|
import { driveSignedIn, driveError, driveLoading, saveId, synced } from '../stores/dataSync';
|
||||||
import { getLocalSaveJson, updateSave, updateTime, UPDATE_TIME_KEY } from '../stores/saveManager';
|
import { getLocalSaveJson, updateSave, updateTime, UPDATE_TIME_KEY } from '../stores/saveManager';
|
||||||
|
|
||||||
import SyncConflictModal from '../components/SyncConflictModal.svelte';
|
import SyncConflictModal from '../components/SyncConflictModal.svelte';
|
||||||
|
@ -31,10 +31,19 @@
|
||||||
synced.set(false);
|
synced.set(false);
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.onload = handleClientLoad;
|
script.onload = handleClientLoad;
|
||||||
|
script.onerror = handleError;
|
||||||
script.src = 'https://apis.google.com/js/api.js';
|
script.src = 'https://apis.google.com/js/api.js';
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleError() {
|
||||||
|
console.log('error loading google drive api');
|
||||||
|
driveSignedIn.set(false);
|
||||||
|
driveLoading.set(false);
|
||||||
|
driveError.set(true);
|
||||||
|
synced.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
function handleClientLoad() {
|
function handleClientLoad() {
|
||||||
gapi.load('client:auth2', initClient);
|
gapi.load('client:auth2', initClient);
|
||||||
}
|
}
|
||||||
|
@ -212,6 +221,10 @@
|
||||||
},
|
},
|
||||||
function (error) {
|
function (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
driveSignedIn.set(false);
|
||||||
|
driveLoading.set(false);
|
||||||
|
driveError.set(true);
|
||||||
|
synced.set(true);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
import Icon from '../components/Icon.svelte';
|
import Icon from '../components/Icon.svelte';
|
||||||
import Select from '../components/Select.svelte';
|
import Select from '../components/Select.svelte';
|
||||||
|
|
||||||
import { driveSignedIn, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync';
|
import { driveSignedIn, driveError, driveLoading, synced, localModified, lastSyncTime } from '../stores/dataSync';
|
||||||
import { server } from '../stores/server';
|
import { server } from '../stores/server';
|
||||||
|
|
||||||
const servers = [
|
const servers = [
|
||||||
|
@ -63,6 +63,11 @@
|
||||||
<p class="text-white mb-4">Paimon.moe can only read and write file that this site create.</p>
|
<p class="text-white mb-4">Paimon.moe can only read and write file that this site create.</p>
|
||||||
{#if $driveLoading}
|
{#if $driveLoading}
|
||||||
<Icon path={mdiLoading} color="white" spin />
|
<Icon path={mdiLoading} color="white" spin />
|
||||||
|
{:else if $driveError}
|
||||||
|
<Button color="red">
|
||||||
|
<Icon path={mdiGoogleDrive} className="mr-2" />
|
||||||
|
Google Drive API cannot be loaded
|
||||||
|
</Button>
|
||||||
{:else if !$driveSignedIn}
|
{:else if !$driveSignedIn}
|
||||||
<Button on:click={signIn}>
|
<Button on:click={signIn}>
|
||||||
<Icon path={mdiGoogleDrive} className="mr-2" />
|
<Icon path={mdiGoogleDrive} className="mr-2" />
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
|
||||||
|
|
||||||
export const driveSignedIn = writable(false);
|
export const driveSignedIn = writable(false);
|
||||||
export const driveLoading = writable(true);
|
export const driveLoading = writable(true);
|
||||||
|
export const driveError = writable(false);
|
||||||
export const lastSyncTime = writable(null);
|
export const lastSyncTime = writable(null);
|
||||||
export const localModified = writable(false);
|
export const localModified = writable(false);
|
||||||
export const synced = writable(false);
|
export const synced = writable(false);
|
||||||
|
|
Loading…
Reference in a new issue