diff --git a/frontend/bun.lockb b/frontend/bun.lockb index 1f190b7..0887dfa 100755 Binary files a/frontend/bun.lockb and b/frontend/bun.lockb differ diff --git a/frontend/package.json b/frontend/package.json index d83836f..9002825 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -20,6 +20,7 @@ "@tabler/icons-solidjs": "^3.30.0", "@tauri-apps/api": "^2", "@tauri-apps/plugin-dialog": "~2", + "@tauri-apps/plugin-fs": "~2", "@tauri-apps/plugin-http": "~2", "@tauri-apps/plugin-opener": "^2", "clsx": "^2.1.1", @@ -30,6 +31,7 @@ "solid-motionone": "^1.0.3", "solidjs-markdown": "^0.2.0", "tailwind-scrollbar-hide": "^2.0.0", + "tauri-plugin-sharetarget-api": "^0.1.6", "valibot": "^1.0.0-rc.2" }, "devDependencies": { diff --git a/frontend/src-tauri/Cargo.lock b/frontend/src-tauri/Cargo.lock index 17746d0..b303b4f 100644 --- a/frontend/src-tauri/Cargo.lock +++ b/frontend/src-tauri/Cargo.lock @@ -13,9 +13,11 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-fs", "tauri-plugin-global-shortcut", "tauri-plugin-http", "tauri-plugin-log", + "tauri-plugin-sharetarget", "tauri-plugin-store", "tokio", ] @@ -4057,6 +4059,20 @@ dependencies = [ "time", ] +[[package]] +name = "tauri-plugin-sharetarget" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a6e4638b6a5492a46847fc9e994df8cfd2dbc1bacc11f15c207d6a2163c341" +dependencies = [ + "serde", + "serde_json", + "tauri", + "tauri-build", + "tauri-plugin", + "thiserror 1.0.69", +] + [[package]] name = "tauri-plugin-store" version = "2.2.0" diff --git a/frontend/src-tauri/Cargo.toml b/frontend/src-tauri/Cargo.toml index 50f8ced..8d72705 100644 --- a/frontend/src-tauri/Cargo.toml +++ b/frontend/src-tauri/Cargo.toml @@ -27,6 +27,8 @@ tokio = { version = "1.36.0", features = ["full"] } tauri-plugin-store = "2.0.0-beta.12" tauri-plugin-http = "2.0.0-beta.12" tauri-plugin-log = "2" +tauri-plugin-sharetarget = "0.1.6" +tauri-plugin-fs = "2" [target."cfg(target_os = \"macos\")".dependencies] cocoa = "0.26" diff --git a/frontend/src-tauri/capabilities/default.json b/frontend/src-tauri/capabilities/default.json index fd96f69..d428b17 100644 --- a/frontend/src-tauri/capabilities/default.json +++ b/frontend/src-tauri/capabilities/default.json @@ -1,26 +1,39 @@ { - "$schema": "../gen/schemas/desktop-schema.json", - "identifier": "default", - "description": "Capability for the main window", - "windows": ["main"], - "permissions": [ - "core:default", - "core:window:allow-start-dragging", - "http:default", + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": [ + "main" + ], + "permissions": [ + "core:default", + "core:window:allow-start-dragging", + "http:default", + "sharetarget:default", + { + "identifier": "fs:scope", + "allow": [ { - "identifier": "http:default", - "allow": [ - { - "url": "https://haystack.johncosta.tech" - }, - { - "url": "http://localhost:3040" - }, - { - "url": "http://192.168.1.199:3040" - } - ] + "path": "$APPDATA/databases/*" + } + ] + }, + { + "identifier": "http:default", + "allow": [ + { + "url": "https://haystack.johncosta.tech" }, - "log:default" - ] -} + { + "url": "http://localhost:3040" + }, + { + "url": "http://192.168.1.199:3040" + } + ] + }, + "log:default", + "fs:default", + "fs:default" + ] +} \ No newline at end of file diff --git a/frontend/src-tauri/gen/android/app/src/main/AndroidManifest.xml b/frontend/src-tauri/gen/android/app/src/main/AndroidManifest.xml index a8d9fb6..faad303 100644 --- a/frontend/src-tauri/gen/android/app/src/main/AndroidManifest.xml +++ b/frontend/src-tauri/gen/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + @@ -18,7 +19,10 @@ android:exported="true"> + + + diff --git a/frontend/src-tauri/src/lib.rs b/frontend/src-tauri/src/lib.rs index 756b9f3..8720ed1 100644 --- a/frontend/src-tauri/src/lib.rs +++ b/frontend/src-tauri/src/lib.rs @@ -11,9 +11,11 @@ pub fn run() { let watcher_state = new_shared_watcher_state(); tauri::Builder::default() + .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_log::Builder::new().build()) .plugin(tauri_plugin_store::Builder::new().build()) .plugin(tauri_plugin_http::init()) + .plugin(tauri_plugin_sharetarget::init()) // .plugin(tauri_plugin_dialog::init()) // .plugin(tauri_plugin_opener::init()) // .manage(watcher_state) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c4fefac..0f796de 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,13 +1,22 @@ import { Route, Router } from "@solidjs/router"; import { listen } from "@tauri-apps/api/event"; -import { createEffect, onCleanup } from "solid-js"; +import { createEffect, createSignal, For, onCleanup, Show } from "solid-js"; import { Login } from "./Login"; import { ProtectedRoute } from "./ProtectedRoute"; import { Search } from "./Search"; import { Settings } from "./Settings"; import { ImageViewer } from "./components/ImageViewer"; +import type { PluginListener } from "@tauri-apps/api/core"; +import { + listenForShareEvents, + type ShareEvent, +} from "tauri-plugin-sharetarget-api"; +import { readFile } from "@tauri-apps/plugin-fs"; export const App = () => { + const [logs, setLogs] = createSignal([]); + const [file, setFile] = createSignal(); + createEffect(() => { // TODO: Don't use window.location.href const unlisten = listen("focus-search", () => { @@ -19,9 +28,40 @@ export const App = () => { }); }); + createEffect(() => { + let listener: PluginListener; + const setupListener = async () => { + listener = await listenForShareEvents( + async (intent: ShareEvent) => { + const contents = await readFile(intent.stream).catch( + (error: Error) => { + console.warn("fetching shared content failed:"); + throw error; + }, + ); + setFile( + new File([contents], intent.name ?? "no-name", { + type: intent.content_type, + }), + ); + setLogs((l) => [...l, intent.uri]); + }, + ); + }; + setupListener(); + return () => { + listener?.unregister(); + }; + }); + return ( <> +

Hello

+ + {(f) => my-image} + + {(log) =>

{log}

}