mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-24 21:40:48 +02:00
chore(example): Improve dialog/fs mobile examples (#2410)
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
|
content="width=device-width, initial-scale=1.0, viewport-fit=cover, user-scalable=0"
|
||||||
/>
|
/>
|
||||||
<title>Svelte + Vite App</title>
|
<title>Svelte + Vite App</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -68,6 +68,9 @@
|
|||||||
"fs:allow-rename",
|
"fs:allow-rename",
|
||||||
"fs:allow-mkdir",
|
"fs:allow-mkdir",
|
||||||
"fs:allow-remove",
|
"fs:allow-remove",
|
||||||
|
"fs:allow-stat",
|
||||||
|
"fs:allow-fstat",
|
||||||
|
"fs:allow-lstat",
|
||||||
"fs:allow-write-text-file",
|
"fs:allow-write-text-file",
|
||||||
"fs:read-meta",
|
"fs:read-meta",
|
||||||
"fs:scope-download-recursive",
|
"fs:scope-download-recursive",
|
||||||
@@ -75,6 +78,9 @@
|
|||||||
{
|
{
|
||||||
"identifier": "fs:scope-appdata-recursive",
|
"identifier": "fs:scope-appdata-recursive",
|
||||||
"allow": [
|
"allow": [
|
||||||
|
{
|
||||||
|
"path": "$APPDATA/db/"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "$APPDATA/db/**"
|
"path": "$APPDATA/db/**"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script>
|
<script>
|
||||||
import * as fs from '@tauri-apps/plugin-fs'
|
import * as fs from '@tauri-apps/plugin-fs'
|
||||||
|
import * as os from '@tauri-apps/plugin-os'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||||
import { arrayBufferToBase64 } from '../lib/utils'
|
import { arrayBufferToBase64 } from '../lib/utils'
|
||||||
import { onDestroy } from 'svelte'
|
import { onDestroy, onMount } from 'svelte'
|
||||||
|
|
||||||
const { onMessage, insecureRenderHtml } = $props()
|
const { onMessage, insecureRenderHtml } = $props()
|
||||||
|
|
||||||
@@ -18,6 +19,12 @@
|
|||||||
let baseDir = $state()
|
let baseDir = $state()
|
||||||
let unwatchFn
|
let unwatchFn
|
||||||
let unwatchPath = ''
|
let unwatchPath = ''
|
||||||
|
let isMobile = $state(false)
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
let platform = os.platform()
|
||||||
|
isMobile = platform === 'android' || platform === 'ios'
|
||||||
|
})
|
||||||
|
|
||||||
const dirOptions = Object.keys(fs.BaseDirectory).filter((key) =>
|
const dirOptions = Object.keys(fs.BaseDirectory).filter((key) =>
|
||||||
isNaN(parseInt(key))
|
isNaN(parseInt(key))
|
||||||
@@ -38,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mkdir() {
|
function mkdir() {
|
||||||
fs.mkdir(path, { baseDir })
|
fs.mkdir(path, { baseDir, recursive: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
onMessage(`Created dir ${path}`)
|
onMessage(`Created dir ${path}`)
|
||||||
})
|
})
|
||||||
@@ -73,6 +80,16 @@
|
|||||||
.catch(onMessage)
|
.catch(onMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function write() {
|
||||||
|
const encoder = new TextEncoder()
|
||||||
|
file
|
||||||
|
.write(encoder.encode('Hello from Tauri :)'))
|
||||||
|
.then(() => {
|
||||||
|
onMessage(`wrote to file`)
|
||||||
|
})
|
||||||
|
.catch(onMessage)
|
||||||
|
}
|
||||||
|
|
||||||
function stat() {
|
function stat() {
|
||||||
file
|
file
|
||||||
.stat()
|
.stat()
|
||||||
@@ -180,6 +197,13 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
{#if isMobile}
|
||||||
|
<div>
|
||||||
|
On mobile, paths outside of App* paths require the use of dialogs
|
||||||
|
regardless of Tauri's scope mechanism.
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
{/if}
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<select class="input" bind:value={baseDir}>
|
<select class="input" bind:value={baseDir}>
|
||||||
<option value={undefined} selected>None</option>
|
<option value={undefined} selected>None</option>
|
||||||
@@ -207,6 +231,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{#if file}
|
{#if file}
|
||||||
<div>
|
<div>
|
||||||
|
<button class="btn" onclick={write}>Write</button>
|
||||||
<button class="btn" onclick={truncate}>Truncate</button>
|
<button class="btn" onclick={truncate}>Truncate</button>
|
||||||
<button class="btn" onclick={stat}>Stat</button>
|
<button class="btn" onclick={stat}>Stat</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user