diff --git a/Cargo.lock b/Cargo.lock index 7b5167a9ad..cba217ee26 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" @@ -17568,6 +17448,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" @@ -17822,7 +17716,7 @@ dependencies = [ "flate2", "futures-util", "http 1.4.0", - "infer 0.19.0", + "infer", "log", "minisign-verify", "osakit", @@ -18014,7 +17908,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 +18994,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 +19072,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 +19472,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/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/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..c193861ddd --- /dev/null +++ b/plugins/path2/js/bindings.gen.ts @@ -0,0 +1,89 @@ +// @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> { + try { + return { status: "ok", data: await TAURI_INVOKE("plugin:path2|base") }; +} catch (e) { + if(e instanceof Error) throw e; + else return { status: "error", error: e as any }; +} +} +} + +/** 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..45c6e63a8d --- /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::Result) +} + +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"] +}