Add webnative

This commit is contained in:
Brian Ginsburg 2022-07-14 12:43:42 -07:00
parent d9205e7637
commit dc0ce83990
No known key found for this signature in database
GPG Key ID: B7A01B90EB115B2D
4 changed files with 1289 additions and 31 deletions

1256
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -51,5 +51,8 @@
"nodeArguments": [
"--loader=./tsnode-loader.js"
]
},
"dependencies": {
"webnative": "^0.32.0"
}
}

View File

@ -0,0 +1,55 @@
import * as webnative from 'webnative'
import type FileSystem from 'webnative/fs/index'
let state: webnative.State
const fissionInit = {
permissions: {
app: {
name: 'app-name',
creator: 'creator-name',
},
// Ask the user permission to additional filesystem paths
fs: {
// private: [webnative.path.directory('Documents', 'Contacts')],
},
},
}
webnative.setup.debug({ enabled: true })
export const initialize = async (): Promise<void> => {
try {
const st = await webnative.initialise(fissionInit)
state = st
switch (state.scenario) {
case webnative.Scenario.AuthCancelled:
case webnative.Scenario.NotAuthorised:
console.log('Not logged in')
break
case webnative.Scenario.AuthSucceeded:
case webnative.Scenario.Continuation:
console.log('Logged in')
break
}
} catch (error) {
switch (error) {
case webnative.InitialisationError.InsecureContext:
console.log('Insecure context')
break
case webnative.InitialisationError.UnsupportedBrowser:
console.log('Unsupported browser')
break
}
}
}
// interface StateFS {
// fs?: FileSystem
// }
// export const getWNFS: () => FileSystem = () => (state as StateFS)?.fs

View File

@ -1,5 +1,11 @@
<script lang="ts">
import { initialize } from '$lib/common/webnative'
const init = async () => {
await initialize()
}
init()
</script>
<h1>Hello world!</h1>