From 046c80be44256fcd7878fcf1121172f084e2f7de Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Fri, 29 Jul 2022 12:58:22 -0700 Subject: [PATCH] Bootstrap filesystem and add filesystem store Co-authored-by: Jess Martin --- src/components/auth/Register.svelte | 6 +++++- src/lib/common/webnative.ts | 13 +++++++++---- src/stores.ts | 8 ++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/auth/Register.svelte b/src/components/auth/Register.svelte index 6b84061..35f2fb2 100644 --- a/src/components/auth/Register.svelte +++ b/src/components/auth/Register.svelte @@ -3,11 +3,12 @@ import { onDestroy, onMount } from 'svelte' import { + bootstrapFilesystem, isUsernameValid, isUsernameAvailable, register } from '$lib/common/webnative' - import { sessionStore } from '../../stores' + import { filesystemStore, sessionStore } from '../../stores' import type { Session } from '$lib/session' import CheckIcon from '$components/icons/CheckIcon.svelte' import XIcon from '$components/icons/XIcon.svelte' @@ -54,6 +55,9 @@ console.log('session after registration', $sessionStore) + const fs = await bootstrapFilesystem() + filesystemStore.set(fs) + goto('/linkDevice') } } diff --git a/src/lib/common/webnative.ts b/src/lib/common/webnative.ts index 6ba6f6c..921cf3d 100644 --- a/src/lib/common/webnative.ts +++ b/src/lib/common/webnative.ts @@ -1,17 +1,17 @@ import * as webnative from 'webnative' -// import type FileSystem from 'webnative/fs/index' +import type FileSystem from 'webnative/fs/index' import { setup } from 'webnative' import { asyncDebounce } from '$lib/common/utils' -import { sessionStore } from '../../stores' +import { filesystemStore, sessionStore } from '../../stores' // runfission.net = staging -setup.endpoints({ api: 'https://runfission.net', user: 'fissionuser.net' }) +setup.endpoints({ api: 'https://runfission.net', lobby: 'https://auth.runfission.net', user: 'fissionuser.net' }) let state: webnative.AppState // TODO: Add a flag or script to turn debugging on/off -setup.debug({ enabled: true }) +setup.debug({ enabled: false }) export const initialize = async (): Promise => { try { @@ -32,6 +32,7 @@ export const initialize = async (): Promise => { authed: state.authenticated, loading: false }) + filesystemStore.set(state.fs) break default: @@ -79,6 +80,10 @@ export const register = async (username: string): Promise => { return success } +export const bootstrapFilesystem = async (): Promise => { + return await webnative.bootstrapRootFileSystem() +} + // interface StateFS { // fs?: FileSystem // } diff --git a/src/stores.ts b/src/stores.ts index 60af46c..2a8a5d9 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -1,8 +1,10 @@ import { writable } from 'svelte/store' +import type { Writable } from 'svelte/store' +import type FileSystem from 'webnative/fs/index' + import { loadTheme } from '$lib/theme' import type { Session } from '$lib/session' import type { Theme } from '$lib/theme' -import type { Writable } from 'svelte/store' export const theme: Writable = writable(loadTheme()) @@ -10,4 +12,6 @@ export const sessionStore: Writable = writable({ username: '', authed: false, loading: true -}) \ No newline at end of file +}) + +export const filesystemStore: Writable = writable(null) \ No newline at end of file