working app and docs
24
moxie-app/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
moxie-app/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
|
||||
}
|
||||
7
moxie-app/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Tauri + Vanilla
|
||||
|
||||
This template should help get you started developing with Tauri in vanilla HTML, CSS and Javascript.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
||||
232
moxie-app/package-lock.json
generated
Normal file
@ -0,0 +1,232 @@
|
||||
{
|
||||
"name": "moxie-app",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "moxie-app",
|
||||
"version": "0.1.0",
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^2"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.11.2.tgz",
|
||||
"integrity": "sha512-bk3HemqvGRoy+5D/dVMUQHKMYLglD0jVnMm/0iGMH6ufZ+p8r14m6BpIixwij3PBvZdvORUp1YifTD8QxVZ1Nw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"bin": {
|
||||
"tauri": "tauri.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/tauri"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@tauri-apps/cli-darwin-arm64": "2.11.2",
|
||||
"@tauri-apps/cli-darwin-x64": "2.11.2",
|
||||
"@tauri-apps/cli-linux-arm-gnueabihf": "2.11.2",
|
||||
"@tauri-apps/cli-linux-arm64-gnu": "2.11.2",
|
||||
"@tauri-apps/cli-linux-arm64-musl": "2.11.2",
|
||||
"@tauri-apps/cli-linux-riscv64-gnu": "2.11.2",
|
||||
"@tauri-apps/cli-linux-x64-gnu": "2.11.2",
|
||||
"@tauri-apps/cli-linux-x64-musl": "2.11.2",
|
||||
"@tauri-apps/cli-win32-arm64-msvc": "2.11.2",
|
||||
"@tauri-apps/cli-win32-ia32-msvc": "2.11.2",
|
||||
"@tauri-apps/cli-win32-x64-msvc": "2.11.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-darwin-arm64": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.11.2.tgz",
|
||||
"integrity": "sha512-+4UZzLt+eOAEQCwgd+TqKgyUJMrvx+BgdXLLaqJYmPqzP+nE6YZr/hY6CWLYGQb8jFn99jEkmC6uA3tNvamA1w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-darwin-x64": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.11.2.tgz",
|
||||
"integrity": "sha512-VjYYtZUPqDMLutSfJEyxFE3Bz+DPi7c8wC3imckgvciLDZLq4qwKJxBicg0BXGhXjJsl8vKWgWRFNMPELQ+Xyg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm-gnueabihf": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.11.2.tgz",
|
||||
"integrity": "sha512-yMemD6f4i95AQriS8EazyOFzbE34yjnP16i3IOzpHGQvBoy2DjypFMFBq0NtPuITURv/cOGguRtHR5d79/9CSA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm64-gnu": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.11.2.tgz",
|
||||
"integrity": "sha512-cgI91D2wL8GSgoWwZXDqt+DwnuZCP2/bz03QAE4TrhgAKIsrB4hX26W/H1EONPUUNkqrsgeCD0wU6pcNjV/5kw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-arm64-musl": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.11.2.tgz",
|
||||
"integrity": "sha512-X1rm0BERqAAggtYTESSgXrS3sz4Sb/OiPiz54UqISlXW+GkR3vNIGnsy/lejNmoXGVqri3Q53BCfQiclOIyRPw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-riscv64-gnu": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.11.2.tgz",
|
||||
"integrity": "sha512-usbMLJbT3KtkOrBMDVeGYNM35aTHXx38SJSzTMSqqjeUIOQ+iVPjb2yAGNAE+KqmBbAx4FOFIyMeKXx2M/JKGQ==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-x64-gnu": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.11.2.tgz",
|
||||
"integrity": "sha512-Ru4gwJKPG0ctVGchRGpRup4Y4lW2SSfFnrbQcyHhCliKy4g8Qz97TrUgCur4CbWyAgKxvGh3SjrkA0LDYzDGiw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-linux-x64-musl": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.11.2.tgz",
|
||||
"integrity": "sha512-eUm7T6clN1MMmNSRQ9gaWsQdyehQx2Gmn5hht/QUlqZQI/qcP2OJK5dnaxqwFzCr2HdsEo9ydxaqcS1oJzMvUw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-arm64-msvc": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.11.2.tgz",
|
||||
"integrity": "sha512-HeeZW80jU+gVTOEX4X/hC6NVSAdDVXajwP5fxIZ/3z9WvUC7qrudX2GMTilYq6Dg0e0sk0XgsAJD1hZ5wPBXUA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-ia32-msvc": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.11.2.tgz",
|
||||
"integrity": "sha512-YhjQNZcXfbkCLyazSv1nPnJ9iRFE1wm6kc51FDbU10/Dk09io+6PAGMLjkxnX2GdM0qMnDmTjstY8mTDVvtKeA==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-win32-x64-msvc": {
|
||||
"version": "2.11.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.11.2.tgz",
|
||||
"integrity": "sha512-d2JchlFIpZevZVReyqhQOekJmb1UH3rhZ5VX6sH3ty9ETE0TKQavpihvoScUXfKKpW6HZC0MrFGRU0ZtD+w3gA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
moxie-app/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "moxie-app",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"tauri": "tauri",
|
||||
"dev": "tauri dev",
|
||||
"build": "tauri build -- --no-bundle"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^2"
|
||||
}
|
||||
}
|
||||
7
moxie-app/src-tauri/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
29
moxie-app/src-tauri/Cargo.toml
Normal file
@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "moxie-app"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com
|
||||
name = "moxie_app_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio-tungstenite = "0.24"
|
||||
futures-util = "0.3"
|
||||
|
||||
# 👇 Replaced the old tokio configuration with the full feature flags list
|
||||
tokio = { version = "1", features = ["net", "rt", "sync", "macros"] }
|
||||
3
moxie-app/src-tauri/build.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
16
moxie-app/src-tauri/capabilities/default.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Standard app capabilities",
|
||||
"platforms": [
|
||||
"windows",
|
||||
"macOS",
|
||||
"linux"
|
||||
],
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default"
|
||||
]
|
||||
}
|
||||
29
moxie-app/src-tauri/extWebview.js
Normal file
@ -0,0 +1,29 @@
|
||||
// src-tauri/inject.js
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('Initializing local background socket link...')
|
||||
const ws = new WebSocket('ws://127.0.0.1:8080')
|
||||
|
||||
ws.onopen = () => {
|
||||
console.log('WebSocket connected successfully!')
|
||||
const payload = {
|
||||
command: 'remote_action',
|
||||
message: 'Hello automatically from: ' + window.location.href
|
||||
}
|
||||
ws.send(JSON.stringify(payload))
|
||||
}
|
||||
|
||||
ws.onmessage = event => {
|
||||
console.log('📩 RECEIVED REPLY FROM TAURI BACKEND:', JSON.parse(event.data))
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
localsession: window.localStorage.getItem('token') || 'no-session'
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
ws.onerror = err => {
|
||||
console.error('Connection failed:', err)
|
||||
}
|
||||
|
||||
window.localAppSocket = ws
|
||||
})
|
||||
BIN
moxie-app/src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
moxie-app/src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
moxie-app/src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
moxie-app/src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
moxie-app/src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
moxie-app/src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
moxie-app/src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
moxie-app/src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
moxie-app/src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
moxie-app/src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
moxie-app/src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
moxie-app/src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
moxie-app/src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
moxie-app/src-tauri/icons/icon.icns
Normal file
BIN
moxie-app/src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
moxie-app/src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
53
moxie-app/src-tauri/src/lib.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use tauri::Manager;
|
||||
use tauri::{AppHandle, WebviewUrl, WebviewWindowBuilder};
|
||||
|
||||
// 1. Declare the new server module file 👇
|
||||
mod server;
|
||||
|
||||
#[tauri::command]
|
||||
async fn greet(app_handle: AppHandle, name: String) -> Result<String, String> {
|
||||
let window_label = "remote-target-window";
|
||||
|
||||
let target_url = match name.parse() {
|
||||
Ok(url) => WebviewUrl::External(url),
|
||||
Err(_) => {
|
||||
return Err(format!("Error: '{}' is not a valid URL format.", name));
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(existing_window) = app_handle.get_webview_window(window_label) {
|
||||
let _ = existing_window.set_focus();
|
||||
return Ok(format!("Focused existing window for {}", name));
|
||||
}
|
||||
|
||||
let app_clone = app_handle.clone();
|
||||
let url_clone = target_url.clone();
|
||||
|
||||
let script_to_inject = include_str!("../extWebview.js");
|
||||
|
||||
app_handle.run_on_main_thread(move || {
|
||||
let _new_window = WebviewWindowBuilder::new(&app_clone, window_label, url_clone)
|
||||
.title("Remote Session")
|
||||
.inner_size(1024.0, 768.0)
|
||||
.resizable(true)
|
||||
.focused(true)
|
||||
.initialization_script(script_to_inject)
|
||||
.build();
|
||||
}).map_err(|e| format!("Failed to dispatch to main thread: {}", e))?;
|
||||
|
||||
Ok(format!("Dispatched window spawn for: {}", name))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|_app| {
|
||||
// 2. Call the server function using module referencing 👇
|
||||
tauri::async_runtime::spawn(server::start_websocket_server());
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
6
moxie-app/src-tauri/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
moxie_app_lib::run()
|
||||
}
|
||||
57
moxie-app/src-tauri/src/server.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_tungstenite::accept_async;
|
||||
use futures_util::stream::StreamExt;
|
||||
use futures_util::sink::SinkExt;
|
||||
use tokio::sync::broadcast; // 1. Bring Tokio's broadcast module into scope
|
||||
|
||||
pub async fn start_websocket_server() {
|
||||
let listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
|
||||
println!("Bypassed IPC Bridge: Listening for remote commands on ws://127.0.0.1:8080");
|
||||
|
||||
// 2. Create a broadcast channel that holds up to 16 messages in the queue
|
||||
let (tx, _rx) = broadcast::channel::<String>(16);
|
||||
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
// Clone the transmitter handle for this specific client connection task
|
||||
let tx = tx.clone();
|
||||
// Create a dedicated receiver handle for this client connection task
|
||||
let mut rx = tx.subscribe();
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
if let Ok(ws_stream) = accept_async(stream).await {
|
||||
let (mut ws_sender, mut ws_receiver) = ws_stream.split();
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
// Branch A: Listen for incoming text sent FROM this specific web view client
|
||||
incoming_msg = ws_receiver.next() => {
|
||||
match incoming_msg {
|
||||
Some(Ok(msg)) => {
|
||||
if msg.is_text() {
|
||||
let text = msg.to_text().unwrap().to_string();
|
||||
println!("⚡ Routing cross-window message: {}", text);
|
||||
|
||||
// Broadcast this message out to ALL connected windows
|
||||
let _ = tx.send(text);
|
||||
}
|
||||
}
|
||||
_ => break, // Disconnection or error handled cleanly
|
||||
}
|
||||
}
|
||||
// Branch B: Listen for broadcast messages pushed from OTHER windows via Rust
|
||||
broadcast_msg = rx.recv() => {
|
||||
if let Ok(text_payload) = broadcast_msg {
|
||||
// Push the broadcasted packet down to this window's browser console
|
||||
let msg_frame = tokio_tungstenite::tungstenite::Message::Text(text_payload.into());
|
||||
if let Err(e) = ws_sender.send(msg_frame).await {
|
||||
eprintln!("Failed to relay data down the socket: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
33
moxie-app/src-tauri/tauri.conf.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"$schema": "https://tauri.app",
|
||||
"productName": "moxie-app",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.dev.moxie-app",
|
||||
"build": {
|
||||
"frontendDist": "../src"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"title": "moxie-app",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": false,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
1
moxie-app/src/assets/javascript.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>
|
||||
|
After Width: | Height: | Size: 995 B |
6
moxie-app/src/assets/tauri.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
36
moxie-app/src/index.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri App</title>
|
||||
<script type="module" src="/main.js" defer></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container">
|
||||
<h1>Welcome to Tauri</h1>
|
||||
<h2 id="sh"> </h2>
|
||||
|
||||
<div class="row">
|
||||
<a href="https://tauri.app" target="_blank">
|
||||
<img src="/assets/tauri.svg" class="logo tauri" alt="Tauri logo" />
|
||||
</a>
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
|
||||
<img src="/assets/javascript.svg" class="logo vanilla" alt="JavaScript logo" />
|
||||
</a>
|
||||
</div>
|
||||
<p>Click on the Tauri logo to learn more about the framework</p>
|
||||
|
||||
<form class="row" id="greet-form">
|
||||
<input id="greet-input" placeholder="Enter a name..." />
|
||||
<button type="button" id="wstest">hay hello</button>
|
||||
<button type="submit">Greet</button>
|
||||
</form>
|
||||
<p id="greet-msg"></p>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
41
moxie-app/src/main.js
Normal file
@ -0,0 +1,41 @@
|
||||
const { invoke } = window.__TAURI__.core
|
||||
|
||||
let greetInputEl
|
||||
let greetMsgEl
|
||||
|
||||
async function greet () {
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
greetMsgEl.textContent = await invoke('greet', { name: greetInputEl.value })
|
||||
}
|
||||
const mainSocket = new WebSocket('ws://127.0.0.1:8080')
|
||||
|
||||
mainSocket.onopen = ms => {
|
||||
console.log('Main Control Window connected to the broadcast hub!')
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
greetInputEl = document.querySelector('#greet-input')
|
||||
greetMsgEl = document.querySelector('#greet-msg')
|
||||
document.querySelector('#greet-form').addEventListener('submit', e => {
|
||||
e.preventDefault()
|
||||
greet()
|
||||
})
|
||||
document.querySelector('#wstest').addEventListener('click', () => {
|
||||
const payload = {
|
||||
sender: 'local-app-main',
|
||||
content: 'hi from the webview! 1'
|
||||
}
|
||||
|
||||
// Ship the data packets straight into the Rust loop
|
||||
mainSocket.send(JSON.stringify(payload))
|
||||
})
|
||||
})
|
||||
|
||||
mainSocket.onmessage = event => {
|
||||
const msgs = JSON.parse(event.data)
|
||||
console.log(msgs.type)
|
||||
if (msgs.localsession) {
|
||||
const shEl = document.querySelector('#sh')
|
||||
shEl.textContent = `Session Hash: ${msgs.localsession}`
|
||||
}
|
||||
}
|
||||
112
moxie-app/src/styles.css
Normal file
@ -0,0 +1,112 @@
|
||||
.logo.vanilla:hover {
|
||||
filter: drop-shadow(0 0 2em #ffe21c);
|
||||
}
|
||||
:root {
|
||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
|
||||
color: #0f0f0f;
|
||||
background-color: #f6f6f6;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 0;
|
||||
padding-top: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: 0.75s;
|
||||
}
|
||||
|
||||
.logo.tauri:hover {
|
||||
filter: drop-shadow(0 0 2em #24c8db);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
color: #0f0f0f;
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.25s;
|
||||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: #396cd8;
|
||||
}
|
||||
button:active {
|
||||
border-color: #396cd8;
|
||||
background-color: #e8e8e8;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#greet-input {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color: #f6f6f6;
|
||||
background-color: #2f2f2f;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #24c8db;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f98;
|
||||
}
|
||||
button:active {
|
||||
background-color: #0f0f0f69;
|
||||
}
|
||||
}
|
||||
284
tauri2-docs/cheatsheet.md
Normal file
@ -0,0 +1,284 @@
|
||||
# 🚀 Tauri 2.0 Definitive Cheat Sheet
|
||||
|
||||
**Tauri 2.0** features a complete architecture overhaul centered around mobile support (iOS/Android), modularized core plugins, and a strict **Access Control List (ACL)** security model. This cheat sheet covers core implementation patterns with up-to-date syntax.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Project Setup & Structure
|
||||
|
||||
Tauri 2.0 splits frontend configurations and introduces modular Rust codebases via `lib.rs`.
|
||||
|
||||
### CLI Management
|
||||
```bash
|
||||
# Initialize a new app
|
||||
npm create tauri-app@latest
|
||||
|
||||
# Run development mode (Hot-reloads UI + Rust)
|
||||
npm run tauri dev
|
||||
|
||||
# Build production artifacts
|
||||
npm run tauri build
|
||||
```
|
||||
|
||||
### File Hierarchy
|
||||
```text
|
||||
my-app/
|
||||
├── src/ # Frontend UI (React, Vue, Svelte, etc.)
|
||||
├── src-tauri/ # Backend environment
|
||||
│ ├── capabilities/ # NEW: Security capability JSON/TOML files
|
||||
│ │ └── default.json # Maps app windows to permissions
|
||||
│ ├── src/
|
||||
│ │ ├── main.rs # Minimal platform entry-point
|
||||
│ │ └── lib.rs # Core Application setup & commands
|
||||
│ ├── Cargo.toml # Rust dependencies
|
||||
│ └── tauri.conf.json # Desktop/Mobile global window configurations
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Security: The Tauri 2.0 Permission System
|
||||
|
||||
Tauri 2.0 enforces explicit privileges. Frontend access to system commands or plugins requires configuring a **Permission** inside a **Capability** map.
|
||||
|
||||
### 1. Identify Plugin Permissions
|
||||
Official plugins expose granular identifier strings:
|
||||
* **Core Permissions**: `core:path:allow-home`, `core:event:allow-listen`, `core:event:allow-emit`.
|
||||
* **Plugin Permissions**: `<plugin-name>:allow-<command>` (e.g., `http:allow-request`, `fs:allow-read`).
|
||||
|
||||
### 2. Define Capabilities (`src-tauri/capabilities/default.json`)
|
||||
Capabilities attach permissions to specific application windows.
|
||||
|
||||
```json
|
||||
{
|
||||
"\$schema": "../gen/schemas/capability.json",
|
||||
"identifier": "main-window-capability",
|
||||
"description": "Allowed permissions for the primary UI",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:path:allow-home",
|
||||
"core:event:allow-listen",
|
||||
"core:event:allow-emit",
|
||||
"fs:allow-read",
|
||||
"websocket:allow-connect",
|
||||
"websocket:allow-send"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Fine-Grained Scopes
|
||||
Scopes restrict what a plugin command can touch (e.g., locking file-system access down to a explicit directory). Define these inside your capability entries:
|
||||
|
||||
```json
|
||||
{
|
||||
"identifier": "secure-fs-scope",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
{
|
||||
"identifier": "fs:allow-write",
|
||||
"allow": [{ "path": "\$APPDATA/logs/*" }]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📡 WebSockets in Tauri 2.0
|
||||
|
||||
Tauri 2.0 approaches WebSockets from two distinct perspectives depending on requirements: utilizing the client plugin to query a external endpoint, or instantiating a native high-performance Rust WebSocket Server.
|
||||
|
||||
### Option A: The Built-in WebSocket Client Plugin
|
||||
Use this to safely initiate connections to external services from the frontend via a high-performance Rust proxy client.
|
||||
|
||||
#### 1. Setup Backend Setup (`src-tauri/src/lib.rs`)
|
||||
```rust
|
||||
// Ensure 'tauri-plugin-websocket' is added to Cargo.toml
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_websocket::init()) // Initialize client plugin
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
#### 2. Frontend Execution (`JavaScript / TypeScript`)
|
||||
Ensure `websocket:allow-connect` and `websocket:allow-send` are added to your active capability configuration.
|
||||
```typescript
|
||||
import WebSocket from '@tauri-apps/plugin-websocket';
|
||||
|
||||
// Connect to a server
|
||||
const ws = await WebSocket.connect('ws://127.0.0.1:8080');
|
||||
|
||||
// Handle incoming messages
|
||||
ws.addListener((msg) => {
|
||||
console.log('Received payload:', msg.data);
|
||||
});
|
||||
|
||||
// Push data out
|
||||
await ws.send({ type: 'Text', data: 'Hello World!' });
|
||||
|
||||
// Disconnect gracefully
|
||||
await ws.disconnect();
|
||||
```
|
||||
|
||||
### Option B: Built-in Custom Rust WebSocket Server
|
||||
If you want your Tauri application to **act as a WebSocket Server** (e.g., exposing a local port so mobile apps or local interfaces can stream data directly to your backend), spin up a Tokio-backed server thread inside the Tauri `setup` stage.
|
||||
|
||||
#### 1. Dependencies (`src-tauri/Cargo.toml`)
|
||||
```toml
|
||||
[dependencies]
|
||||
tauri = { version = "2.0", features = [] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio-tungstenite = "0.21" # Industry standard high-performance WS crate
|
||||
futures-util = "0.3"
|
||||
```
|
||||
|
||||
#### 2. Server Implementation (`src-tauri/src/lib.rs`)
|
||||
```rust
|
||||
use tauri::Manager;
|
||||
use tokio::net::TcpListener;
|
||||
use futures-util::{StreamExt, SinkExt};
|
||||
use tokio_tungstenite::accept_async;
|
||||
|
||||
async fn start_ws_server(port: &str) {
|
||||
let listener = TcpListener::bind(format!("127.0.0.1:{}", port))
|
||||
.await
|
||||
.expect("Failed to bind port");
|
||||
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
tokio::spawn(async move {
|
||||
if let Ok(mut ws_stream) = accept_async(stream).await {
|
||||
println!("New connection established to Tauri WS Server!");
|
||||
while let Some(Ok(msg)) = ws_stream.next().await {
|
||||
if msg.is_text() || msg.is_binary() {
|
||||
// Eco back received payloads
|
||||
let _ = ws_stream.send(msg).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
// Spin up native server safely in an isolated async tokio environment
|
||||
tokio::spawn(start_ws_server("8080"));
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ⚡ Inter-Process Communication (IPC) & State
|
||||
|
||||
### Commands (Invoking Rust from Frontend)
|
||||
Pass data directly via JSON-RPC structures across the isolation barrier.
|
||||
|
||||
```rust
|
||||
// src-tauri/src/lib.rs
|
||||
use std::sync::Mutex;
|
||||
use tauri::State;
|
||||
|
||||
pub struct AppState {
|
||||
pub counter: Mutex<u32>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn increment_counter(state: State<'_, AppState>, value: u32) -> u32 {
|
||||
let mut counter = state.counter.lock().unwrap();
|
||||
*counter += value;
|
||||
*counter // Return to frontend
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.manage(AppState { counter: Mutex::new(0) }) // Inject State
|
||||
.invoke_handler(tauri::generate_handler![increment_counter])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("failed to run app");
|
||||
}
|
||||
```
|
||||
|
||||
```typescript
|
||||
// Frontend Invoke Pattern
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
const result = await invoke<number>('increment_counter', { value: 5 });
|
||||
console.log(result); // Output: 5
|
||||
```
|
||||
|
||||
### Events (Asynchronous Global Communication)
|
||||
Ideal for un-prompted data streaming from Rust to UI components.
|
||||
|
||||
```rust
|
||||
// Backend Emit
|
||||
use tauri::{Emitter, AppHandle};
|
||||
|
||||
fn stream_system_status(app_handle: &AppHandle, load: f32) {
|
||||
// Emits a global event to all active window contexts
|
||||
app_handle.emit("cpu-status", load).unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
```typescript
|
||||
// Frontend Listen
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
|
||||
// Make sure 'core:event:allow-listen' is in capabilities
|
||||
const unlisten = await listen<number>('cpu-status', (event) => {
|
||||
console.log(`CPU utilization: ${event.payload}%`);
|
||||
});
|
||||
|
||||
// Execute unlisten() later to clean up memory hooks
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📇 Deep Links & Windowing
|
||||
|
||||
### Multiple Window Spawning
|
||||
|
||||
```rust
|
||||
// Rust implementation
|
||||
use tauri::WebviewUrl;
|
||||
|
||||
fn create_extra_window(app: &tauri::AppHandle) {
|
||||
let _window = tauri::WebviewWindowBuilder::new(
|
||||
app,
|
||||
"secondary_panel",
|
||||
WebviewUrl::App("index.html/#/settings".into())
|
||||
)
|
||||
.title("Settings Panel")
|
||||
.inner_size(600.0, 400.0)
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
```
|
||||
|
||||
### Single Instance Lock & Deep Linking
|
||||
Ensures only one instance runs, piping external application schemas (e.g. `my-app://open?token=xyz`) into the active runtime.
|
||||
|
||||
```rust
|
||||
// src-tauri/src/lib.rs
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
|
||||
println!("Attempted alternative launch instances: {:?}, working dir: {:?}", args, cwd);
|
||||
// Focus primary window on secondary call triggers
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}))
|
||||
.run(tauri::generate_context!())
|
||||
.expect("failed execution");
|
||||
}
|
||||
```
|
||||
17
tauri2-docs/tauri2-links.md
Normal file
@ -0,0 +1,17 @@
|
||||
* Tauri 2.0 Upgrade & Migration Platform Index:
|
||||
https://v2.tauri.app/start/migrate/
|
||||
|
||||
* Tauri 2.0 In-Depth Guide for Upgrading from v1.x:
|
||||
https://v2.tauri.app/start/migrate/from-tauri-1/
|
||||
|
||||
* Tauri 2.0 Application Architecture Security and Core Capabilities Manual:
|
||||
https://v2.tauri.app/security/capabilities/
|
||||
|
||||
* Tauri 2.0 Granular Window Permissions Reference Guide:
|
||||
https://v2.tauri.app/security/permissions/
|
||||
|
||||
* Tauri 2.0 Official Configuration Files Layout Schema (`tauri.conf.json`):
|
||||
https://v2.tauri.app/develop/configuration-files/
|
||||
|
||||
* Tauri 2.0 Rust API Documentation Engine (Official `tauri` Crate Source Docs):
|
||||
https://docs.rs
|
||||