Add fs example and rename tauri imports
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": ">=2.0.0-beta.14",
|
||||
"@tauri-apps/plugin-fs": "2.0.0-beta.6",
|
||||
"@tauri-apps/plugin-notification": "2.0.0-beta.6",
|
||||
"@tauri-apps/plugin-os": "2.0.0-beta.6",
|
||||
"@tauri-apps/plugin-shell": "2.0.0-beta.7"
|
||||
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
@@ -11,6 +11,9 @@ importers:
|
||||
'@tauri-apps/api':
|
||||
specifier: '>=2.0.0-beta.14'
|
||||
version: 2.0.0-beta.14
|
||||
'@tauri-apps/plugin-fs':
|
||||
specifier: 2.0.0-beta.6
|
||||
version: 2.0.0-beta.6
|
||||
'@tauri-apps/plugin-notification':
|
||||
specifier: 2.0.0-beta.6
|
||||
version: 2.0.0-beta.6
|
||||
@@ -1687,6 +1690,9 @@ packages:
|
||||
engines: {node: '>= 10'}
|
||||
hasBin: true
|
||||
|
||||
'@tauri-apps/plugin-fs@2.0.0-beta.6':
|
||||
resolution: {integrity: sha512-R7M5wggENzJhiA0HwP63AzdF6uzdXRYe0z+ETSue9gvJmqKtqVp+qx9JLsWSfwENHy8RDKmrnuDL18kx/Q2aFA==}
|
||||
|
||||
'@tauri-apps/plugin-notification@2.0.0-beta.6':
|
||||
resolution: {integrity: sha512-KoYxGuBn3MIzTFyEhwh5O1VYGSwIplmABlYrDnLudf81Y8zKAIuJ8lnGprtiiUfU2ycXQH/0Zr/ku/NU8a+wdA==}
|
||||
|
||||
@@ -7138,6 +7144,10 @@ snapshots:
|
||||
'@tauri-apps/cli-win32-ia32-msvc': 2.0.0-beta.21
|
||||
'@tauri-apps/cli-win32-x64-msvc': 2.0.0-beta.21
|
||||
|
||||
'@tauri-apps/plugin-fs@2.0.0-beta.6':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0-beta.14
|
||||
|
||||
'@tauri-apps/plugin-notification@2.0.0-beta.6':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0-beta.14
|
||||
|
20
src-tauri/Cargo.lock
generated
20
src-tauri/Cargo.lock
generated
@@ -2299,6 +2299,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-fs",
|
||||
"tauri-plugin-notification",
|
||||
"tauri-plugin-os",
|
||||
"tauri-plugin-shell",
|
||||
@@ -3802,6 +3803,25 @@ dependencies = [
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-fs"
|
||||
version = "2.0.0-beta.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17e1f9fb6054cbc48c9e0fda7e8c8aeaccddb4fe880163473555beeed580010e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"glob",
|
||||
"schemars",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"thiserror",
|
||||
"url",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-notification"
|
||||
version = "2.0.0-beta.9"
|
||||
|
@@ -23,6 +23,7 @@ features = [ ]
|
||||
tauri-plugin-shell = "2.0.0-beta.8"
|
||||
tauri-plugin-notification = "2.0.0-beta.9"
|
||||
tauri-plugin-os = "2.0.0-beta.7"
|
||||
tauri-plugin-fs = "2.0.0-beta.10"
|
||||
serde_json = "1"
|
||||
|
||||
[dependencies.tauri]
|
||||
|
@@ -34,6 +34,8 @@
|
||||
"os:allow-arch",
|
||||
"os:allow-family",
|
||||
"os:allow-version",
|
||||
"os:allow-locale"
|
||||
"os:allow-locale",
|
||||
"fs:allow-document-read",
|
||||
"fs:allow-document-write"
|
||||
]
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
{"main":{"identifier":"main","description":"Capabilities for the main window","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":["-c",{"validator":"\\S+"}],"cmd":"sh","name":"exec-sh","sidecar":false}]},"notification:default","os:allow-platform","os:allow-arch","os:allow-family","os:allow-version","os:allow-locale"]}}
|
||||
{"main":{"identifier":"main","description":"Capabilities for the main window","local":true,"windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","shell:allow-open",{"identifier":"shell:allow-execute","allow":[{"args":["-c",{"validator":"\\S+"}],"cmd":"sh","name":"exec-sh","sidecar":false}]},"notification:default","os:allow-platform","os:allow-arch","os:allow-family","os:allow-version","os:allow-locale","fs:allow-document-read","fs:allow-document-write"]}}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_notification::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<button transition-colors gap-1 rounded-md bg-emerald-500 px-3.5 py-2.5 text-sm text-white font-semibold shadow-sm hover="bg-emerald-600" focus-visible="outline-2 outline-emerald-600 outline-offset-2 outline">
|
||||
<button class="disabled:(cursor-not-allowed opacity-60)" gap-1 rounded-md bg-emerald-500 px-3.5 py-2.5 text-sm text-white font-semibold shadow-sm transition-colors hover="bg-emerald-600" focus-visible="outline-2 outline-emerald-600 outline-offset-2 outline">
|
||||
<slot />
|
||||
</button>
|
||||
</template>
|
||||
|
@@ -21,8 +21,8 @@
|
||||
<NavLink to="/os">
|
||||
OS Informations
|
||||
</NavLink>
|
||||
<NavLink to="/foo">
|
||||
404
|
||||
<NavLink to="/file">
|
||||
File
|
||||
</NavLink>
|
||||
</div>
|
||||
<div hidden lg="flex flex-1 justify-end">
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
const { showSidebar } = useSidebar();
|
||||
const tauriVersion = await getTauriVersion();
|
||||
const tauriVersion = await useTauriAppGetTauriVersion();
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@@ -44,7 +44,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const tauriVersion = await getTauriVersion();
|
||||
const tauriVersion = await useTauriAppGetTauriVersion();
|
||||
const { showSidebar } = useSidebar();
|
||||
</script>
|
||||
|
||||
|
@@ -3,24 +3,45 @@ import * as tauriApp from "@tauri-apps/api/app";
|
||||
import * as tauriShell from "@tauri-apps/plugin-shell";
|
||||
import * as tauriOs from "@tauri-apps/plugin-os";
|
||||
import * as tauriNotification from "@tauri-apps/plugin-notification";
|
||||
import * as tauriFs from "@tauri-apps/plugin-fs";
|
||||
|
||||
export default defineNuxtModule({
|
||||
const capitalize = (name: string) => {
|
||||
return name.charAt(0).toUpperCase() + name.slice(1);
|
||||
};
|
||||
|
||||
export default defineNuxtModule<ModuleOptions>({
|
||||
meta: {
|
||||
name: "nuxt-tauri",
|
||||
configKey: "nuxt-tauri"
|
||||
},
|
||||
setup() {
|
||||
defaults: {
|
||||
prefix: "useTauri"
|
||||
},
|
||||
setup(options) {
|
||||
Object.keys(tauriApp).filter((name) => name !== "default").forEach((name) => {
|
||||
addImports({ from: "@tauri-apps/api/app", name });
|
||||
const prefix = `${options.prefix}App` || "";
|
||||
const as = prefix ? prefix + capitalize(name) : name;
|
||||
addImports({ from: "@tauri-apps/api/app", name, as });
|
||||
});
|
||||
Object.keys(tauriShell).filter((name) => name !== "default").forEach((name) => {
|
||||
addImports({ from: "@tauri-apps/plugin-shell", name });
|
||||
const prefix = `${options.prefix}Shell` || "";
|
||||
const as = prefix ? prefix + capitalize(name) : name;
|
||||
addImports({ from: "@tauri-apps/plugin-shell", name, as });
|
||||
});
|
||||
Object.keys(tauriOs).filter((name) => name !== "default").forEach((name) => {
|
||||
addImports({ from: "@tauri-apps/plugin-os", name });
|
||||
const prefix = `${options.prefix}Os` || "";
|
||||
const as = prefix ? prefix + capitalize(name) : name;
|
||||
addImports({ from: "@tauri-apps/plugin-os", name, as });
|
||||
});
|
||||
Object.keys(tauriNotification).filter((name) => name !== "default").forEach((name) => {
|
||||
addImports({ from: "@tauri-apps/plugin-notification", name });
|
||||
const prefix = `${options.prefix}Notification` || "";
|
||||
const as = prefix ? prefix + capitalize(name) : name;
|
||||
addImports({ from: "@tauri-apps/plugin-notification", name, as });
|
||||
});
|
||||
Object.keys(tauriFs).filter((name) => name !== "default").forEach((name) => {
|
||||
const prefix = `${options.prefix}Fs` || "";
|
||||
const as = prefix ? prefix + capitalize(name) : name;
|
||||
addImports({ from: "@tauri-apps/plugin-fs", name, as });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -34,7 +34,7 @@
|
||||
const result = ref("");
|
||||
|
||||
const sendCommand = async () => {
|
||||
const response = await Command.create("exec-sh", [
|
||||
const response = await useTauriShellCommand.create("exec-sh", [
|
||||
"-c",
|
||||
input.value
|
||||
]).execute();
|
||||
|
69
src/pages/file.vue
Normal file
69
src/pages/file.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<LayoutTile
|
||||
title="File System"
|
||||
description="Access the file system. For this demo the only allowed permission is read/write to the Documents folder root."
|
||||
>
|
||||
<form @submit.prevent="createDummyFile()">
|
||||
<div mx-auto max-w-xl lg="mr-0 max-w-lg">
|
||||
<div grid grid-cols-1 gap-x-8 gap-y-6>
|
||||
<div>
|
||||
<label for="filename-input" block text-sm text-white font-semibold leading-6>
|
||||
Text file name
|
||||
<span text-neutral-400 font-light>(with extension)</span>
|
||||
</label>
|
||||
<div mt="2.5">
|
||||
<input id="filename-input" v-model="fileName" type="text" name="filename-input" block w-full border-0 rounded-md bg="white/5" px="3.5" py-2 text-white shadow-sm ring-1 ring="white/10" ring-inset sm="text-sm leading-6" focus="ring-2 ring-emerald-500 ring-inset">
|
||||
</div>
|
||||
</div>
|
||||
<div mt-8>
|
||||
<label for="filecontent-input" block text-sm text-white font-semibold leading-6>File content</label>
|
||||
<div mt="2.5">
|
||||
<textarea id="filecontent-input" v-model="fileContent" name="filecontent-input" rows="10" block w-full border-0 rounded-md bg="white/5" px="3.5" py-2 text-white shadow-sm ring-1 ring="white/10" ring-inset sm="text-sm leading-6" focus="ring-2 ring-emerald-500 ring-inset" />
|
||||
</div>
|
||||
</div>
|
||||
<div flex justify-end gap-3>
|
||||
<div v-if="done" h-full flex-center text-emerald-400 space-x-1>
|
||||
<p>Done</p>
|
||||
<i-heroicons-solid-check size-4 />
|
||||
</div>
|
||||
<div v-if="error" h-full flex-center text-red-400 space-x-1>
|
||||
<p>Error</p>
|
||||
<i-heroicons-solid-exclamation-triangle size-4 />
|
||||
</div>
|
||||
<Btn type="submit" :disabled="fileName === ''">
|
||||
Create file
|
||||
</Btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</LayoutTile>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const fileName = ref("");
|
||||
const fileContent = ref("");
|
||||
const done = ref(false);
|
||||
const error = ref(false);
|
||||
|
||||
const createDummyFile = async () => {
|
||||
try {
|
||||
const fileExists = await useTauriFsExists(fileName.value, {
|
||||
baseDir: useTauriFsBaseDirectory.Document
|
||||
});
|
||||
|
||||
if (!fileExists) {
|
||||
await useTauriFsWriteTextFile(fileName.value, fileContent.value, {
|
||||
baseDir: useTauriFsBaseDirectory.Document
|
||||
});
|
||||
done.value = true;
|
||||
fileName.value = fileContent.value = "";
|
||||
setTimeout(() => done.value = false, 3000);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error creating file:", err);
|
||||
error.value = true;
|
||||
setTimeout(() => error.value = false, 3000);
|
||||
}
|
||||
};
|
||||
</script>
|
@@ -40,15 +40,15 @@
|
||||
const permissionError = ref(false);
|
||||
|
||||
const createNotification = async () => {
|
||||
let permissionGranted = await isPermissionGranted();
|
||||
let permissionGranted = await useTauriNotificationIsPermissionGranted();
|
||||
|
||||
if (!permissionGranted) {
|
||||
const permission = await requestPermission();
|
||||
const permission = await useTauriNotificationRequestPermission();
|
||||
permissionGranted = permission === "granted";
|
||||
}
|
||||
|
||||
if (permissionGranted) {
|
||||
sendNotification({
|
||||
useTauriNotificationSendNotification({
|
||||
title: notificationTitle.value,
|
||||
body: notificationBody.value
|
||||
});
|
||||
|
@@ -14,8 +14,8 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
const currentPlatform = await platform();
|
||||
const currentArch = await arch();
|
||||
const currentVersion = await version();
|
||||
const currentLocale = await locale() || "Not detectable";
|
||||
const currentPlatform = await useTauriOsPlatform();
|
||||
const currentArch = await useTauriOsArch();
|
||||
const currentVersion = await useTauriOsVersion();
|
||||
const currentLocale = await useTauriOsLocale() || "Not detectable";
|
||||
</script>
|
||||
|
4
types/global.d.ts
vendored
4
types/global.d.ts
vendored
@@ -1,3 +1,3 @@
|
||||
declare interface MyTest {
|
||||
text: string
|
||||
declare interface ModuleOptions {
|
||||
prefix: false | string
|
||||
}
|
||||
|
Reference in New Issue
Block a user