Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta
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>
</head>
Expand Down
6 changes: 6 additions & 0 deletions examples/api/src-tauri/capabilities/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@
"fs:allow-rename",
"fs:allow-mkdir",
"fs:allow-remove",
"fs:allow-stat",
"fs:allow-fstat",
"fs:allow-lstat",
"fs:allow-write-text-file",
"fs:read-meta",
"fs:scope-download-recursive",
"fs:scope-resource-recursive",
{
"identifier": "fs:scope-appdata-recursive",
"allow": [
{
"path": "$APPDATA/db/"
},
{
"path": "$APPDATA/db/**"
}
Expand Down
29 changes: 27 additions & 2 deletions examples/api/src/views/FileSystem.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script>
import * as fs from '@tauri-apps/plugin-fs'
import * as os from '@tauri-apps/plugin-os'
import { convertFileSrc } from '@tauri-apps/api/core'
import { arrayBufferToBase64 } from '../lib/utils'
import { onDestroy } from 'svelte'
import { onDestroy, onMount } from 'svelte'

const { onMessage, insecureRenderHtml } = $props()

Expand All @@ -18,6 +19,12 @@
let baseDir = $state()
let unwatchFn
let unwatchPath = ''
let isMobile = $state(false)

onMount(() => {
let platform = os.platform()
isMobile = platform === 'android' || platform === 'ios'
})

const dirOptions = Object.keys(fs.BaseDirectory).filter((key) =>
isNaN(parseInt(key))
Expand All @@ -38,7 +45,7 @@
}

function mkdir() {
fs.mkdir(path, { baseDir })
fs.mkdir(path, { baseDir, recursive: true })
.then(() => {
onMessage(`Created dir ${path}`)
})
Expand Down Expand Up @@ -73,6 +80,16 @@
.catch(onMessage)
}

function write() {
const encoder = new TextEncoder()
file
.write(encoder.encode('Hello from Tauri :)'))
.then(() => {
onMessage(`wrote to file`)
})
.catch(onMessage)
}

function stat() {
file
.stat()
Expand Down Expand Up @@ -180,6 +197,13 @@
</script>

<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">
<select class="input" bind:value={baseDir}>
<option value={undefined} selected>None</option>
Expand Down Expand Up @@ -207,6 +231,7 @@
</div>
{#if file}
<div>
<button class="btn" onclick={write}>Write</button>
<button class="btn" onclick={truncate}>Truncate</button>
<button class="btn" onclick={stat}>Stat</button>
</div>
Expand Down