diff --git a/plugins/push-notifications/.gitignore b/plugins/push-notifications/.gitignore new file mode 100644 index 000000000..50d8e32e8 --- /dev/null +++ b/plugins/push-notifications/.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/push-notifications/Cargo.toml b/plugins/push-notifications/Cargo.toml new file mode 100644 index 000000000..07e295c97 --- /dev/null +++ b/plugins/push-notifications/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "tauri-plugin-push-notifications" +version = "0.1.0" +description = "Enable push notifications in your Tauri app." +edition = { workspace = true } +authors = { workspace = true } +license = { workspace = true } +rust-version = { workspace = true } +repository = { workspace = true } +exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"] +links = "tauri-plugin-push-notifications" + +[package.metadata.docs.rs] +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] + +[package.metadata.platforms.support] +linux = { level = "none", notes = "No push functionality available" } +windows = { level = "partial", notes = "Experimental" } +macos = { level = "full", notes = "" } +android = { level = "full", notes = "" } +ios = { level = "full", notes = "" } + +[dependencies] +tauri = { workspace = true, features = ["push-notifications"] } +serde = { workspace = true } +serde_json = { workspace = true } +thiserror = { workspace = true } +base64 = "^0" + +[build-dependencies] +tauri-plugin = { version = "^2", features = ["build"] } +schemars = { workspace = true } +serde = { workspace = true } + +[patch.crates-io] +tauri = { path = "/workspace/tauri/crates/tauri" } +tauri-plugin = { path = "/workspace/tauri/crates/tauri-plugin" } +tao = { path = "/workspace/tao" } diff --git a/plugins/push-notifications/README.md b/plugins/push-notifications/README.md new file mode 100644 index 000000000..a2e7e488d --- /dev/null +++ b/plugins/push-notifications/README.md @@ -0,0 +1,4 @@ +# Tauri Plugin push-notifications + +Coming soon. + diff --git a/plugins/push-notifications/build.rs b/plugins/push-notifications/build.rs new file mode 100644 index 000000000..9b6d5c3ab --- /dev/null +++ b/plugins/push-notifications/build.rs @@ -0,0 +1,8 @@ +const COMMANDS: &[&str] = &["push_token"]; + +fn main() { + tauri_plugin::Builder::new(COMMANDS) + .android_path("android") + .ios_path("ios") + .build(); +} diff --git a/plugins/push-notifications/guest-js/index.ts b/plugins/push-notifications/guest-js/index.ts new file mode 100644 index 000000000..62fecc94d --- /dev/null +++ b/plugins/push-notifications/guest-js/index.ts @@ -0,0 +1,12 @@ +import { invoke } from "@tauri-apps/api/core" + +export type PushTokenResponse = { + value?: string; +} + +export async function pushToken(): Promise { + return await invoke<{value?: string}>('plugin:push-notifications|push_token', { + payload: {}, + }).then((r: PushTokenResponse) => (r.value ? r.value : null)); +} + \ No newline at end of file diff --git a/plugins/push-notifications/package.json b/plugins/push-notifications/package.json new file mode 100644 index 000000000..1a536bf70 --- /dev/null +++ b/plugins/push-notifications/package.json @@ -0,0 +1,33 @@ +{ + "name": "tauri-plugin-push-notifications", + "version": "0.1.0", + "author": "Sam Gammon ", + "description": "Tauri plugin for push notifications (APNS, FCM, etc)", + "type": "module", + "types": "./dist-js/index.d.ts", + "main": "./dist-js/index.cjs", + "module": "./dist-js/index.js", + "exports": { + "types": "./dist-js/index.d.ts", + "import": "./dist-js/index.js", + "require": "./dist-js/index.cjs" + }, + "files": [ + "dist-js", + "README.md" + ], + "scripts": { + "build": "rollup -c", + "prepublishOnly": "pnpm build", + "pretest": "pnpm build" + }, + "dependencies": { + "@tauri-apps/api": ">=2.0.0-beta.6" + }, + "devDependencies": { + "@rollup/plugin-typescript": "^11.1.6", + "rollup": "^4.9.6", + "typescript": "^5.3.3", + "tslib": "^2.6.2" + } +} diff --git a/plugins/push-notifications/permissions/autogenerated/commands/push_token.toml b/plugins/push-notifications/permissions/autogenerated/commands/push_token.toml new file mode 100644 index 000000000..25625c7b0 --- /dev/null +++ b/plugins/push-notifications/permissions/autogenerated/commands/push_token.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-push-token" +description = "Enables the push_token command without any pre-configured scope." +commands.allow = ["push_token"] + +[[permission]] +identifier = "deny-push-token" +description = "Denies the push_token command without any pre-configured scope." +commands.deny = ["push_token"] diff --git a/plugins/push-notifications/permissions/autogenerated/reference.md b/plugins/push-notifications/permissions/autogenerated/reference.md new file mode 100644 index 000000000..d897c3617 --- /dev/null +++ b/plugins/push-notifications/permissions/autogenerated/reference.md @@ -0,0 +1,41 @@ +## Default Permission + +Default permissions for the plugin + +- `allow-push-token` + +## Permission Table + + + + + + + + + + + + + + + + + +
IdentifierDescription
+ +`push-notifications:allow-push-token` + + + +Enables the push_token command without any pre-configured scope. + +
+ +`push-notifications:deny-push-token` + + + +Denies the push_token command without any pre-configured scope. + +
diff --git a/plugins/push-notifications/permissions/default.toml b/plugins/push-notifications/permissions/default.toml new file mode 100644 index 000000000..e8156c7a0 --- /dev/null +++ b/plugins/push-notifications/permissions/default.toml @@ -0,0 +1,3 @@ +[default] +description = "Default permissions for the plugin" +permissions = ["allow-push-token"] diff --git a/plugins/push-notifications/permissions/schemas/schema.json b/plugins/push-notifications/permissions/schemas/schema.json new file mode 100644 index 000000000..dc719f3df --- /dev/null +++ b/plugins/push-notifications/permissions/schemas/schema.json @@ -0,0 +1,315 @@ +{ + "$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 push_token command without any pre-configured scope.", + "type": "string", + "const": "allow-push-token" + }, + { + "description": "Denies the push_token command without any pre-configured scope.", + "type": "string", + "const": "deny-push-token" + }, + { + "description": "Default permissions for the plugin", + "type": "string", + "const": "default" + } + ] + } + } +} \ No newline at end of file diff --git a/plugins/push-notifications/pnpm-lock.yaml b/plugins/push-notifications/pnpm-lock.yaml new file mode 100644 index 000000000..de4be1301 --- /dev/null +++ b/plugins/push-notifications/pnpm-lock.yaml @@ -0,0 +1,325 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@tauri-apps/api': + specifier: '>=2.0.0-beta.6' + version: 2.1.1 + devDependencies: + '@rollup/plugin-typescript': + specifier: ^11.1.6 + version: 11.1.6(rollup@4.25.0)(tslib@2.8.1)(typescript@5.6.3) + rollup: + specifier: ^4.9.6 + version: 4.25.0 + tslib: + specifier: ^2.6.2 + version: 2.8.1 + typescript: + specifier: ^5.3.3 + version: 5.6.3 + +packages: + + '@rollup/plugin-typescript@11.1.6': + resolution: {integrity: sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==, tarball: https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.14.0||^3.0.0||^4.0.0 + tslib: '*' + typescript: '>=3.7.0' + peerDependenciesMeta: + rollup: + optional: true + tslib: + optional: true + + '@rollup/pluginutils@5.1.3': + resolution: {integrity: sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==, tarball: https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.3.tgz} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + + '@rollup/rollup-android-arm-eabi@4.25.0': + resolution: {integrity: sha512-CC/ZqFZwlAIbU1wUPisHyV/XRc5RydFrNLtgl3dGYskdwPZdt4HERtKm50a/+DtTlKeCq9IXFEWR+P6blwjqBA==, tarball: https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.25.0.tgz} + cpu: [arm] + os: [android] + + '@rollup/rollup-android-arm64@4.25.0': + resolution: {integrity: sha512-/Y76tmLGUJqVBXXCfVS8Q8FJqYGhgH4wl4qTA24E9v/IJM0XvJCGQVSW1QZ4J+VURO9h8YCa28sTFacZXwK7Rg==, tarball: https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.25.0.tgz} + cpu: [arm64] + os: [android] + + '@rollup/rollup-darwin-arm64@4.25.0': + resolution: {integrity: sha512-YVT6L3UrKTlC0FpCZd0MGA7NVdp7YNaEqkENbWQ7AOVOqd/7VzyHpgIpc1mIaxRAo1ZsJRH45fq8j4N63I/vvg==, tarball: https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.25.0.tgz} + cpu: [arm64] + os: [darwin] + + '@rollup/rollup-darwin-x64@4.25.0': + resolution: {integrity: sha512-ZRL+gexs3+ZmmWmGKEU43Bdn67kWnMeWXLFhcVv5Un8FQcx38yulHBA7XR2+KQdYIOtD0yZDWBCudmfj6lQJoA==, tarball: https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.25.0.tgz} + cpu: [x64] + os: [darwin] + + '@rollup/rollup-freebsd-arm64@4.25.0': + resolution: {integrity: sha512-xpEIXhiP27EAylEpreCozozsxWQ2TJbOLSivGfXhU4G1TBVEYtUPi2pOZBnvGXHyOdLAUUhPnJzH3ah5cqF01g==, tarball: https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.25.0.tgz} + cpu: [arm64] + os: [freebsd] + + '@rollup/rollup-freebsd-x64@4.25.0': + resolution: {integrity: sha512-sC5FsmZGlJv5dOcURrsnIK7ngc3Kirnx3as2XU9uER+zjfyqIjdcMVgzy4cOawhsssqzoAX19qmxgJ8a14Qrqw==, tarball: https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.25.0.tgz} + cpu: [x64] + os: [freebsd] + + '@rollup/rollup-linux-arm-gnueabihf@4.25.0': + resolution: {integrity: sha512-uD/dbLSs1BEPzg564TpRAQ/YvTnCds2XxyOndAO8nJhaQcqQGFgv/DAVko/ZHap3boCvxnzYMa3mTkV/B/3SWA==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.25.0.tgz} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm-musleabihf@4.25.0': + resolution: {integrity: sha512-ZVt/XkrDlQWegDWrwyC3l0OfAF7yeJUF4fq5RMS07YM72BlSfn2fQQ6lPyBNjt+YbczMguPiJoCfaQC2dnflpQ==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.25.0.tgz} + cpu: [arm] + os: [linux] + + '@rollup/rollup-linux-arm64-gnu@4.25.0': + resolution: {integrity: sha512-qboZ+T0gHAW2kkSDPHxu7quaFaaBlynODXpBVnPxUgvWYaE84xgCKAPEYE+fSMd3Zv5PyFZR+L0tCdYCMAtG0A==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.25.0.tgz} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-arm64-musl@4.25.0': + resolution: {integrity: sha512-ndWTSEmAaKr88dBuogGH2NZaxe7u2rDoArsejNslugHZ+r44NfWiwjzizVS1nUOHo+n1Z6qV3X60rqE/HlISgw==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.25.0.tgz} + cpu: [arm64] + os: [linux] + + '@rollup/rollup-linux-powerpc64le-gnu@4.25.0': + resolution: {integrity: sha512-BVSQvVa2v5hKwJSy6X7W1fjDex6yZnNKy3Kx1JGimccHft6HV0THTwNtC2zawtNXKUu+S5CjXslilYdKBAadzA==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.25.0.tgz} + cpu: [ppc64] + os: [linux] + + '@rollup/rollup-linux-riscv64-gnu@4.25.0': + resolution: {integrity: sha512-G4hTREQrIdeV0PE2JruzI+vXdRnaK1pg64hemHq2v5fhv8C7WjVaeXc9P5i4Q5UC06d/L+zA0mszYIKl+wY8oA==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.25.0.tgz} + cpu: [riscv64] + os: [linux] + + '@rollup/rollup-linux-s390x-gnu@4.25.0': + resolution: {integrity: sha512-9T/w0kQ+upxdkFL9zPVB6zy9vWW1deA3g8IauJxojN4bnz5FwSsUAD034KpXIVX5j5p/rn6XqumBMxfRkcHapQ==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.25.0.tgz} + cpu: [s390x] + os: [linux] + + '@rollup/rollup-linux-x64-gnu@4.25.0': + resolution: {integrity: sha512-ThcnU0EcMDn+J4B9LD++OgBYxZusuA7iemIIiz5yzEcFg04VZFzdFjuwPdlURmYPZw+fgVrFzj4CA64jSTG4Ig==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.25.0.tgz} + cpu: [x64] + os: [linux] + + '@rollup/rollup-linux-x64-musl@4.25.0': + resolution: {integrity: sha512-zx71aY2oQxGxAT1JShfhNG79PnjYhMC6voAjzpu/xmMjDnKNf6Nl/xv7YaB/9SIa9jDYf8RBPWEnjcdlhlv1rQ==, tarball: https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.25.0.tgz} + cpu: [x64] + os: [linux] + + '@rollup/rollup-win32-arm64-msvc@4.25.0': + resolution: {integrity: sha512-JT8tcjNocMs4CylWY/CxVLnv8e1lE7ff1fi6kbGocWwxDq9pj30IJ28Peb+Y8yiPNSF28oad42ApJB8oUkwGww==, tarball: https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.25.0.tgz} + cpu: [arm64] + os: [win32] + + '@rollup/rollup-win32-ia32-msvc@4.25.0': + resolution: {integrity: sha512-dRLjLsO3dNOfSN6tjyVlG+Msm4IiZnGkuZ7G5NmpzwF9oOc582FZG05+UdfTbz5Jd4buK/wMb6UeHFhG18+OEg==, tarball: https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.25.0.tgz} + cpu: [ia32] + os: [win32] + + '@rollup/rollup-win32-x64-msvc@4.25.0': + resolution: {integrity: sha512-/RqrIFtLB926frMhZD0a5oDa4eFIbyNEwLLloMTEjmqfwZWXywwVVOVmwTsuyhC9HKkVEZcOOi+KV4U9wmOdlg==, tarball: https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.25.0.tgz} + cpu: [x64] + os: [win32] + + '@tauri-apps/api@2.1.1': + resolution: {integrity: sha512-fzUfFFKo4lknXGJq8qrCidkUcKcH2UHhfaaCNt4GzgzGaW2iS26uFOg4tS3H4P8D6ZEeUxtiD5z0nwFF0UN30A==, tarball: https://registry.npmjs.org/@tauri-apps/api/-/api-2.1.1.tgz} + + '@types/estree@1.0.6': + resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==, tarball: https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz} + + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==, tarball: https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz} + + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==, tarball: https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + + function-bind@1.1.2: + resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==, tarball: https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz} + + hasown@2.0.2: + resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==, tarball: https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz} + engines: {node: '>= 0.4'} + + is-core-module@2.15.1: + resolution: {integrity: sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==, tarball: https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz} + engines: {node: '>= 0.4'} + + path-parse@1.0.7: + resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==, tarball: https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz} + + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==, tarball: https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz} + engines: {node: '>=12'} + + resolve@1.22.8: + resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==, tarball: https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz} + hasBin: true + + rollup@4.25.0: + resolution: {integrity: sha512-uVbClXmR6wvx5R1M3Od4utyLUxrmOcEm3pAtMphn73Apq19PDtHpgZoEvqH2YnnaNUuvKmg2DgRd2Sqv+odyqg==, tarball: https://registry.npmjs.org/rollup/-/rollup-4.25.0.tgz} + engines: {node: '>=18.0.0', npm: '>=8.0.0'} + hasBin: true + + supports-preserve-symlinks-flag@1.0.0: + resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==, tarball: https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz} + engines: {node: '>= 0.4'} + + tslib@2.8.1: + resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==, tarball: https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz} + + typescript@5.6.3: + resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==, tarball: https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz} + engines: {node: '>=14.17'} + hasBin: true + +snapshots: + + '@rollup/plugin-typescript@11.1.6(rollup@4.25.0)(tslib@2.8.1)(typescript@5.6.3)': + dependencies: + '@rollup/pluginutils': 5.1.3(rollup@4.25.0) + resolve: 1.22.8 + typescript: 5.6.3 + optionalDependencies: + rollup: 4.25.0 + tslib: 2.8.1 + + '@rollup/pluginutils@5.1.3(rollup@4.25.0)': + dependencies: + '@types/estree': 1.0.6 + estree-walker: 2.0.2 + picomatch: 4.0.2 + optionalDependencies: + rollup: 4.25.0 + + '@rollup/rollup-android-arm-eabi@4.25.0': + optional: true + + '@rollup/rollup-android-arm64@4.25.0': + optional: true + + '@rollup/rollup-darwin-arm64@4.25.0': + optional: true + + '@rollup/rollup-darwin-x64@4.25.0': + optional: true + + '@rollup/rollup-freebsd-arm64@4.25.0': + optional: true + + '@rollup/rollup-freebsd-x64@4.25.0': + optional: true + + '@rollup/rollup-linux-arm-gnueabihf@4.25.0': + optional: true + + '@rollup/rollup-linux-arm-musleabihf@4.25.0': + optional: true + + '@rollup/rollup-linux-arm64-gnu@4.25.0': + optional: true + + '@rollup/rollup-linux-arm64-musl@4.25.0': + optional: true + + '@rollup/rollup-linux-powerpc64le-gnu@4.25.0': + optional: true + + '@rollup/rollup-linux-riscv64-gnu@4.25.0': + optional: true + + '@rollup/rollup-linux-s390x-gnu@4.25.0': + optional: true + + '@rollup/rollup-linux-x64-gnu@4.25.0': + optional: true + + '@rollup/rollup-linux-x64-musl@4.25.0': + optional: true + + '@rollup/rollup-win32-arm64-msvc@4.25.0': + optional: true + + '@rollup/rollup-win32-ia32-msvc@4.25.0': + optional: true + + '@rollup/rollup-win32-x64-msvc@4.25.0': + optional: true + + '@tauri-apps/api@2.1.1': {} + + '@types/estree@1.0.6': {} + + estree-walker@2.0.2: {} + + fsevents@2.3.3: + optional: true + + function-bind@1.1.2: {} + + hasown@2.0.2: + dependencies: + function-bind: 1.1.2 + + is-core-module@2.15.1: + dependencies: + hasown: 2.0.2 + + path-parse@1.0.7: {} + + picomatch@4.0.2: {} + + resolve@1.22.8: + dependencies: + is-core-module: 2.15.1 + path-parse: 1.0.7 + supports-preserve-symlinks-flag: 1.0.0 + + rollup@4.25.0: + dependencies: + '@types/estree': 1.0.6 + optionalDependencies: + '@rollup/rollup-android-arm-eabi': 4.25.0 + '@rollup/rollup-android-arm64': 4.25.0 + '@rollup/rollup-darwin-arm64': 4.25.0 + '@rollup/rollup-darwin-x64': 4.25.0 + '@rollup/rollup-freebsd-arm64': 4.25.0 + '@rollup/rollup-freebsd-x64': 4.25.0 + '@rollup/rollup-linux-arm-gnueabihf': 4.25.0 + '@rollup/rollup-linux-arm-musleabihf': 4.25.0 + '@rollup/rollup-linux-arm64-gnu': 4.25.0 + '@rollup/rollup-linux-arm64-musl': 4.25.0 + '@rollup/rollup-linux-powerpc64le-gnu': 4.25.0 + '@rollup/rollup-linux-riscv64-gnu': 4.25.0 + '@rollup/rollup-linux-s390x-gnu': 4.25.0 + '@rollup/rollup-linux-x64-gnu': 4.25.0 + '@rollup/rollup-linux-x64-musl': 4.25.0 + '@rollup/rollup-win32-arm64-msvc': 4.25.0 + '@rollup/rollup-win32-ia32-msvc': 4.25.0 + '@rollup/rollup-win32-x64-msvc': 4.25.0 + fsevents: 2.3.3 + + supports-preserve-symlinks-flag@1.0.0: {} + + tslib@2.8.1: {} + + typescript@5.6.3: {} diff --git a/plugins/push-notifications/rollup.config.js b/plugins/push-notifications/rollup.config.js new file mode 100644 index 000000000..d83436352 --- /dev/null +++ b/plugins/push-notifications/rollup.config.js @@ -0,0 +1,31 @@ +import { readFileSync } from 'fs' +import { join } from 'path' +import { cwd } from 'process' +import typescript from '@rollup/plugin-typescript' + +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'), 'utf8')) + +export default { + input: 'guest-js/index.ts', + output: [ + { + file: pkg.exports.import, + format: 'esm' + }, + { + file: pkg.exports.require, + format: 'cjs' + } + ], + plugins: [ + typescript({ + declaration: true, + declarationDir: `./${pkg.exports.import.split('/')[0]}` + }) + ], + external: [ + /^@tauri-apps\/api/, + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}) + ] +} diff --git a/plugins/push-notifications/src/commands.rs b/plugins/push-notifications/src/commands.rs new file mode 100644 index 000000000..b3073ae2a --- /dev/null +++ b/plugins/push-notifications/src/commands.rs @@ -0,0 +1,14 @@ +use std::sync::Mutex; +use tauri::{command, AppHandle, Manager, Runtime}; + +use crate::models::*; +use crate::PushNotificationsExt; +use crate::{PushTokenState, Result}; + +#[command] +pub(crate) async fn push_token(app: AppHandle) -> Result { + let state = app.state::>(); + + app.push_notifications() + .get_push_token(state, PushTokenRequest {}) +} diff --git a/plugins/push-notifications/src/desktop.rs b/plugins/push-notifications/src/desktop.rs new file mode 100644 index 000000000..894c7c8a6 --- /dev/null +++ b/plugins/push-notifications/src/desktop.rs @@ -0,0 +1,37 @@ +use base64::{engine::general_purpose, Engine as _}; +use serde::de::DeserializeOwned; +use std::sync::Mutex; +use tauri::{plugin::PluginApi, AppHandle, Runtime, State}; + +use crate::models::*; +use crate::PushTokenState; + +pub fn init( + app: &AppHandle, + _api: PluginApi, +) -> crate::Result> { + Ok(PushNotifications(app.clone())) +} + +/// Access to the push-notifications APIs. +pub struct PushNotifications(AppHandle); + +impl PushNotifications { + pub fn get_push_token( + &self, + state: State>, + _payload: PushTokenRequest, + ) -> crate::Result { + let state = state.lock().unwrap(); + + match &state.token { + Some(token) => { + let encoded = general_purpose::STANDARD.encode(&token); + Ok(PushTokenResponse { + value: Some(encoded.clone()), + }) + } + None => Ok(PushTokenResponse { value: None }), + } + } +} diff --git a/plugins/push-notifications/src/error.rs b/plugins/push-notifications/src/error.rs new file mode 100644 index 000000000..177e8c268 --- /dev/null +++ b/plugins/push-notifications/src/error.rs @@ -0,0 +1,21 @@ +use serde::{ser::Serializer, Serialize}; + +pub type Result = std::result::Result; + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error(transparent)] + Io(#[from] std::io::Error), + #[cfg(mobile)] + #[error(transparent)] + PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError), +} + +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/push-notifications/src/lib.rs b/plugins/push-notifications/src/lib.rs new file mode 100644 index 000000000..d84ed97e7 --- /dev/null +++ b/plugins/push-notifications/src/lib.rs @@ -0,0 +1,82 @@ +use tauri::{ + plugin::{Builder, TauriPlugin}, + Manager, RunEvent, Runtime, +}; + +pub use models::*; +use std::{collections::HashMap, sync::Mutex}; + +#[cfg(desktop)] +mod desktop; +#[cfg(mobile)] +mod mobile; + +mod commands; +mod error; +mod models; + +pub use error::{Error, Result}; + +#[cfg(desktop)] +use desktop::PushNotifications; +#[cfg(mobile)] +use mobile::PushNotifications; + +/// Structure of push token state managed by the plugin. +#[derive(Default, Clone)] +pub struct PushTokenState { + token: Option>, + err: Option, +} + +/// Persistent push token store. +struct PushTokenStore(Mutex>); + +/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the push-notifications APIs. +pub trait PushNotificationsExt { + fn push_notifications(&self) -> &PushNotifications; +} + +impl> PushNotificationsExt for T { + fn push_notifications(&self) -> &PushNotifications { + self.state::>().inner() + } +} + +/// Initializes the plugin. +pub fn init() -> TauriPlugin { + Builder::new("push-notifications") + .invoke_handler(tauri::generate_handler![commands::push_token]) + .setup(|app, api| { + // setup push token storage + app.manage(PushTokenStore(Default::default())); + app.manage(Mutex::new(PushTokenState::default())); + #[cfg(mobile)] + let push_notifications = mobile::init(app, api)?; + #[cfg(desktop)] + let push_notifications = desktop::init(app, api)?; + app.manage(push_notifications); + Ok(()) + }) + .on_event(|app, event| { + match event { + RunEvent::PushRegistration(token) => { + let state = app.state::>(); + let mut state = state.lock().unwrap(); + let owned = token.to_owned(); + state.token = Some(owned); + } + + RunEvent::PushRegistrationFailed(err) => { + let state = app.state::>(); + let mut state = state.lock().unwrap(); + let owned = err.to_owned(); + state.err = Some(owned); + } + + // @TODO: token persistence? + _ => {} + } + }) + .build() +} diff --git a/plugins/push-notifications/src/mobile.rs b/plugins/push-notifications/src/mobile.rs new file mode 100644 index 000000000..0d63b4658 --- /dev/null +++ b/plugins/push-notifications/src/mobile.rs @@ -0,0 +1,47 @@ +use base64::{engine::general_purpose, Engine as _}; +use serde::de::DeserializeOwned; +use std::sync::Mutex; +use tauri::{ + plugin::{PluginApi, PluginHandle}, + AppHandle, Runtime, State, +}; + +use crate::models::*; +use crate::PushTokenState; + +#[cfg(target_os = "ios")] +tauri::ios_plugin_binding!(init_plugin_push_notifications); + +// initializes the Kotlin or Swift plugin classes +pub fn init( + _app: &AppHandle, + api: PluginApi, +) -> crate::Result> { + #[cfg(target_os = "android")] + let handle = api.register_android_plugin("", "PushNotificationsPlugin")?; + #[cfg(target_os = "ios")] + let handle = api.register_ios_plugin(init_plugin_push_notifications)?; + Ok(PushNotifications(handle)) +} + +/// Access to the push-notifications APIs. +pub struct PushNotifications(PluginHandle); + +impl PushNotifications { + pub fn get_push_token( + &self, + state: State>, + _payload: PushTokenRequest, + ) -> crate::Result { + let state = state.lock().unwrap(); + match &state.token { + Some(token) => { + let encoded = general_purpose::STANDARD.encode(&token); + Ok(PushTokenResponse { + value: Some(encoded.clone()), + }) + } + None => Ok(PushTokenResponse { value: None }), + } + } +} diff --git a/plugins/push-notifications/src/models.rs b/plugins/push-notifications/src/models.rs new file mode 100644 index 000000000..38734fb80 --- /dev/null +++ b/plugins/push-notifications/src/models.rs @@ -0,0 +1,13 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PushTokenRequest { + // Nothing at this time. +} + +#[derive(Debug, Clone, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PushTokenResponse { + pub value: Option, +} diff --git a/plugins/push-notifications/tsconfig.json b/plugins/push-notifications/tsconfig.json new file mode 100644 index 000000000..059112270 --- /dev/null +++ b/plugins/push-notifications/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "es2021", + "module": "esnext", + "moduleResolution": "bundler", + "skipLibCheck": true, + "strict": true, + "noUnusedLocals": true, + "noImplicitAny": true, + "noEmit": true + }, + "include": ["guest-js/*.ts"], + "exclude": ["dist-js", "node_modules"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8b81b751..edf332abc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -267,6 +267,25 @@ importers: specifier: ^2.0.0 version: 2.1.1 + plugins/push-notifications: + dependencies: + '@tauri-apps/api': + specifier: '>=2.0.0-beta.6' + version: 2.1.1 + devDependencies: + '@rollup/plugin-typescript': + specifier: ^11.1.6 + version: 11.1.6(rollup@4.27.2)(tslib@2.8.1)(typescript@5.6.3) + rollup: + specifier: ^4.9.6 + version: 4.27.2 + tslib: + specifier: ^2.6.2 + version: 2.8.1 + typescript: + specifier: ^5.3.3 + version: 5.6.3 + plugins/shell: dependencies: '@tauri-apps/api': @@ -2424,9 +2443,9 @@ snapshots: - encoding - mocha - '@covector/assemble@0.12.0': + '@covector/assemble@0.12.0(mocha@10.7.3)': dependencies: - '@covector/command': 0.8.0 + '@covector/command': 0.8.0(mocha@10.7.3) '@covector/files': 0.8.0 effection: 2.0.8(mocha@10.7.3) js-yaml: 4.1.0 @@ -2437,9 +2456,10 @@ snapshots: unified: 9.2.2 transitivePeerDependencies: - encoding + - mocha - supports-color - '@covector/changelog@0.12.0': + '@covector/changelog@0.12.0(mocha@10.7.3)': dependencies: '@covector/files': 0.8.0 effection: 2.0.8(mocha@10.7.3) @@ -2449,14 +2469,16 @@ snapshots: unified: 9.2.2 transitivePeerDependencies: - encoding + - mocha - supports-color - '@covector/command@0.8.0': + '@covector/command@0.8.0(mocha@10.7.3)': dependencies: - '@effection/process': 2.1.4 + '@effection/process': 2.1.4(mocha@10.7.3) effection: 2.0.8(mocha@10.7.3) transitivePeerDependencies: - encoding + - mocha '@covector/files@0.8.0': dependencies: @@ -2503,10 +2525,8 @@ snapshots: dependencies: effection: 2.0.8(mocha@10.7.3) mocha: 10.7.3 - transitivePeerDependencies: - - encoding - '@effection/process@2.1.4': + '@effection/process@2.1.4(mocha@10.7.3)': dependencies: cross-spawn: 7.0.3 ctrlc-windows: 2.1.0 @@ -2514,6 +2534,7 @@ snapshots: shellwords: 0.1.1 transitivePeerDependencies: - encoding + - mocha '@effection/stream@2.0.6': dependencies: @@ -3384,9 +3405,9 @@ snapshots: dependencies: '@clack/prompts': 0.7.0 '@covector/apply': 0.10.0(mocha@10.7.3) - '@covector/assemble': 0.12.0 - '@covector/changelog': 0.12.0 - '@covector/command': 0.8.0 + '@covector/assemble': 0.12.0(mocha@10.7.3) + '@covector/changelog': 0.12.0(mocha@10.7.3) + '@covector/command': 0.8.0(mocha@10.7.3) '@covector/files': 0.8.0 effection: 2.0.8(mocha@10.7.3) globby: 11.1.0