diff --git a/Cargo.lock b/Cargo.lock index 355fef35d0..588c378dd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4829,6 +4829,7 @@ dependencies = [ "tauri-plugin-dialog", "tauri-plugin-export", "tauri-plugin-extensions", + "tauri-plugin-folder", "tauri-plugin-fs", "tauri-plugin-hooks", "tauri-plugin-http", @@ -18244,6 +18245,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "tauri-plugin-folder" +version = "0.1.0" +dependencies = [ + "serde", + "specta", + "specta-typescript", + "tauri", + "tauri-plugin", + "tauri-specta", + "thiserror 2.0.17", + "tokio", +] + [[package]] name = "tauri-plugin-fs" version = "2.4.4" diff --git a/Cargo.toml b/Cargo.toml index 32642295d4..3238f7e9a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,6 +139,7 @@ tauri-plugin-deeplink2 = { path = "plugins/deeplink2" } tauri-plugin-detect = { path = "plugins/detect" } tauri-plugin-export = { path = "plugins/export" } tauri-plugin-extensions = { path = "plugins/extensions" } +tauri-plugin-folder = { path = "plugins/folder" } tauri-plugin-hooks = { path = "plugins/hooks" } tauri-plugin-icon = { path = "plugins/icon" } tauri-plugin-importer = { path = "plugins/importer" } diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 1305a2693d..2872034259 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -37,6 +37,7 @@ "@hypr/plugin-deeplink2": "workspace:*", "@hypr/plugin-detect": "workspace:*", "@hypr/plugin-export": "workspace:*", + "@hypr/plugin-folder": "workspace:*", "@hypr/plugin-extensions": "workspace:*", "@hypr/plugin-hooks": "workspace:*", "@hypr/plugin-icon": "workspace:*", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 5771798038..c4b8f1d3c7 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -36,6 +36,7 @@ tauri-plugin-detect = { workspace = true } tauri-plugin-dialog = { workspace = true } tauri-plugin-export = { workspace = true } tauri-plugin-extensions = { workspace = true } +tauri-plugin-folder = { workspace = true } tauri-plugin-fs = { workspace = true } tauri-plugin-hooks = { workspace = true } tauri-plugin-http = { workspace = true } diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json index 536f2a09ab..b5f74603f4 100644 --- a/apps/desktop/src-tauri/capabilities/default.json +++ b/apps/desktop/src-tauri/capabilities/default.json @@ -194,6 +194,7 @@ "os:default", "detect:default", "export:default", + "folder:default", "permissions:default", "settings:default", "sfx:default", diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index ae507432a6..875570c743 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -95,6 +95,7 @@ pub async fn main() { .plugin(tauri_plugin_deep_link::init()) .plugin(tauri_plugin_deeplink2::init()) .plugin(tauri_plugin_export::init()) + .plugin(tauri_plugin_folder::init()) .plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_path2::init()) diff --git a/plugins/folder/.gitignore b/plugins/folder/.gitignore new file mode 100644 index 0000000000..50d8e32e89 --- /dev/null +++ b/plugins/folder/.gitignore @@ -0,0 +1,17 @@ +/.vs +.DS_Store +.Thumbs.db +*.sublime* +.idea/ +debug.log +package-lock.json +.vscode/settings.json +yarn.lock + +/.tauri +/target +Cargo.lock +node_modules/ + +dist-js +dist diff --git a/plugins/folder/Cargo.toml b/plugins/folder/Cargo.toml new file mode 100644 index 0000000000..037382a509 --- /dev/null +++ b/plugins/folder/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "tauri-plugin-folder" +version = "0.1.0" +authors = ["You"] +edition = "2024" +exclude = ["/js", "/node_modules"] +links = "tauri-plugin-folder" +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/folder/build.rs b/plugins/folder/build.rs new file mode 100644 index 0000000000..029861396b --- /dev/null +++ b/plugins/folder/build.rs @@ -0,0 +1,5 @@ +const COMMANDS: &[&str] = &["ping"]; + +fn main() { + tauri_plugin::Builder::new(COMMANDS).build(); +} diff --git a/plugins/folder/js/bindings.gen.ts b/plugins/folder/js/bindings.gen.ts new file mode 100644 index 0000000000..c3a9782078 --- /dev/null +++ b/plugins/folder/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 ping() : Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("plugin:folder|ping") }; +} 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/folder/js/index.ts b/plugins/folder/js/index.ts new file mode 100644 index 0000000000..a96e122f03 --- /dev/null +++ b/plugins/folder/js/index.ts @@ -0,0 +1 @@ +export * from "./bindings.gen"; diff --git a/plugins/folder/package.json b/plugins/folder/package.json new file mode 100644 index 0000000000..669b5ee0b0 --- /dev/null +++ b/plugins/folder/package.json @@ -0,0 +1,11 @@ +{ + "name": "@hypr/plugin-folder", + "private": true, + "main": "./js/index.ts", + "scripts": { + "codegen": "cargo test -p tauri-plugin-folder" + }, + "dependencies": { + "@tauri-apps/api": "^2.9.1" + } +} diff --git a/plugins/folder/permissions/autogenerated/commands/ping.toml b/plugins/folder/permissions/autogenerated/commands/ping.toml new file mode 100644 index 0000000000..1d1358807e --- /dev/null +++ b/plugins/folder/permissions/autogenerated/commands/ping.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-ping" +description = "Enables the ping command without any pre-configured scope." +commands.allow = ["ping"] + +[[permission]] +identifier = "deny-ping" +description = "Denies the ping command without any pre-configured scope." +commands.deny = ["ping"] diff --git a/plugins/folder/permissions/autogenerated/reference.md b/plugins/folder/permissions/autogenerated/reference.md new file mode 100644 index 0000000000..3921775504 --- /dev/null +++ b/plugins/folder/permissions/autogenerated/reference.md @@ -0,0 +1,43 @@ +## Default Permission + +Default permissions for the plugin + +#### This default permission set includes the following: + +- `allow-ping` + +## Permission Table + + + + + + + + + + + + + + + + + +
IdentifierDescription
+ +`folder:allow-ping` + + + +Enables the ping command without any pre-configured scope. + +
+ +`folder:deny-ping` + + + +Denies the ping command without any pre-configured scope. + +
diff --git a/plugins/folder/permissions/default.toml b/plugins/folder/permissions/default.toml new file mode 100644 index 0000000000..cc5a76f22e --- /dev/null +++ b/plugins/folder/permissions/default.toml @@ -0,0 +1,3 @@ +[default] +description = "Default permissions for the plugin" +permissions = ["allow-ping"] diff --git a/plugins/folder/permissions/schemas/schema.json b/plugins/folder/permissions/schemas/schema.json new file mode 100644 index 0000000000..ac68e129e2 --- /dev/null +++ b/plugins/folder/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 ping command without any pre-configured scope.", + "type": "string", + "const": "allow-ping", + "markdownDescription": "Enables the ping command without any pre-configured scope." + }, + { + "description": "Denies the ping command without any pre-configured scope.", + "type": "string", + "const": "deny-ping", + "markdownDescription": "Denies the ping command without any pre-configured scope." + }, + { + "description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-ping`", + "type": "string", + "const": "default", + "markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-ping`" + } + ] + } + } +} \ No newline at end of file diff --git a/plugins/folder/src/commands.rs b/plugins/folder/src/commands.rs new file mode 100644 index 0000000000..2684be50ba --- /dev/null +++ b/plugins/folder/src/commands.rs @@ -0,0 +1,7 @@ +use crate::FolderPluginExt; + +#[tauri::command] +#[specta::specta] +pub(crate) async fn ping(app: tauri::AppHandle) -> Result { + app.folder().ping().map_err(|e| e.to_string()) +} diff --git a/plugins/folder/src/error.rs b/plugins/folder/src/error.rs new file mode 100644 index 0000000000..b816bf4ccd --- /dev/null +++ b/plugins/folder/src/error.rs @@ -0,0 +1,18 @@ +use serde::{Serialize, ser::Serializer}; + +pub type Result = std::result::Result; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("Unknown error")] + Unknown, +} + +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/folder/src/ext.rs b/plugins/folder/src/ext.rs new file mode 100644 index 0000000000..387c42f13e --- /dev/null +++ b/plugins/folder/src/ext.rs @@ -0,0 +1,28 @@ +pub struct Folder<'a, R: tauri::Runtime, M: tauri::Manager> { + manager: &'a M, + _runtime: std::marker::PhantomData R>, +} + +impl<'a, R: tauri::Runtime, M: tauri::Manager> Folder<'a, R, M> { + pub fn ping(&self) -> Result { + Ok("pong".to_string()) + } +} + +pub trait FolderPluginExt { + fn folder(&self) -> Folder<'_, R, Self> + where + Self: tauri::Manager + Sized; +} + +impl> FolderPluginExt for T { + fn folder(&self) -> Folder<'_, R, Self> + where + Self: Sized, + { + Folder { + manager: self, + _runtime: std::marker::PhantomData, + } + } +} diff --git a/plugins/folder/src/lib.rs b/plugins/folder/src/lib.rs new file mode 100644 index 0000000000..bf28902911 --- /dev/null +++ b/plugins/folder/src/lib.rs @@ -0,0 +1,47 @@ +mod commands; +mod error; +mod ext; + +pub use error::{Error, Result}; +pub use ext::*; + +const PLUGIN_NAME: &str = "folder"; + +fn make_specta_builder() -> tauri_specta::Builder { + tauri_specta::Builder::::new() + .plugin_name(PLUGIN_NAME) + .commands(tauri_specta::collect_commands![ + commands::ping::, + ]) + .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(); + } +} diff --git a/plugins/folder/tsconfig.json b/plugins/folder/tsconfig.json new file mode 100644 index 0000000000..13b985325d --- /dev/null +++ b/plugins/folder/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../tsconfig.base.json", + "include": ["./js/*.ts"], + "exclude": ["node_modules"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cf502fa8bc..20986296d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -263,6 +263,9 @@ importers: '@hypr/plugin-extensions': specifier: workspace:* version: link:../../plugins/extensions + '@hypr/plugin-folder': + specifier: workspace:* + version: link:../../plugins/folder '@hypr/plugin-hooks': specifier: workspace:* version: link:../../plugins/hooks @@ -838,7 +841,7 @@ importers: version: 1.11.19 drizzle-orm: specifier: ^0.44.7 - version: 0.44.7(@cloudflare/workers-types@4.20251221.0)(@opentelemetry/api@1.9.0)(@types/pg@8.16.0)(bun-types@1.3.5)(pg@8.16.3)(postgres@3.4.7) + version: 0.44.7(@cloudflare/workers-types@4.20251221.0)(@opentelemetry/api@1.8.0)(@types/pg@8.16.0)(bun-types@1.3.5)(pg@8.16.3)(postgres@3.4.7) exa-js: specifier: ^1.10.2 version: 1.10.2(ws@8.18.3) @@ -1496,6 +1499,12 @@ importers: specifier: ^2.9.1 version: 2.9.1 + plugins/folder: + dependencies: + '@tauri-apps/api': + specifier: ^2.9.1 + version: 2.9.1 + plugins/hooks: dependencies: '@tauri-apps/api': @@ -26266,10 +26275,10 @@ snapshots: dotenv@17.2.3: {} - drizzle-orm@0.44.7(@cloudflare/workers-types@4.20251221.0)(@opentelemetry/api@1.9.0)(@types/pg@8.16.0)(bun-types@1.3.5)(pg@8.16.3)(postgres@3.4.7): + drizzle-orm@0.44.7(@cloudflare/workers-types@4.20251221.0)(@opentelemetry/api@1.8.0)(@types/pg@8.16.0)(bun-types@1.3.5)(pg@8.16.3)(postgres@3.4.7): optionalDependencies: '@cloudflare/workers-types': 4.20251221.0 - '@opentelemetry/api': 1.9.0 + '@opentelemetry/api': 1.8.0 '@types/pg': 8.16.0 bun-types: 1.3.5 pg: 8.16.3