diff --git a/.github/actions/desktop-e2e-linux/action.yml b/.github/actions/desktop-e2e-linux/action.yml index 3155cd1fe7..894d83198b 100644 --- a/.github/actions/desktop-e2e-linux/action.yml +++ b/.github/actions/desktop-e2e-linux/action.yml @@ -40,7 +40,7 @@ runs: id: e2e-test run: | # Run tests and capture output to log file - pnpm -F e2e-blackbox test 2>&1 | tee "${{ env.E2E_LOGS_DIR }}/e2e-test-output.log" + pnpm -F e2e-blackbox e2e 2>&1 | tee "${{ env.E2E_LOGS_DIR }}/e2e-test-output.log" exit ${PIPESTATUS[0]} env: APP_BINARY_PATH: ${{ env.APP_BINARY_PATH }} diff --git a/Cargo.lock b/Cargo.lock index 7b5167a9ad..f6bd6a24ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,26 +964,6 @@ dependencies = [ "syn 2.0.111", ] -[[package]] -name = "async-stripe" -version = "0.39.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58d670cf4d47a1b8ffef54286a5625382e360a34ee76902fd93ad8c7032a0c30" -dependencies = [ - "futures-util", - "http-types", - "hyper 0.14.32", - "hyper-tls 0.5.0", - "serde", - "serde_json", - "serde_path_to_error", - "serde_qs 0.10.1", - "smart-default 0.6.0", - "smol_str 0.1.24", - "thiserror 1.0.69", - "tokio", -] - [[package]] name = "async-task" version = "4.7.1" @@ -3563,7 +3543,7 @@ dependencies = [ "rustc-hash 1.1.0", "rustybuzz 0.14.1", "self_cell", - "smol_str 0.2.2", + "smol_str", "swash", "sys-locale", "ttf-parser 0.21.1", @@ -4143,25 +4123,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" -[[package]] -name = "db-admin" -version = "0.1.0" -dependencies = [ - "async-stripe", - "chrono", - "codes-iso-639", - "db-core", - "libsql", - "nango", - "schemars 0.8.22", - "serde", - "serde_json", - "strum 0.26.3", - "thiserror 2.0.17", - "tokio", - "uuid", -] - [[package]] name = "db-core" version = "0.1.0" @@ -4527,6 +4488,7 @@ dependencies = [ "tauri-plugin-notification", "tauri-plugin-opener", "tauri-plugin-os", + "tauri-plugin-path2", "tauri-plugin-pdf", "tauri-plugin-permissions", "tauri-plugin-prevent-default", @@ -8448,27 +8410,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" -[[package]] -name = "http-types" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e9b187a72d63adbfba487f48095306ac823049cb504ee195541e91c7775f5ad" -dependencies = [ - "anyhow", - "async-channel 1.9.0", - "base64 0.13.1", - "futures-lite 1.13.0", - "http 0.2.12", - "infer 0.2.3", - "pin-project-lite", - "rand 0.7.3", - "serde", - "serde_json", - "serde_qs 0.8.5", - "serde_urlencoded", - "url", -] - [[package]] name = "httparse" version = "1.10.1" @@ -8615,19 +8556,6 @@ dependencies = [ "tokio-io-timeout", ] -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper 0.14.32", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "hyper-tls" version = "0.6.0" @@ -9140,12 +9068,6 @@ dependencies = [ "rustversion", ] -[[package]] -name = "infer" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac" - [[package]] name = "infer" version = "0.19.0" @@ -10651,7 +10573,7 @@ dependencies = [ "num-traits", "range-map", "scroll", - "smart-default 0.7.1", + "smart-default", ] [[package]] @@ -13992,7 +13914,7 @@ dependencies = [ "http-body-util", "hyper 1.8.1", "hyper-rustls 0.27.7", - "hyper-tls 0.6.0", + "hyper-tls", "hyper-util", "js-sys", "log", @@ -15246,28 +15168,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_qs" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7715380eec75f029a4ef7de39a9200e0a63823176b759d055b613f5a87df6a6" -dependencies = [ - "percent-encoding", - "serde", - "thiserror 1.0.69", -] - -[[package]] -name = "serde_qs" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cac3f1e2ca2fe333923a1ae72caca910b98ed0630bb35ef6f8c8517d6e81afa" -dependencies = [ - "percent-encoding", - "serde", - "thiserror 1.0.69", -] - [[package]] name = "serde_qs" version = "1.0.0-rc.4" @@ -15717,17 +15617,6 @@ version = "2.0.0-alpha.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d44cfb396c3caf6fbfd0ab422af02631b69ddd96d2eff0b0f0724f9024051b" -[[package]] -name = "smart-default" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "smart-default" version = "0.7.1" @@ -15767,15 +15656,6 @@ dependencies = [ "futures-lite 2.6.1", ] -[[package]] -name = "smol_str" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" -dependencies = [ - "serde", -] - [[package]] name = "smol_str" version = "0.2.2" @@ -17238,6 +17118,7 @@ dependencies = [ "specta-typescript", "tauri", "tauri-plugin", + "tauri-plugin-path2", "tauri-specta", "thiserror 2.0.17", "tokio", @@ -17368,6 +17249,7 @@ dependencies = [ "specta-typescript", "tauri", "tauri-plugin", + "tauri-plugin-path2", "tauri-specta", "thiserror 2.0.17", "tokio", @@ -17479,6 +17361,7 @@ dependencies = [ "tauri", "tauri-plugin", "tauri-plugin-opener", + "tauri-plugin-path2", "tauri-specta", "thiserror 2.0.17", "vergen-gix", @@ -17568,6 +17451,20 @@ dependencies = [ "thiserror 2.0.17", ] +[[package]] +name = "tauri-plugin-path2" +version = "0.1.0" +dependencies = [ + "serde", + "specta", + "specta-typescript", + "tauri", + "tauri-plugin", + "tauri-specta", + "thiserror 2.0.17", + "tokio", +] + [[package]] name = "tauri-plugin-pdf" version = "0.1.0" @@ -17662,6 +17559,7 @@ dependencies = [ "specta-typescript", "tauri", "tauri-plugin", + "tauri-plugin-path2", "tauri-specta", "thiserror 2.0.17", "tokio", @@ -17747,6 +17645,7 @@ dependencies = [ "strum 0.26.3", "tauri", "tauri-plugin", + "tauri-plugin-path2", "tauri-plugin-store", "tauri-specta", "thiserror 2.0.17", @@ -17822,7 +17721,7 @@ dependencies = [ "flate2", "futures-util", "http 1.4.0", - "infer 0.19.0", + "infer", "log", "minisign-verify", "osakit", @@ -18014,7 +17913,7 @@ dependencies = [ "glob", "html5ever 0.29.1", "http 1.4.0", - "infer 0.19.0", + "infer", "json-patch 3.0.1", "kuchikiki", "log", @@ -19100,7 +18999,7 @@ dependencies = [ "owhisper-interface", "serde", "serde_json", - "serde_qs 1.0.0-rc.4", + "serde_qs", "thiserror 2.0.17", "tokio", "tokio-stream", @@ -19178,7 +19077,7 @@ dependencies = [ "pyannote-local", "rodio", "serde_json", - "serde_qs 1.0.0-rc.4", + "serde_qs", "thiserror 2.0.17", "tokio", "tokio-util", @@ -19578,7 +19477,7 @@ dependencies = [ "ecow", "image 0.25.9", "indexmap 2.12.1", - "infer 0.19.0", + "infer", "krilla", "krilla-svg", "rustc-hash 2.1.1", diff --git a/Cargo.toml b/Cargo.toml index 766033512e..935b6ac212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,6 +138,7 @@ tauri-plugin-local-stt = { path = "plugins/local-stt" } tauri-plugin-misc = { path = "plugins/misc" } tauri-plugin-network = { path = "plugins/network" } tauri-plugin-notification = { path = "plugins/notification" } +tauri-plugin-path2 = { path = "plugins/path2" } tauri-plugin-pdf = { path = "plugins/pdf" } tauri-plugin-permissions = { path = "plugins/permissions" } tauri-plugin-settings = { path = "plugins/settings" } diff --git a/apps/desktop/package.json b/apps/desktop/package.json index e975df2274..ad7e9817ec 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -48,6 +48,7 @@ "@hypr/plugin-misc": "workspace:*", "@hypr/plugin-network": "workspace:*", "@hypr/plugin-notification": "workspace:*", + "@hypr/plugin-path2": "workspace:*", "@hypr/plugin-pdf": "workspace:*", "@hypr/plugin-permissions": "workspace:*", "@hypr/plugin-settings": "workspace:*", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 503fde2ab7..f994793c8c 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -49,6 +49,7 @@ tauri-plugin-network = { workspace = true } tauri-plugin-notification = { workspace = true } tauri-plugin-opener = { workspace = true } tauri-plugin-os = { workspace = true } +tauri-plugin-path2 = { workspace = true } tauri-plugin-pdf = { workspace = true } tauri-plugin-permissions = { workspace = true } tauri-plugin-prevent-default = { workspace = true } diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json index 7a5f44fab5..569520201f 100644 --- a/apps/desktop/src-tauri/capabilities/default.json +++ b/apps/desktop/src-tauri/capabilities/default.json @@ -158,6 +158,7 @@ "permissions:default", "settings:default", "sfx:default", + "path2:default", "pdf:default", "autostart:default", { diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 2c4ce7e1af..5214ba30d5 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -77,6 +77,7 @@ pub async fn main() { .plugin(tauri_plugin_export::init()) .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_fs::init()) + .plugin(tauri_plugin_path2::init()) .plugin(tauri_plugin_pdf::init()) .plugin(tauri_plugin_process::init()) .plugin(tauri_plugin_misc::init()) diff --git a/apps/desktop/src/store/tinybase/localPersister2.test.ts b/apps/desktop/src/store/tinybase/localPersister2.test.ts index 03941ea106..e476333b62 100644 --- a/apps/desktop/src/store/tinybase/localPersister2.test.ts +++ b/apps/desktop/src/store/tinybase/localPersister2.test.ts @@ -5,8 +5,10 @@ import { SCHEMA, type Schemas } from "@hypr/store"; import { createLocalPersister2 } from "./localPersister2"; -vi.mock("@tauri-apps/api/path", () => ({ - appDataDir: vi.fn().mockResolvedValue("/mock/data/dir/"), +vi.mock("@hypr/plugin-path2", () => ({ + commands: { + base: vi.fn().mockResolvedValue("/mock/data/dir/"), + }, })); vi.mock("@tauri-apps/plugin-fs", () => ({ diff --git a/apps/desktop/src/store/tinybase/localPersister2.ts b/apps/desktop/src/store/tinybase/localPersister2.ts index f94b1da944..3581842d48 100644 --- a/apps/desktop/src/store/tinybase/localPersister2.ts +++ b/apps/desktop/src/store/tinybase/localPersister2.ts @@ -1,9 +1,9 @@ -import { appDataDir } from "@tauri-apps/api/path"; import { exists, mkdir } from "@tauri-apps/plugin-fs"; import { createCustomPersister } from "tinybase/persisters/with-schemas"; import type { MergeableStore, OptionalSchemas } from "tinybase/with-schemas"; import { commands, type JsonValue } from "@hypr/plugin-export"; +import { commands as path2Commands } from "@hypr/plugin-path2"; import { type EnhancedNote, type Session } from "@hypr/store"; import { isValidTiptapContent } from "@hypr/tiptap/shared"; @@ -28,7 +28,7 @@ export function createLocalPersister2( const batchItems: [JsonValue, string][] = []; const dirsToCreate = new Set(); - const dataDir = await appDataDir(); + const dataDir = await path2Commands.base(); for (const [id, row] of Object.entries(tables?.enhanced_notes ?? {})) { // @ts-ignore diff --git a/apps/desktop/src/store/zustand/listener/general.ts b/apps/desktop/src/store/zustand/listener/general.ts index bb063c36c3..c24f9cf0a8 100644 --- a/apps/desktop/src/store/zustand/listener/general.ts +++ b/apps/desktop/src/store/zustand/listener/general.ts @@ -1,5 +1,4 @@ import { getIdentifier } from "@tauri-apps/api/app"; -import { appDataDir } from "@tauri-apps/api/path"; import { Effect, Exit } from "effect"; import { create as mutate } from "mutative"; import type { StoreApi } from "zustand"; @@ -18,6 +17,7 @@ import { commands as listener2Commands, events as listener2Events, } from "@hypr/plugin-listener2"; +import { commands as path2Commands } from "@hypr/plugin-path2"; import { fromResult } from "../../../effect"; import type { BatchActions, BatchState } from "./batch"; @@ -205,7 +205,7 @@ export const createGeneralSlice = < const [dataDirPath, micUsingApps, bundleId] = yield* Effect.tryPromise({ try: () => Promise.all([ - appDataDir(), + path2Commands.base(), detectCommands .listMicUsingApplications() .then((r) => @@ -291,8 +291,8 @@ export const createGeneralSlice = < onSuccess: () => { if (sessionId) { void Promise.all([ - appDataDir(), - getIdentifier().catch(() => "com.hyprnote.app"), + path2Commands.base(), + getIdentifier().catch(() => "com.hyprnote.stable"), ]) .then(([dataDirPath, bundleId]) => { const sessionPath = `${dataDirPath}/hyprnote/sessions/${sessionId}`; diff --git a/e2e/blackbox/package.json b/e2e/blackbox/package.json index c8283d4379..dd3ec42ce8 100644 --- a/e2e/blackbox/package.json +++ b/e2e/blackbox/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "test": "wdio run wdio.blackbox.conf.ts" + "e2e": "wdio run wdio.blackbox.conf.ts" }, "devDependencies": { "@wdio/cli": "^9.21.1", diff --git a/packages/tiptap/package.json b/packages/tiptap/package.json index e82065aca7..1a65e7664d 100644 --- a/packages/tiptap/package.json +++ b/packages/tiptap/package.json @@ -20,7 +20,6 @@ "@codemirror/state": "^6.5.2", "@codemirror/view": "^6.39.4", "@floating-ui/dom": "^1.7.4", - "@hypr/plugin-db": "workspace:^", "@hypr/ui": "workspace:^", "@remixicon/react": "^4.7.0", "@tanstack/react-query": "^5.90.12", diff --git a/packages/utils/package.json b/packages/utils/package.json index 06080a15a8..9618f211e8 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -6,7 +6,6 @@ "dependencies": { "@ai-sdk/openai-compatible": "^1.0.29", "@date-fns/tz": "^1.4.1", - "@hypr/plugin-db": "workspace:^", "@hypr/plugin-listener": "workspace:^", "@hypr/plugin-windows": "workspace:^", "@tauri-apps/api": "^2.9.1", diff --git a/plugins/hooks/Cargo.toml b/plugins/hooks/Cargo.toml index dd9b07fd75..22066d94f4 100644 --- a/plugins/hooks/Cargo.toml +++ b/plugins/hooks/Cargo.toml @@ -17,6 +17,8 @@ tokio = { workspace = true, features = ["macros", "rt"] } hypr-docs = { workspace = true } [dependencies] +tauri-plugin-path2 = { workspace = true } + tauri = { workspace = true, features = ["test"] } tauri-specta = { workspace = true, features = ["derive", "typescript"] } diff --git a/plugins/hooks/src/config.rs b/plugins/hooks/src/config.rs index e62b3748e0..399b7af8e8 100644 --- a/plugins/hooks/src/config.rs +++ b/plugins/hooks/src/config.rs @@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::path::PathBuf; +use tauri_plugin_path2::Path2PluginExt; + /// Configuration for hook execution. #[derive(Debug, Clone, Serialize, Deserialize, specta::Type)] pub struct HooksConfig { @@ -48,12 +50,12 @@ impl HooksConfig { } fn config_path(app: &impl tauri::Manager) -> crate::Result { - let data_dir = app - .path() - .data_dir() + let base = app + .path2() + .base() .map_err(|e| crate::Error::ConfigLoad(e.to_string()))?; - Ok(data_dir.join("hyprnote").join("settings.json")) + Ok(base.join("settings.json")) } fn empty() -> Self { diff --git a/plugins/listener2/Cargo.toml b/plugins/listener2/Cargo.toml index f235121c54..0b6fa3c043 100644 --- a/plugins/listener2/Cargo.toml +++ b/plugins/listener2/Cargo.toml @@ -14,6 +14,8 @@ tauri-plugin = { workspace = true, features = ["build"] } specta-typescript = { workspace = true } [dependencies] +tauri-plugin-path2 = { workspace = true } + hypr-audio-utils = { workspace = true } hypr-language = { workspace = true } diff --git a/plugins/listener2/src/commands.rs b/plugins/listener2/src/commands.rs index 3a24b9a070..f80a84a5a6 100644 --- a/plugins/listener2/src/commands.rs +++ b/plugins/listener2/src/commands.rs @@ -1,4 +1,5 @@ -use tauri::{Manager, path::BaseDirectory}; +use tauri::Manager; +use tauri_plugin_path2::Path2PluginExt; use crate::{BatchParams, Listener2PluginExt, Subtitle, VttWord}; @@ -34,11 +35,8 @@ pub async fn export_to_vtt( ) -> Result { use aspasia::{Moment, Subtitle, WebVttSubtitle, webvtt::WebVttCue}; - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(&session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(&session_id); std::fs::create_dir_all(&session_dir).map_err(|e| e.to_string())?; diff --git a/plugins/misc/Cargo.toml b/plugins/misc/Cargo.toml index 744b24bdc8..e0b14620ea 100644 --- a/plugins/misc/Cargo.toml +++ b/plugins/misc/Cargo.toml @@ -16,12 +16,14 @@ indoc = { workspace = true } specta-typescript = { workspace = true } [dependencies] +tauri-plugin-opener = { workspace = true } +tauri-plugin-path2 = { workspace = true } + hypr-audio-utils = { workspace = true } hypr-buffer = { workspace = true } hypr-host = { workspace = true } tauri = { workspace = true, features = ["test"] } -tauri-plugin-opener = { workspace = true } tauri-specta = { workspace = true, features = ["derive", "typescript"] } dirs = { workspace = true } diff --git a/plugins/misc/src/commands.rs b/plugins/misc/src/commands.rs index 112960c39b..cac6bcb9ac 100644 --- a/plugins/misc/src/commands.rs +++ b/plugins/misc/src/commands.rs @@ -1,7 +1,8 @@ use std::path::PathBuf; -use tauri::{Manager, path::BaseDirectory}; +use tauri::Manager; use tauri_plugin_opener::OpenerExt; +use tauri_plugin_path2::Path2PluginExt; use crate::MiscPluginExt; use crate::audio::import_audio; @@ -36,11 +37,8 @@ pub async fn audio_exist( app: tauri::AppHandle, session_id: String, ) -> Result { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(session_id); ["audio.wav", "audio.ogg"] .iter() @@ -58,11 +56,8 @@ pub async fn audio_delete( app: tauri::AppHandle, session_id: String, ) -> Result<(), String> { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(session_id); ["audio.wav", "audio.ogg"] .iter() @@ -94,11 +89,11 @@ fn audio_import_internal( session_id: &str, source_path: &str, ) -> Result { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) + let base = app + .path2() + .base() .map_err(|e| AudioImportError::PathResolver(e.to_string()))?; - let session_dir = data_dir.join(session_id); + let session_dir = base.join("sessions").join(session_id); std::fs::create_dir_all(&session_dir)?; @@ -127,11 +122,8 @@ pub async fn audio_path( app: tauri::AppHandle, session_id: String, ) -> Result { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(session_id); let path = ["audio.ogg", "audio.wav"] .iter() @@ -148,11 +140,8 @@ pub async fn audio_open( app: tauri::AppHandle, session_id: String, ) -> Result<(), String> { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(session_id); app.opener() .open_path(session_dir.to_string_lossy(), None::<&str>) @@ -167,11 +156,8 @@ pub async fn delete_session_folder( app: tauri::AppHandle, session_id: String, ) -> Result<(), String> { - let data_dir = app - .path() - .resolve("hyprnote/sessions", BaseDirectory::Data) - .map_err(|e| e.to_string())?; - let session_dir = data_dir.join(session_id); + let base = app.path2().base().map_err(|e| e.to_string())?; + let session_dir = base.join("sessions").join(session_id); if session_dir.exists() { std::fs::remove_dir_all(session_dir).map_err(|e| e.to_string())?; diff --git a/plugins/path2/.gitignore b/plugins/path2/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/plugins/path2/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/plugins/path2/Cargo.toml b/plugins/path2/Cargo.toml new file mode 100644 index 0000000000..8e426923a2 --- /dev/null +++ b/plugins/path2/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "tauri-plugin-path2" +version = "0.1.0" +authors = ["You"] +edition = "2024" +exclude = ["/js", "/node_modules"] +links = "tauri-plugin-path2" +description = "" + +[build-dependencies] +tauri-plugin = { workspace = true, features = ["build"] } + +[dev-dependencies] +specta-typescript = { workspace = true } +tokio = { workspace = true, features = ["macros"] } + +[dependencies] +tauri = { workspace = true, features = ["test"] } +tauri-specta = { workspace = true, features = ["derive", "typescript"] } + +serde = { workspace = true } +specta = { workspace = true } + +thiserror = { workspace = true } diff --git a/plugins/path2/build.rs b/plugins/path2/build.rs new file mode 100644 index 0000000000..d161c0732b --- /dev/null +++ b/plugins/path2/build.rs @@ -0,0 +1,5 @@ +const COMMANDS: &[&str] = &["base"]; + +fn main() { + tauri_plugin::Builder::new(COMMANDS).build(); +} diff --git a/plugins/path2/js/bindings.gen.ts b/plugins/path2/js/bindings.gen.ts new file mode 100644 index 0000000000..ded2b429ff --- /dev/null +++ b/plugins/path2/js/bindings.gen.ts @@ -0,0 +1,84 @@ +// @ts-nocheck + +// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually. + +/** user-defined commands **/ + + +export const commands = { +async base() : Promise { + return await TAURI_INVOKE("plugin:path2|base"); +} +} + +/** user-defined events **/ + + + +/** user-defined constants **/ + + + +/** user-defined types **/ + + + +/** tauri-specta globals **/ + +import { + invoke as TAURI_INVOKE, + Channel as TAURI_CHANNEL, +} from "@tauri-apps/api/core"; +import * as TAURI_API_EVENT from "@tauri-apps/api/event"; +import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; + +type __EventObj__ = { + listen: ( + cb: TAURI_API_EVENT.EventCallback, + ) => ReturnType>; + once: ( + cb: TAURI_API_EVENT.EventCallback, + ) => ReturnType>; + emit: null extends T + ? (payload?: T) => ReturnType + : (payload: T) => ReturnType; +}; + +export type Result = + | { status: "ok"; data: T } + | { status: "error"; error: E }; + +function __makeEvents__>( + mappings: Record, +) { + return new Proxy( + {} as unknown as { + [K in keyof T]: __EventObj__ & { + (handle: __WebviewWindow__): __EventObj__; + }; + }, + { + get: (_, event) => { + const name = mappings[event as keyof T]; + + return new Proxy((() => {}) as any, { + apply: (_, __, [window]: [__WebviewWindow__]) => ({ + listen: (arg: any) => window.listen(name, arg), + once: (arg: any) => window.once(name, arg), + emit: (arg: any) => window.emit(name, arg), + }), + get: (_, command: keyof __EventObj__) => { + switch (command) { + case "listen": + return (arg: any) => TAURI_API_EVENT.listen(name, arg); + case "once": + return (arg: any) => TAURI_API_EVENT.once(name, arg); + case "emit": + return (arg: any) => TAURI_API_EVENT.emit(name, arg); + } + }, + }); + }, + }, + ); +} diff --git a/plugins/path2/js/index.ts b/plugins/path2/js/index.ts new file mode 100644 index 0000000000..a96e122f03 --- /dev/null +++ b/plugins/path2/js/index.ts @@ -0,0 +1 @@ +export * from "./bindings.gen"; diff --git a/plugins/path2/package.json b/plugins/path2/package.json new file mode 100644 index 0000000000..3240f908a5 --- /dev/null +++ b/plugins/path2/package.json @@ -0,0 +1,11 @@ +{ + "name": "@hypr/plugin-path2", + "private": true, + "main": "./js/index.ts", + "scripts": { + "codegen": "cargo test -p tauri-plugin-path2" + }, + "dependencies": { + "@tauri-apps/api": "^2.9.1" + } +} diff --git a/plugins/path2/permissions/autogenerated/commands/base.toml b/plugins/path2/permissions/autogenerated/commands/base.toml new file mode 100644 index 0000000000..969839f58e --- /dev/null +++ b/plugins/path2/permissions/autogenerated/commands/base.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-base" +description = "Enables the base command without any pre-configured scope." +commands.allow = ["base"] + +[[permission]] +identifier = "deny-base" +description = "Denies the base command without any pre-configured scope." +commands.deny = ["base"] diff --git a/plugins/path2/permissions/autogenerated/reference.md b/plugins/path2/permissions/autogenerated/reference.md new file mode 100644 index 0000000000..fc22cab440 --- /dev/null +++ b/plugins/path2/permissions/autogenerated/reference.md @@ -0,0 +1,43 @@ +## Default Permission + +Default permissions for the path2 plugin + +#### This default permission set includes the following: + +- `allow-base` + +## Permission Table + + + + + + + + + + + + + + + + + +
IdentifierDescription
+ +`path2:allow-base` + + + +Enables the base command without any pre-configured scope. + +
+ +`path2:deny-base` + + + +Denies the base command without any pre-configured scope. + +
diff --git a/plugins/path2/permissions/default.toml b/plugins/path2/permissions/default.toml new file mode 100644 index 0000000000..ec1daeb9dc --- /dev/null +++ b/plugins/path2/permissions/default.toml @@ -0,0 +1,3 @@ +[default] +description = "Default permissions for the path2 plugin" +permissions = ["allow-base"] diff --git a/plugins/path2/permissions/schemas/schema.json b/plugins/path2/permissions/schemas/schema.json new file mode 100644 index 0000000000..b4cde87d2c --- /dev/null +++ b/plugins/path2/permissions/schemas/schema.json @@ -0,0 +1,318 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "PermissionFile", + "description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.", + "type": "object", + "properties": { + "default": { + "description": "The default permission set for the plugin", + "anyOf": [ + { + "$ref": "#/definitions/DefaultPermission" + }, + { + "type": "null" + } + ] + }, + "set": { + "description": "A list of permissions sets defined", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionSet" + } + }, + "permission": { + "description": "A list of inlined permissions", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/Permission" + } + } + }, + "definitions": { + "DefaultPermission": { + "description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.", + "type": "object", + "required": [ + "permissions" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "description": { + "description": "Human-readable description of what the permission does. Tauri convention is to use `

` headings in markdown content for Tauri documentation generation purposes.", + "type": [ + "string", + "null" + ] + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "PermissionSet": { + "description": "A set of direct permissions grouped together under a new name.", + "type": "object", + "required": [ + "description", + "identifier", + "permissions" + ], + "properties": { + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does.", + "type": "string" + }, + "permissions": { + "description": "All permissions this set contains.", + "type": "array", + "items": { + "$ref": "#/definitions/PermissionKind" + } + } + } + }, + "Permission": { + "description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.", + "type": "object", + "required": [ + "identifier" + ], + "properties": { + "version": { + "description": "The version of the permission.", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 1.0 + }, + "identifier": { + "description": "A unique identifier for the permission.", + "type": "string" + }, + "description": { + "description": "Human-readable description of what the permission does. Tauri internal convention is to use `

` headings in markdown content for Tauri documentation generation purposes.", + "type": [ + "string", + "null" + ] + }, + "commands": { + "description": "Allowed or denied commands when using this permission.", + "default": { + "allow": [], + "deny": [] + }, + "allOf": [ + { + "$ref": "#/definitions/Commands" + } + ] + }, + "scope": { + "description": "Allowed or denied scoped when using this permission.", + "allOf": [ + { + "$ref": "#/definitions/Scopes" + } + ] + }, + "platforms": { + "description": "Target platforms this permission applies. By default all platforms are affected by this permission.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Target" + } + } + } + }, + "Commands": { + "description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.", + "type": "object", + "properties": { + "allow": { + "description": "Allowed command.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "deny": { + "description": "Denied command, which takes priority.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "Scopes": { + "description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```", + "type": "object", + "properties": { + "allow": { + "description": "Data that defines what is allowed by the scope.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + }, + "deny": { + "description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.", + "type": [ + "array", + "null" + ], + "items": { + "$ref": "#/definitions/Value" + } + } + } + }, + "Value": { + "description": "All supported ACL values.", + "anyOf": [ + { + "description": "Represents a null JSON value.", + "type": "null" + }, + { + "description": "Represents a [`bool`].", + "type": "boolean" + }, + { + "description": "Represents a valid ACL [`Number`].", + "allOf": [ + { + "$ref": "#/definitions/Number" + } + ] + }, + { + "description": "Represents a [`String`].", + "type": "string" + }, + { + "description": "Represents a list of other [`Value`]s.", + "type": "array", + "items": { + "$ref": "#/definitions/Value" + } + }, + { + "description": "Represents a map of [`String`] keys to [`Value`]s.", + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Value" + } + } + ] + }, + "Number": { + "description": "A valid ACL number.", + "anyOf": [ + { + "description": "Represents an [`i64`].", + "type": "integer", + "format": "int64" + }, + { + "description": "Represents a [`f64`].", + "type": "number", + "format": "double" + } + ] + }, + "Target": { + "description": "Platform target.", + "oneOf": [ + { + "description": "MacOS.", + "type": "string", + "enum": [ + "macOS" + ] + }, + { + "description": "Windows.", + "type": "string", + "enum": [ + "windows" + ] + }, + { + "description": "Linux.", + "type": "string", + "enum": [ + "linux" + ] + }, + { + "description": "Android.", + "type": "string", + "enum": [ + "android" + ] + }, + { + "description": "iOS.", + "type": "string", + "enum": [ + "iOS" + ] + } + ] + }, + "PermissionKind": { + "type": "string", + "oneOf": [ + { + "description": "Enables the base command without any pre-configured scope.", + "type": "string", + "const": "allow-base", + "markdownDescription": "Enables the base command without any pre-configured scope." + }, + { + "description": "Denies the base command without any pre-configured scope.", + "type": "string", + "const": "deny-base", + "markdownDescription": "Denies the base command without any pre-configured scope." + }, + { + "description": "Default permissions for the path2 plugin\n#### This default permission set includes:\n\n- `allow-base`", + "type": "string", + "const": "default", + "markdownDescription": "Default permissions for the path2 plugin\n#### This default permission set includes:\n\n- `allow-base`" + } + ] + } + } +} \ No newline at end of file diff --git a/plugins/path2/src/commands.rs b/plugins/path2/src/commands.rs new file mode 100644 index 0000000000..17f34f94a8 --- /dev/null +++ b/plugins/path2/src/commands.rs @@ -0,0 +1,10 @@ +use crate::Path2PluginExt; + +#[tauri::command] +#[specta::specta] +pub(crate) async fn base(app: tauri::AppHandle) -> Result { + app.path2() + .base() + .map(|p| p.to_string_lossy().to_string()) + .map_err(|e| e.to_string()) +} diff --git a/plugins/path2/src/error.rs b/plugins/path2/src/error.rs new file mode 100644 index 0000000000..a93d52c5bf --- /dev/null +++ b/plugins/path2/src/error.rs @@ -0,0 +1,20 @@ +use serde::{Serialize, Serializer}; + +pub type Result = std::result::Result; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("path error: {0}")] + Path(String), + #[error("io error: {0}")] + Io(#[from] std::io::Error), +} + +impl Serialize for Error { + fn serialize(&self, serializer: S) -> std::result::Result + where + S: Serializer, + { + serializer.serialize_str(self.to_string().as_ref()) + } +} diff --git a/plugins/path2/src/ext.rs b/plugins/path2/src/ext.rs new file mode 100644 index 0000000000..f54e8d52dd --- /dev/null +++ b/plugins/path2/src/ext.rs @@ -0,0 +1,47 @@ +use std::path::PathBuf; + +use tauri::Manager; + +pub struct Path2<'a, R: tauri::Runtime, M: Manager> { + manager: &'a M, + _runtime: std::marker::PhantomData R>, +} + +impl<'a, R: tauri::Runtime, M: Manager> Path2<'a, R, M> { + pub fn base(&self) -> Result { + let path = if cfg!(debug_assertions) { + self.manager + .path() + .app_data_dir() + .map_err(|e| crate::Error::Path(e.to_string()))? + } else { + let data_dir = self + .manager + .path() + .data_dir() + .map_err(|e| crate::Error::Path(e.to_string()))?; + data_dir.join("hyprnote") + }; + + std::fs::create_dir_all(&path)?; + Ok(path) + } +} + +pub trait Path2PluginExt { + fn path2(&self) -> Path2<'_, R, Self> + where + Self: Manager + Sized; +} + +impl> Path2PluginExt for T { + fn path2(&self) -> Path2<'_, R, Self> + where + Self: Sized, + { + Path2 { + manager: self, + _runtime: std::marker::PhantomData, + } + } +} diff --git a/plugins/path2/src/lib.rs b/plugins/path2/src/lib.rs new file mode 100644 index 0000000000..aade6757bd --- /dev/null +++ b/plugins/path2/src/lib.rs @@ -0,0 +1,61 @@ +mod commands; +mod error; +mod ext; + +pub use error::*; +pub use ext::*; + +const PLUGIN_NAME: &str = "path2"; + +fn make_specta_builder() -> tauri_specta::Builder { + tauri_specta::Builder::::new() + .plugin_name(PLUGIN_NAME) + .commands(tauri_specta::collect_commands![ + commands::base::, + ]) + .error_handling(tauri_specta::ErrorHandlingMode::Throw) +} + +pub fn init() -> tauri::plugin::TauriPlugin { + let specta_builder = make_specta_builder(); + + tauri::plugin::Builder::new(PLUGIN_NAME) + .invoke_handler(specta_builder.invoke_handler()) + .build() +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn export_types() { + const OUTPUT_FILE: &str = "./js/bindings.gen.ts"; + + make_specta_builder::() + .export( + specta_typescript::Typescript::default() + .formatter(specta_typescript::formatter::prettier) + .bigint(specta_typescript::BigIntExportBehavior::Number), + OUTPUT_FILE, + ) + .unwrap(); + + let content = std::fs::read_to_string(OUTPUT_FILE).unwrap(); + std::fs::write(OUTPUT_FILE, format!("// @ts-nocheck\n{content}")).unwrap(); + } + + fn create_app(builder: tauri::Builder) -> tauri::App { + let mut ctx = tauri::test::mock_context(tauri::test::noop_assets()); + ctx.config_mut().identifier = "com.hyprnote.dev".to_string(); + + builder.plugin(init()).build(ctx).unwrap() + } + + #[tokio::test] + async fn test_path2() { + let app = create_app(tauri::test::mock_builder()); + let result = app.path2().base(); + assert!(result.is_ok()); + } +} diff --git a/plugins/path2/tsconfig.json b/plugins/path2/tsconfig.json new file mode 100644 index 0000000000..13b985325d --- /dev/null +++ b/plugins/path2/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["./js/*.ts"], + "exclude": ["node_modules"] +} diff --git a/plugins/settings/Cargo.toml b/plugins/settings/Cargo.toml index ee5f896d24..85440f9911 100644 --- a/plugins/settings/Cargo.toml +++ b/plugins/settings/Cargo.toml @@ -15,6 +15,8 @@ specta-typescript = { workspace = true } tokio = { workspace = true, features = ["macros"] } [dependencies] +tauri-plugin-path2 = { workspace = true } + tauri = { workspace = true, features = ["test"] } tauri-specta = { workspace = true, features = ["derive", "typescript"] } diff --git a/plugins/settings/src/lib.rs b/plugins/settings/src/lib.rs index 323d641201..6429d9e121 100644 --- a/plugins/settings/src/lib.rs +++ b/plugins/settings/src/lib.rs @@ -1,4 +1,5 @@ use tauri::Manager; +use tauri_plugin_path2::Path2PluginExt; mod commands; mod error; @@ -28,7 +29,7 @@ pub fn init() -> tauri::plugin::TauriPlugin { tauri::plugin::Builder::new(PLUGIN_NAME) .invoke_handler(specta_builder.invoke_handler()) .setup(|app, _api| { - let base = app.path().data_dir().unwrap().join("hyprnote"); + let base = app.path2().base().unwrap(); let state = SettingsState::new(base); assert!(app.manage(state)); Ok(()) diff --git a/plugins/store2/Cargo.toml b/plugins/store2/Cargo.toml index 9e25ca588e..737137ba72 100644 --- a/plugins/store2/Cargo.toml +++ b/plugins/store2/Cargo.toml @@ -19,6 +19,7 @@ tokio = { workspace = true, features = ["rt", "macros"] } [dependencies] tauri = { workspace = true, features = ["test"] } +tauri-plugin-path2 = { workspace = true } tauri-plugin-store = { workspace = true } tauri-specta = { workspace = true, features = ["derive", "typescript"] } diff --git a/plugins/store2/src/ext.rs b/plugins/store2/src/ext.rs index fce3378336..9b767e518e 100644 --- a/plugins/store2/src/ext.rs +++ b/plugins/store2/src/ext.rs @@ -2,12 +2,12 @@ use std::path::PathBuf; use std::sync::Arc; use tauri::Manager; +use tauri_plugin_path2::Path2PluginExt; pub const STORE_FILENAME: &str = "store.json"; pub fn store_path(app: &tauri::AppHandle) -> Result { - let store_dir = app.path().data_dir()?.join("hyprnote"); - std::fs::create_dir_all(&store_dir).ok(); + let store_dir = app.path2().base()?; Ok(store_dir.join(STORE_FILENAME)) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f343c48c6..dc34ac06dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -250,6 +250,9 @@ importers: '@hypr/plugin-notification': specifier: workspace:* version: link:../../plugins/notification + '@hypr/plugin-path2': + specifier: workspace:* + version: link:../../plugins/path2 '@hypr/plugin-pdf': specifier: workspace:* version: link:../../plugins/pdf @@ -1051,9 +1054,6 @@ importers: '@floating-ui/dom': specifier: ^1.7.4 version: 1.7.4 - '@hypr/plugin-db': - specifier: workspace:^ - version: link:../../plugins/db '@hypr/ui': specifier: workspace:^ version: link:../ui @@ -1320,9 +1320,6 @@ importers: '@date-fns/tz': specifier: ^1.4.1 version: 1.4.1 - '@hypr/plugin-db': - specifier: workspace:^ - version: link:../../plugins/db '@hypr/plugin-listener': specifier: workspace:^ version: link:../../plugins/listener @@ -1397,12 +1394,6 @@ importers: specifier: ^2.9.1 version: 2.9.1 - plugins/db: - dependencies: - '@tauri-apps/api': - specifier: ^2.9.1 - version: 2.9.1 - plugins/db2: dependencies: '@tauri-apps/api': @@ -1493,6 +1484,12 @@ importers: specifier: ^2.9.1 version: 2.9.1 + plugins/path2: + dependencies: + '@tauri-apps/api': + specifier: ^2.9.1 + version: 2.9.1 + plugins/pdf: dependencies: '@tauri-apps/api':