mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:38:29 +02:00
Refactor desktop app into separate client and proxy apps
This commit is contained in:
8
crates-tauri/yaak-app-proxy/.gitignore
vendored
Normal file
8
crates-tauri/yaak-app-proxy/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
target/
|
||||
|
||||
gen/*
|
||||
|
||||
**/permissions/autogenerated
|
||||
**/permissions/schemas
|
||||
18
crates-tauri/yaak-app-proxy/Cargo.toml
Normal file
18
crates-tauri/yaak-app-proxy/Cargo.toml
Normal file
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "yaak-app-proxy"
|
||||
version = "0.0.0"
|
||||
edition = "2024"
|
||||
authors = ["Gregory Schier"]
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "tauri_app_proxy_lib"
|
||||
crate-type = ["staticlib", "cdylib", "lib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.5.3", features = [] }
|
||||
|
||||
[dependencies]
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
tauri = { workspace = true }
|
||||
yaak-proxy = { workspace = true }
|
||||
1
crates-tauri/yaak-app-proxy/bindings/index.ts
generated
Normal file
1
crates-tauri/yaak-app-proxy/bindings/index.ts
generated
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
3
crates-tauri/yaak-app-proxy/build.rs
Normal file
3
crates-tauri/yaak-app-proxy/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
10
crates-tauri/yaak-app-proxy/capabilities/default.json
Normal file
10
crates-tauri/yaak-app-proxy/capabilities/default.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"identifier": "default",
|
||||
"description": "Default capabilities for the Yaak Proxy app",
|
||||
"windows": [
|
||||
"*"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default"
|
||||
]
|
||||
}
|
||||
6
crates-tauri/yaak-app-proxy/package.json
Normal file
6
crates-tauri/yaak-app-proxy/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "@yaakapp-internal/tauri-proxy",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "bindings/index.ts"
|
||||
}
|
||||
63
crates-tauri/yaak-app-proxy/src/lib.rs
Normal file
63
crates-tauri/yaak-app-proxy/src/lib.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use serde::Serialize;
|
||||
use std::sync::Mutex;
|
||||
use tauri::State;
|
||||
use yaak_proxy::ProxyHandle;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ProxyMetadata {
|
||||
name: String,
|
||||
version: String,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ProxyState {
|
||||
handle: Mutex<Option<ProxyHandle>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ProxyStartResult {
|
||||
port: u16,
|
||||
already_running: bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn proxy_metadata(app_handle: tauri::AppHandle) -> ProxyMetadata {
|
||||
ProxyMetadata {
|
||||
name: app_handle.package_info().name.clone(),
|
||||
version: app_handle.package_info().version.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn proxy_start(
|
||||
state: State<'_, ProxyState>,
|
||||
port: Option<u16>,
|
||||
) -> Result<ProxyStartResult, String> {
|
||||
let mut handle = state.handle.lock().map_err(|_| "failed to lock proxy state".to_string())?;
|
||||
|
||||
if let Some(existing) = handle.as_ref() {
|
||||
return Ok(ProxyStartResult { port: existing.port, already_running: true });
|
||||
}
|
||||
|
||||
let proxy_handle = yaak_proxy::start_proxy(port.unwrap_or(0))?;
|
||||
let started_port = proxy_handle.port;
|
||||
*handle = Some(proxy_handle);
|
||||
|
||||
Ok(ProxyStartResult { port: started_port, already_running: false })
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn proxy_stop(state: State<'_, ProxyState>) -> Result<bool, String> {
|
||||
let mut handle = state.handle.lock().map_err(|_| "failed to lock proxy state".to_string())?;
|
||||
Ok(handle.take().is_some())
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.manage(ProxyState::default())
|
||||
.invoke_handler(tauri::generate_handler![proxy_metadata, proxy_start, proxy_stop])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running yaak proxy tauri application");
|
||||
}
|
||||
5
crates-tauri/yaak-app-proxy/src/main.rs
Normal file
5
crates-tauri/yaak-app-proxy/src/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
tauri_app_proxy_lib::run();
|
||||
}
|
||||
13
crates-tauri/yaak-app-proxy/tauri.development.conf.json
Normal file
13
crates-tauri/yaak-app-proxy/tauri.development.conf.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"productName": "Yaak Proxy Dev",
|
||||
"identifier": "app.yaak.proxy.dev",
|
||||
"bundle": {
|
||||
"icon": [
|
||||
"../yaak-app-client/icons/dev/32x32.png",
|
||||
"../yaak-app-client/icons/dev/128x128.png",
|
||||
"../yaak-app-client/icons/dev/128x128@2x.png",
|
||||
"../yaak-app-client/icons/dev/icon.icns",
|
||||
"../yaak-app-client/icons/dev/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
5
crates-tauri/yaak-app-proxy/tauri.release.conf.json
Normal file
5
crates-tauri/yaak-app-proxy/tauri.release.conf.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"build": {
|
||||
"features": []
|
||||
}
|
||||
}
|
||||
9
crates-tauri/yaak-app-proxy/template.desktop
Normal file
9
crates-tauri/yaak-app-proxy/template.desktop
Normal file
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Categories={{categories}}
|
||||
Comment={{comment}}
|
||||
Exec={{exec}}
|
||||
Icon={{icon}}
|
||||
Name={{name}}
|
||||
StartupWMClass={{exec}}
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Reference in New Issue
Block a user