Add webnative
This commit is contained in:
parent
d9205e7637
commit
dc0ce83990
File diff suppressed because it is too large
Load Diff
|
|
@ -51,5 +51,8 @@
|
|||
"nodeArguments": [
|
||||
"--loader=./tsnode-loader.js"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"webnative": "^0.32.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
<script lang="ts">
|
||||
import { initialize } from '$lib/common/webnative'
|
||||
|
||||
const init = async () => {
|
||||
await initialize()
|
||||
}
|
||||
|
||||
init()
|
||||
</script>
|
||||
|
||||
<h1>Hello world!</h1>
|
||||
|
|
|
|||
Loading…
Reference in New Issue