|
1 | 1 | <script>
|
2 | 2 | import * as fs from '@tauri-apps/plugin-fs'
|
| 3 | + import * as os from '@tauri-apps/plugin-os' |
3 | 4 | import { convertFileSrc } from '@tauri-apps/api/core'
|
4 | 5 | import { arrayBufferToBase64 } from '../lib/utils'
|
5 |
| - import { onDestroy } from 'svelte' |
| 6 | + import { onDestroy, onMount } from 'svelte' |
6 | 7 |
|
7 | 8 | const { onMessage, insecureRenderHtml } = $props()
|
8 | 9 |
|
|
18 | 19 | let baseDir = $state()
|
19 | 20 | let unwatchFn
|
20 | 21 | let unwatchPath = ''
|
| 22 | + let isMobile = $state(false) |
| 23 | +
|
| 24 | + onMount(() => { |
| 25 | + let platform = os.platform() |
| 26 | + isMobile = platform === 'android' || platform === 'ios' |
| 27 | + }) |
21 | 28 |
|
22 | 29 | const dirOptions = Object.keys(fs.BaseDirectory).filter((key) =>
|
23 | 30 | isNaN(parseInt(key))
|
|
38 | 45 | }
|
39 | 46 |
|
40 | 47 | function mkdir() {
|
41 |
| - fs.mkdir(path, { baseDir }) |
| 48 | + fs.mkdir(path, { baseDir, recursive: true }) |
42 | 49 | .then(() => {
|
43 | 50 | onMessage(`Created dir ${path}`)
|
44 | 51 | })
|
|
73 | 80 | .catch(onMessage)
|
74 | 81 | }
|
75 | 82 |
|
| 83 | + function write() { |
| 84 | + const encoder = new TextEncoder() |
| 85 | + file |
| 86 | + .write(encoder.encode('Hello from Tauri :)')) |
| 87 | + .then(() => { |
| 88 | + onMessage(`wrote to file`) |
| 89 | + }) |
| 90 | + .catch(onMessage) |
| 91 | + } |
| 92 | +
|
76 | 93 | function stat() {
|
77 | 94 | file
|
78 | 95 | .stat()
|
|
180 | 197 | </script>
|
181 | 198 |
|
182 | 199 | <div class="flex flex-col">
|
| 200 | + {#if isMobile} |
| 201 | + <div> |
| 202 | + On mobile, paths outside of App* paths require the use of dialogs |
| 203 | + regardless of Tauri's scope mechanism. |
| 204 | + </div> |
| 205 | + <br /> |
| 206 | + {/if} |
183 | 207 | <div class="flex gap-1">
|
184 | 208 | <select class="input" bind:value={baseDir}>
|
185 | 209 | <option value={undefined} selected>None</option>
|
|
207 | 231 | </div>
|
208 | 232 | {#if file}
|
209 | 233 | <div>
|
| 234 | + <button class="btn" onclick={write}>Write</button> |
210 | 235 | <button class="btn" onclick={truncate}>Truncate</button>
|
211 | 236 | <button class="btn" onclick={stat}>Stat</button>
|
212 | 237 | </div>
|
|
0 commit comments