Milestone 7: the app normal people install (macOS)
A Tauri menu-bar app runs the same sync engine as `lunesync run`. It connects from the website with no code typed (lune://join and lune://pair links), shows status in the menu bar, and lets a person resolve held secrets, held big changes and kept-both notes side by side. Uninstall shares and hands over first, then removes only what Lune created. Releases are signed on the hub that holds the key (`lunehub release keygen/publish`); other hubs `release import` them. Apps verify the signature and the signed version. Clients older than the previous release are asked to update and keep saving locally. A device can now be on several hubs at once (own and workplace), each with its own key; the CLI takes --team when it matters. The supervisor and status summary moved into core, shared by the CLI and the app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2
desktop/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
gen/
|
||||
27
desktop/Cargo.toml
Normal file
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "lune-desktop"
|
||||
version.workspace = true
|
||||
edition = "2024"
|
||||
description = "Lune: the menu-bar app"
|
||||
|
||||
[[bin]]
|
||||
name = "lune"
|
||||
path = "src/main.rs"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.7.4", features = [] }
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.104"
|
||||
chrono = "0.4.45"
|
||||
lune-core = { version = "0.1.0", path = "../core" }
|
||||
serde = { version = "1.0.229", features = ["derive"] }
|
||||
serde_json = "1.0.154"
|
||||
tauri = { version = "2.12.5", features = ["tray-icon", "image-png"] }
|
||||
tauri-plugin-autostart = "2.7.0"
|
||||
tauri-plugin-deep-link = "2.6.3"
|
||||
tauri-plugin-dialog = "2.8.4"
|
||||
tauri-plugin-opener = "2.7.2"
|
||||
tauri-plugin-updater = "2.14.1"
|
||||
trash = "5.2.2"
|
||||
url = "2.5.4"
|
||||
3
desktop/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
18
desktop/build.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Builds Lune for the Mac: desktop/build.sh <version> [extra tauri --config ...]
|
||||
# Makes the .dmg people download and the .app.tar.gz the updater installs; then publish both on the hub that holds
|
||||
# the signing key: lunehub release publish <version> <app.tar.gz> <dmg>
|
||||
set -eu
|
||||
cd "$(dirname "$0")"
|
||||
v=${1:?usage: desktop/build.sh <version>}
|
||||
shift
|
||||
if grep -q '"pubkey": ""' tauri.conf.json; then
|
||||
echo "note: no update key in tauri.conf.json yet — this build won't accept updates (run lunehub release keygen)" >&2
|
||||
fi
|
||||
npx tauri build --bundles app,dmg --config "{\"version\":\"$v\"}" "$@"
|
||||
b=../target/release/bundle
|
||||
# macOS tar would add ._ resource-fork entries that the updater can't unpack.
|
||||
COPYFILE_DISABLE=1 tar --no-mac-metadata -czf "$b/Lune_${v}_aarch64.app.tar.gz" -C "$b/macos" Lune.app
|
||||
echo "Built:"
|
||||
echo " $(cd "$b" && pwd)/dmg/Lune_${v}_aarch64.dmg"
|
||||
echo " $(cd "$b" && pwd)/Lune_${v}_aarch64.app.tar.gz"
|
||||
7
desktop/capabilities/default.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "The Lune window: its own commands and events only.",
|
||||
"windows": ["main"],
|
||||
"permissions": ["core:default"]
|
||||
}
|
||||
BIN
desktop/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
desktop/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
desktop/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
desktop/icons/icon.icns
Normal file
BIN
desktop/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
desktop/icons/icon.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
desktop/icons/tray-amber.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
desktop/icons/tray-green.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
desktop/icons/tray-grey.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
desktop/icons/tray-red.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
230
desktop/package-lock.json
generated
Normal file
@@ -0,0 +1,230 @@
|
||||
{
|
||||
"name": "lune-desktop",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "lune-desktop",
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "2.12.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli/-/cli-2.12.4.tgz",
|
||||
"integrity": "sha512-JI9bHfudSRJikGOrjbXEm6RjzzvmKuLc+JixB1NE8hNzQkNlCCIC3pTES3uypkR9lxHrsbxzcnSwhI2IxBQphw==",
|
||||
"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.12.4",
|
||||
"@tauri-apps/cli-darwin-x64": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm-gnueabihf": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-arm64-musl": "2.12.4",
|
||||
"@tauri-apps/cli-linux-riscv64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-x64-gnu": "2.12.4",
|
||||
"@tauri-apps/cli-linux-x64-musl": "2.12.4",
|
||||
"@tauri-apps/cli-win32-arm64-msvc": "2.12.4",
|
||||
"@tauri-apps/cli-win32-ia32-msvc": "2.12.4",
|
||||
"@tauri-apps/cli-win32-x64-msvc": "2.12.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/cli-darwin-arm64": {
|
||||
"version": "2.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-2.12.4.tgz",
|
||||
"integrity": "sha512-OxqKSckIkoJ6vX2AjifIJpTasFC0Hbdoo7gEiCmAjauABO3U8m2MRsLWe+QTiBwDx1mIrvgA+rvI7tvDnbnHVg==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-darwin-x64/-/cli-darwin-x64-2.12.4.tgz",
|
||||
"integrity": "sha512-fz76/77wMMJOaaUN6n3CybRG0P/MTEjjqYk81mGPyhi9m6Ue5T+LWBnJP/AkPooNatBPI2vtulGqomyMJ44lCQ==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm-gnueabihf/-/cli-linux-arm-gnueabihf-2.12.4.tgz",
|
||||
"integrity": "sha512-K0w8Bof6Lt8QKLAYhRy0yy36ZH5iA/35VuSOvnxyjvCUZ+A3JKsUTlALviH/sVgAlisaPzzmeJSH8XOn4Q2HBA==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-j5rOnjmRUwWrm1oosf0zBYl4D+fqydgUROFCk0hvKZxvbTT8SOERes0QB7rBV/XWNy+kM6pCKzb3oSm2sRglzg==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.12.4.tgz",
|
||||
"integrity": "sha512-aOue3Fy6Jb7+oWcfAVUsVHfeTybSCt2CZoU06aO4jv4d2Ks/KnaTPwMAK3CLEduGOvBLY1lbBBrIyomqLLH5Sg==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-riscv64-gnu/-/cli-linux-riscv64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-Fx6GShY/RvST+t6LMlTHAwd66+1tEaAAGrnU7cysVfaiRP1BKng5Vl6rVmO6rSLOA1Sp1dRzNYM4f0OWQGb7qA==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-gnu/-/cli-linux-x64-gnu-2.12.4.tgz",
|
||||
"integrity": "sha512-tNzZSa79Z1nRpHxEpQ38lsAFpKlFlYvoXzjTV+lRRn/zSf3wrdUC3wnLcq2XEadchPu4ttK0zivhYzr+XGD19Q==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-linux-x64-musl/-/cli-linux-x64-musl-2.12.4.tgz",
|
||||
"integrity": "sha512-jmZ1pr0xEqUhuEusWtt9Yt+GF6lCnGHUmIL+KIknpbjK/XQ2qkhDBhaxK/JMHM2A8dAacVXCxXJk2EXpwhQUfA==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-fGo8pgEHZxdSYgZ/J98m1usJ7NHKmKbq7k6uT0x1rpOq6Bg2YVzzpaAblWk710f5LHYBJIL5QIFS5IrD+4gmTg==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-ezl8sQIcjYsye3TUnTH5VcWmWzccZASlQm7hlZt0dYyj1XD0qpVW47u2xYVrIKui0F8uQv/7QGZixdWiClBsbg==",
|
||||
"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.12.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/cli-win32-x64-msvc/-/cli-win32-x64-msvc-2.12.4.tgz",
|
||||
"integrity": "sha512-DJhDeCqjLDNMWYFy7ZS8cfeAHX2RK0RbQMLiA3bMVVkXRDJ4NBYiHriGqsUhsr9iG41aTb+dJGkFPmPw1gWwVw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"license": "Apache-2.0 OR MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
desktop/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "lune-desktop",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"tauri": "tauri"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "2.12.4"
|
||||
}
|
||||
}
|
||||
271
desktop/src/commands.rs
Normal file
@@ -0,0 +1,271 @@
|
||||
//! What the Lune window can ask for: status, connecting, and the decisions only a person makes.
|
||||
|
||||
use crate::{AppState, Connect};
|
||||
use lune_core::config::{Config, default_device_name};
|
||||
use lune_core::hub::{self, HubLink};
|
||||
use lune_core::state;
|
||||
use lune_core::status::{self, VaultStatus};
|
||||
use lune_core::tidy::{self, Keep};
|
||||
use lune_core::vault::Vault;
|
||||
use lune_core::{secrets, supervisor};
|
||||
use serde::Serialize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use tauri::{AppHandle, State};
|
||||
use tauri_plugin_autostart::ManagerExt as _;
|
||||
use tauri_plugin_dialog::DialogExt;
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
|
||||
type Answer<T> = Result<T, String>;
|
||||
|
||||
fn plain(e: anyhow::Error) -> String {
|
||||
format!("{e:#}").replace("the hub said: ", "")
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Pending {
|
||||
kind: &'static str,
|
||||
hub: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Overview {
|
||||
version: String,
|
||||
connected: bool,
|
||||
/// The hubs this Mac is on, by address.
|
||||
teams: Vec<String>,
|
||||
device: String,
|
||||
folder: String,
|
||||
level: String,
|
||||
summary: String,
|
||||
vaults: Vec<VaultStatus>,
|
||||
pending: Option<Pending>,
|
||||
update: Option<String>,
|
||||
recent: Vec<String>,
|
||||
}
|
||||
|
||||
/// The name people gave this Mac ("Sen's MacBook Air"), rather than its network host name.
|
||||
fn mac_name() -> String {
|
||||
std::process::Command::new("scutil")
|
||||
.args(["--get", "ComputerName"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||
.map(|n| n.trim().chars().take(40).collect::<String>())
|
||||
.filter(|n| !n.is_empty())
|
||||
.unwrap_or_else(default_device_name)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn overview(app: AppHandle, state: State<AppState>) -> Answer<Overview> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let label = config.device_label();
|
||||
let (level, summary) = crate::summary(&config);
|
||||
let pending = state.pending.lock().unwrap().as_ref().map(|c| Pending {
|
||||
kind: if matches!(c, Connect::Join { .. }) { "join" } else { "pair" },
|
||||
hub: c.hub(),
|
||||
});
|
||||
Ok(Overview {
|
||||
version: app.package_info().version.to_string(),
|
||||
connected: !config.hubs.is_empty(),
|
||||
teams: config.hubs.iter().map(|h| h.url.clone()).collect(),
|
||||
device: config.device_name.clone().unwrap_or_else(mac_name),
|
||||
folder: config.vaults_dir().display().to_string(),
|
||||
level,
|
||||
summary,
|
||||
vaults: config.vaults.iter().map(|v| status::of(v, &label)).collect(),
|
||||
pending,
|
||||
update: state.update_ready.lock().unwrap().clone(),
|
||||
recent: crate::recent_log(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Connects this Mac to a team: from the link the website opened, or from a hub address and pairing code typed
|
||||
/// by hand. A Mac can be on several teams' hubs at once.
|
||||
#[tauri::command(async)]
|
||||
pub fn connect(
|
||||
app: AppHandle,
|
||||
state: State<AppState>,
|
||||
name: String,
|
||||
folder: String,
|
||||
hub_url: Option<String>,
|
||||
code: Option<String>,
|
||||
) -> Answer<String> {
|
||||
let label = name.trim();
|
||||
if label.is_empty() {
|
||||
return Err("give this Mac a name your team will see".into());
|
||||
}
|
||||
let mut config = Config::load().map_err(plain)?;
|
||||
let request = match (hub_url, code) {
|
||||
(Some(hub), Some(code)) if !hub.trim().is_empty() && !code.trim().is_empty() => {
|
||||
let hub = hub.trim().trim_end_matches('/');
|
||||
let hub = if hub.starts_with("http") { hub.to_string() } else { format!("https://{hub}") };
|
||||
Connect::Pair { hub, code: code.trim().to_string() }
|
||||
}
|
||||
_ => state.pending.lock().unwrap().clone().ok_or("open the link from your team's website, or enter a code")?,
|
||||
};
|
||||
if config.hub(request.hub().trim_end_matches('/')).is_some() {
|
||||
*state.pending.lock().unwrap() = None;
|
||||
return Err(format!("this Mac is already connected to {}", request.hub()));
|
||||
}
|
||||
let (url, welcome) = match &request {
|
||||
Connect::Join { link } => hub::join(link, label).map_err(plain)?,
|
||||
Connect::Pair { hub, code } => (hub.clone(), hub::login(hub, code, label).map_err(plain)?),
|
||||
};
|
||||
*state.pending.lock().unwrap() = None;
|
||||
config.device_name = Some(label.to_string());
|
||||
config.vaults_dir = Some(folder.into());
|
||||
config.hubs.push(HubLink { url, device_id: welcome.device_id, key: welcome.key });
|
||||
config.save().map_err(plain)?;
|
||||
supervisor::CHECK_HUB.store(true, Ordering::Relaxed);
|
||||
// Start with the Mac from now on (not for test setups that point LUNE_HOME elsewhere).
|
||||
if std::env::var_os("LUNE_HOME").is_none() {
|
||||
let _ = app.autolaunch().enable();
|
||||
}
|
||||
Ok(format!("Connected as {} — your vaults are on their way", welcome.person))
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn choose_folder(app: AppHandle) -> Option<String> {
|
||||
let start = Config::load().unwrap_or_default().vaults_dir();
|
||||
let start = start.ancestors().find(|p| p.exists()).map(|p| p.to_path_buf()).unwrap_or_default();
|
||||
app.dialog()
|
||||
.file()
|
||||
.set_title("Where should shared vaults live?")
|
||||
.set_directory(start)
|
||||
.blocking_pick_folder()
|
||||
.and_then(|p| p.into_path().ok())
|
||||
.map(|p| p.display().to_string())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn share_now() {
|
||||
supervisor::share_now(&Config::load().unwrap_or_default());
|
||||
}
|
||||
|
||||
/// Opens a vault and holds its op lock for one decision; afterwards the runner shares at once.
|
||||
fn with_vault<T>(name: &str, f: impl FnOnce(&Config, &Vault) -> anyhow::Result<T>) -> Answer<T> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
config.use_hub_credentials();
|
||||
let cfg = config.find(name).ok_or(format!("no vault named {name}"))?;
|
||||
let v = Vault::open(cfg, &config.device_label()).map_err(plain)?;
|
||||
let out = {
|
||||
let _op = state::op_lock(&v.git_dir).map_err(plain)?;
|
||||
f(&config, &v).map_err(plain)?
|
||||
};
|
||||
let _ = std::fs::write(state::lune_dir(&v.git_dir).join("nudge"), "");
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn held_share(vault: String) -> Answer<()> {
|
||||
with_vault(&vault, |_, v| v.share_held().map(|_| ()))
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn held_undo(vault: String) -> Answer<usize> {
|
||||
with_vault(&vault, |_, v| v.undo_held().map(|kept| kept.len()))
|
||||
}
|
||||
|
||||
fn held_hits(v: &Vault, path: &str) -> anyhow::Result<Vec<secrets::Hit>> {
|
||||
let note = v.secret_holds()?.into_iter().find(|n| n.path == path);
|
||||
note.map(|n| n.hits).filter(|h| !h.is_empty()).ok_or_else(|| anyhow::anyhow!("nothing is held in {path} any more"))
|
||||
}
|
||||
|
||||
/// Replace with a pointer (P2): the secret goes, a note on where to find it stays.
|
||||
#[tauri::command(async)]
|
||||
pub fn secret_pointer(vault: String, path: String, pointer: String) -> Answer<()> {
|
||||
if pointer.trim().is_empty() {
|
||||
return Err("say where to get it, e.g. \"search prod-deploy in Secrets Manager\"".into());
|
||||
}
|
||||
with_vault(&vault, |_, v| {
|
||||
let hits = held_hits(v, &path)?;
|
||||
let file = v.root.join(&path);
|
||||
let text = std::fs::read_to_string(&file)?;
|
||||
std::fs::write(&file, secrets::replace_with_pointer(&text, &hits, None, pointer.trim()))?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn not_a_secret(vault: String, path: String) -> Answer<()> {
|
||||
with_vault(&vault, |config, v| {
|
||||
let cfg = config.find(&vault).unwrap();
|
||||
for h in held_hits(v, &path)? {
|
||||
secrets::allow(&v.git_dir, &h, &path)?;
|
||||
if let (Some(hub), Some(id)) = (config.hub_of(cfg), cfg.hub_vault) {
|
||||
hub.not_a_secret(id, &h.line_hash)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Comparison {
|
||||
note: String,
|
||||
copy: String,
|
||||
label: String,
|
||||
/// The copy beside the note is this Mac's version (the usual case after a clash here).
|
||||
copy_is_mine: bool,
|
||||
note_text: Option<String>,
|
||||
copy_text: Option<String>,
|
||||
}
|
||||
|
||||
fn as_text(bytes: Option<Vec<u8>>) -> Option<String> {
|
||||
bytes.filter(|b| b.len() <= 200_000 && !b.iter().take(8000).any(|&c| c == 0)).map(|b| String::from_utf8_lossy(&b).into_owned())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn compare(vault: String, copy: String) -> Answer<Comparison> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let cfg = config.find(&vault).ok_or(format!("no vault named {vault}"))?;
|
||||
let v = Vault::open(cfg, &config.device_label()).map_err(plain)?;
|
||||
let k = tidy::list(&v).map_err(plain)?.into_iter().find(|k| k.copy == copy).ok_or("that was tidied already")?;
|
||||
Ok(Comparison {
|
||||
note_text: as_text(std::fs::read(v.root.join(&k.note)).ok()),
|
||||
copy_text: as_text(std::fs::read(v.root.join(&k.copy)).ok()),
|
||||
copy_is_mine: k.label.eq_ignore_ascii_case(&v.label),
|
||||
note: k.note,
|
||||
copy: k.copy,
|
||||
label: k.label,
|
||||
})
|
||||
}
|
||||
|
||||
/// Keeps the version in place ("note"), the one beside it ("copy"), or both as separate notes.
|
||||
#[tauri::command(async)]
|
||||
pub fn tidy(vault: String, copy: String, keep: String) -> Answer<()> {
|
||||
with_vault(&vault, |_, v| {
|
||||
let k = tidy::list(v)?.into_iter().find(|k| k.copy == copy).ok_or_else(|| anyhow::anyhow!("that was tidied already"))?;
|
||||
let copy_is_mine = k.label.eq_ignore_ascii_case(&v.label);
|
||||
let choice = match (keep.as_str(), copy_is_mine) {
|
||||
("both", _) => Keep::Both,
|
||||
("copy", true) | ("note", false) => Keep::Mine,
|
||||
_ => Keep::Theirs,
|
||||
};
|
||||
tidy::keep(v, ©, choice).map(|_| ())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open_canvas_now(app: &AppHandle, team: Option<&str>) -> Answer<()> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let hub = config.pick_hub(team).map_err(plain)?;
|
||||
let link = hub.web_link().map_err(plain)?;
|
||||
app.opener().open_url(link, None::<&str>).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn open_canvas(app: AppHandle, team: Option<String>) -> Answer<()> {
|
||||
open_canvas_now(&app, team.as_deref())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
pub fn open_folder(app: AppHandle, vault: String) -> Answer<()> {
|
||||
let config = Config::load().map_err(plain)?;
|
||||
let cfg = config.find(&vault).ok_or(format!("no vault named {vault}"))?;
|
||||
app.opener().open_path(cfg.path.display().to_string(), None::<&str>).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn restart(app: AppHandle) {
|
||||
app.restart();
|
||||
}
|
||||
419
desktop/src/main.rs
Normal file
@@ -0,0 +1,419 @@
|
||||
//! Lune for the Mac (M7): the sync engine in the menu bar, a small window for what needs a person, connecting
|
||||
//! from a link, signed updates from the hub, and a clean uninstall.
|
||||
|
||||
mod commands;
|
||||
|
||||
use lune_core::config::{self, Config};
|
||||
use lune_core::{membership, remote, runner, status, supervisor};
|
||||
use std::collections::VecDeque;
|
||||
use std::io::Write;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
use std::time::Duration;
|
||||
use tauri::image::Image;
|
||||
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
|
||||
use tauri::tray::{TrayIcon, TrayIconBuilder};
|
||||
use tauri::{AppHandle, Manager, WindowEvent};
|
||||
use tauri_plugin_autostart::{MacosLauncher, ManagerExt as _};
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
|
||||
use tauri_plugin_updater::UpdaterExt;
|
||||
|
||||
/// A request to connect this Mac, from a `lune://` link the website opened.
|
||||
#[derive(Clone)]
|
||||
pub enum Connect {
|
||||
/// An invite link: creates the person's account and this device.
|
||||
Join { link: String },
|
||||
/// A pairing code made for a signed-in person.
|
||||
Pair { hub: String, code: String },
|
||||
}
|
||||
|
||||
impl Connect {
|
||||
pub fn hub(&self) -> String {
|
||||
match self {
|
||||
Connect::Join { link } => link.split("/join/").next().unwrap_or_default().to_string(),
|
||||
Connect::Pair { hub, .. } => hub.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_url(url: &url::Url) -> Option<Connect> {
|
||||
let param = |name: &str| url.query_pairs().find(|(k, _)| k == name).map(|(_, v)| v.into_owned());
|
||||
match url.host_str()? {
|
||||
"join" => Some(Connect::Join { link: param("link")? }),
|
||||
"pair" => Some(Connect::Pair { hub: param("hub")?, code: param("code")? }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AppState {
|
||||
pub pending: Mutex<Option<Connect>>,
|
||||
/// A newer version, downloaded and installed; it runs after a restart.
|
||||
pub update_ready: Mutex<Option<String>>,
|
||||
tray: Mutex<Option<TrayParts>>,
|
||||
}
|
||||
|
||||
struct TrayParts {
|
||||
icon: TrayIcon,
|
||||
status: MenuItem<tauri::Wry>,
|
||||
canvas: MenuItem<tauri::Wry>,
|
||||
update: MenuItem<tauri::Wry>,
|
||||
level: String,
|
||||
}
|
||||
|
||||
static APP: OnceLock<AppHandle> = OnceLock::new();
|
||||
static RECENT: Mutex<VecDeque<String>> = Mutex::new(VecDeque::new());
|
||||
|
||||
/// The engine's log: kept briefly for the window and appended to `lune.log` next to the config.
|
||||
fn log_line(vault: &str, msg: &str) {
|
||||
let line = format!("{} {vault:<10} {msg}", chrono::Local::now().format("%H:%M:%S"));
|
||||
{
|
||||
let mut recent = RECENT.lock().unwrap();
|
||||
recent.push_back(line.clone());
|
||||
while recent.len() > 50 {
|
||||
recent.pop_front();
|
||||
}
|
||||
}
|
||||
if let Ok(dir) = config::config_dir() {
|
||||
let path = dir.join("lune.log");
|
||||
if std::fs::metadata(&path).is_ok_and(|m| m.len() > 2_000_000) {
|
||||
let _ = std::fs::remove_file(&path);
|
||||
}
|
||||
if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(path) {
|
||||
let _ = writeln!(f, "{line}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recent_log() -> Vec<String> {
|
||||
RECENT.lock().unwrap().iter().rev().take(12).cloned().collect()
|
||||
}
|
||||
|
||||
pub fn show_window(app: &AppHandle) {
|
||||
if let Some(w) = app.get_webview_window("main") {
|
||||
let _ = w.show();
|
||||
let _ = w.unminimize();
|
||||
let _ = w.set_focus();
|
||||
}
|
||||
// Opening the window is a good moment to look for an update.
|
||||
let app = app.clone();
|
||||
tauri::async_runtime::spawn(async move { check_for_update(&app).await });
|
||||
}
|
||||
|
||||
fn tray_image(level: &str) -> Image<'static> {
|
||||
let bytes: &[u8] = match level {
|
||||
"secret" => include_bytes!("../icons/tray-red.png"),
|
||||
"behind" => include_bytes!("../icons/tray-amber.png"),
|
||||
"offline" => include_bytes!("../icons/tray-grey.png"),
|
||||
_ => include_bytes!("../icons/tray-green.png"),
|
||||
};
|
||||
Image::from_bytes(bytes).expect("tray icons are valid PNGs")
|
||||
}
|
||||
|
||||
/// One line for the menu bar: the worst thing going on, in plain words.
|
||||
pub fn summary(config: &Config) -> (String, String) {
|
||||
if config.hubs.is_empty() && config.vaults.is_empty() {
|
||||
return ("offline".into(), "Not connected to a team yet".into());
|
||||
}
|
||||
let label = config.device_label();
|
||||
let all: Vec<status::VaultStatus> = config.vaults.iter().map(|v| status::of(v, &label)).collect();
|
||||
let level = status::worst(all.iter().map(|s| s.level)).to_string();
|
||||
let text = match all.iter().find(|s| s.level == level && level != "current") {
|
||||
Some(s) if !s.secrets.is_empty() => format!("{}: a note was held back (possible secret)", s.name),
|
||||
Some(s) if !s.held.is_empty() => format!("{}: a big change is waiting for you", s.name),
|
||||
Some(s) if !s.tidy.is_empty() && s.headline == "Synced" => {
|
||||
format!("{}: {} to tidy", s.name, if s.tidy.len() == 1 { "1 note".to_string() } else { format!("{} notes", s.tidy.len()) })
|
||||
}
|
||||
Some(s) => format!("{}: {}", s.name, s.headline),
|
||||
None if all.is_empty() => "Waiting for vaults to arrive".into(),
|
||||
None => "All synced".into(),
|
||||
};
|
||||
(level, text)
|
||||
}
|
||||
|
||||
fn refresh_tray(app: &AppHandle) {
|
||||
let config = Config::load().unwrap_or_default();
|
||||
let (level, text) = summary(&config);
|
||||
let state = app.state::<AppState>();
|
||||
let update = state.update_ready.lock().unwrap().clone();
|
||||
let mut tray = state.tray.lock().unwrap();
|
||||
let Some(t) = tray.as_mut() else { return };
|
||||
if t.level != level {
|
||||
let _ = t.icon.set_icon(Some(tray_image(&level)));
|
||||
t.level = level;
|
||||
}
|
||||
let _ = t.status.set_text(&text);
|
||||
let _ = t.icon.set_tooltip(Some(format!("Lune — {text}")));
|
||||
let _ = t.canvas.set_enabled(!config.hubs.is_empty());
|
||||
match update {
|
||||
Some(v) => {
|
||||
let _ = t.update.set_text(format!("Restart to update (Lune {v})"));
|
||||
let _ = t.update.set_enabled(true);
|
||||
}
|
||||
None => {
|
||||
let _ = t.update.set_text(format!("Lune {}", app.package_info().version));
|
||||
let _ = t.update.set_enabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn build_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
let status = MenuItem::with_id(app, "status", "Starting…", false, None::<&str>)?;
|
||||
let open = MenuItem::with_id(app, "open", "Open Lune", true, None::<&str>)?;
|
||||
let canvas = MenuItem::with_id(app, "canvas", "Open team canvas", false, None::<&str>)?;
|
||||
let share = MenuItem::with_id(app, "share", "Share now", true, None::<&str>)?;
|
||||
let update = MenuItem::with_id(app, "update", "", false, None::<&str>)?;
|
||||
let uninstall_item = MenuItem::with_id(app, "uninstall", "Uninstall Lune…", true, None::<&str>)?;
|
||||
let quit = MenuItem::with_id(app, "quit", "Quit Lune", true, None::<&str>)?;
|
||||
let sep = || PredefinedMenuItem::separator(app);
|
||||
let menu = Menu::with_items(app, &[&status, &sep()?, &open, &canvas, &share, &sep()?, &update, &uninstall_item, &quit])?;
|
||||
let icon = TrayIconBuilder::with_id("lune")
|
||||
.icon(tray_image("offline"))
|
||||
.icon_as_template(false)
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(true)
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"open" => show_window(app),
|
||||
"canvas" => {
|
||||
// One team: straight to its canvas. Several: the window lists them.
|
||||
if Config::load().unwrap_or_default().hubs.len() > 1 {
|
||||
show_window(app);
|
||||
} else {
|
||||
let app = app.clone();
|
||||
std::thread::spawn(move || {
|
||||
if let Err(e) = commands::open_canvas_now(&app, None) {
|
||||
log_line("hub", &format!("couldn't open the canvas: {e}"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
"share" => supervisor::share_now(&Config::load().unwrap_or_default()),
|
||||
"update" => app.restart(),
|
||||
"uninstall" => {
|
||||
let app = app.clone();
|
||||
std::thread::spawn(move || uninstall(&app));
|
||||
}
|
||||
"quit" => app.exit(0),
|
||||
_ => {}
|
||||
})
|
||||
.build(app)?;
|
||||
let state = app.state::<AppState>();
|
||||
*state.tray.lock().unwrap() = Some(TrayParts { icon, status, canvas, update, level: "offline".into() });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Looks for a newer version on this Mac's hubs (they all serve releases signed with the one key); downloads and
|
||||
/// installs it, ready for a restart (D3).
|
||||
pub async fn check_for_update(app: &AppHandle) {
|
||||
let hubs = Config::load().map(|c| c.hubs).unwrap_or_default();
|
||||
if hubs.is_empty() {
|
||||
return;
|
||||
}
|
||||
if app.state::<AppState>().update_ready.lock().unwrap().is_some() {
|
||||
return;
|
||||
}
|
||||
let configured = app
|
||||
.config()
|
||||
.plugins
|
||||
.0
|
||||
.get("updater")
|
||||
.and_then(|u| u.get("pubkey"))
|
||||
.and_then(|k| k.as_str())
|
||||
.is_some_and(|k| !k.is_empty());
|
||||
if !configured {
|
||||
return; // a build without the hub's public key can't verify updates, so it doesn't take any
|
||||
}
|
||||
let endpoints = hubs.iter().filter_map(|h| format!("{}/api/update/{{{{target}}}}/{{{{arch}}}}/{{{{current_version}}}}", h.url).parse().ok());
|
||||
let result = async {
|
||||
let updater = app
|
||||
.updater_builder()
|
||||
.endpoints(endpoints.collect())?
|
||||
.header("User-Agent", remote::user_agent())?
|
||||
.build()?;
|
||||
if let Some(update) = updater.check().await? {
|
||||
log_line("app", &format!("downloading Lune {}", update.version));
|
||||
update.download_and_install(|_, _| {}, || {}).await?;
|
||||
return Ok::<_, anyhow::Error>(Some(update.version));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
.await;
|
||||
match result {
|
||||
Ok(Some(version)) => {
|
||||
log_line("app", &format!("Lune {version} is ready — restart to use it"));
|
||||
*app.state::<AppState>().update_ready.lock().unwrap() = Some(version);
|
||||
refresh_tray(app);
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => log_line("app", &format!("couldn't check for an update: {e:#}")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Uninstall Lune… (D5): asks once, then shares, hands over, removes what Lune made, and moves itself to the Trash.
|
||||
fn uninstall(app: &AppHandle) {
|
||||
let ok = app
|
||||
.dialog()
|
||||
.message(
|
||||
"Lune first shares anything not yet shared and hands the rest to your team, then removes:\n\n\
|
||||
• the vault folders Lune created\n• this Mac from your team\n• Lune's settings and login item\n• the app itself\n\n\
|
||||
Folders you added yourself stay, and so does any folder whose changes couldn't be shared.",
|
||||
)
|
||||
.title("Uninstall Lune from this Mac?")
|
||||
.kind(MessageDialogKind::Warning)
|
||||
.buttons(MessageDialogButtons::OkCancelCustom("Uninstall".into(), "Cancel".into()))
|
||||
.blocking_show();
|
||||
if !ok {
|
||||
return;
|
||||
}
|
||||
runner::STOP.store(true, Ordering::Relaxed);
|
||||
let mut config = Config::load().unwrap_or_default();
|
||||
config.use_hub_credentials();
|
||||
let done = membership::uninstall(&mut config);
|
||||
let _ = app.autolaunch().disable();
|
||||
let mut leftovers = vec![];
|
||||
if let Ok(dir) = config::config_dir() {
|
||||
leftovers.push(dir);
|
||||
}
|
||||
let paths = app.path();
|
||||
leftovers.extend([paths.app_data_dir(), paths.app_cache_dir(), paths.app_log_dir(), paths.app_config_dir()].into_iter().flatten());
|
||||
if let Some(home) = std::env::home_dir() {
|
||||
let id = &app.config().identifier;
|
||||
leftovers.push(home.join("Library/WebKit").join(id));
|
||||
leftovers.push(home.join("Library/Caches").join(id));
|
||||
}
|
||||
let message = match done {
|
||||
Ok(done) => {
|
||||
for dir in leftovers.iter().filter(|d| d.exists()) {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
let bundle = std::env::current_exe()
|
||||
.ok()
|
||||
.and_then(|exe| exe.ancestors().find(|p| p.extension().is_some_and(|e| e == "app")).map(|p| p.to_path_buf()));
|
||||
let mut text = String::from("Lune is uninstalled.");
|
||||
if let Some(bundle) = bundle
|
||||
&& let Err(e) = move_to_trash(&bundle)
|
||||
{
|
||||
log_line("app", &format!("couldn't move the app to the Trash: {e}"));
|
||||
text = format!("Lune is uninstalled. Drag {} to the Trash to finish.", bundle.display());
|
||||
}
|
||||
if !done.removed.is_empty() {
|
||||
text.push_str(&format!("\n\nRemoved:\n{}", done.removed.join("\n")));
|
||||
}
|
||||
if !done.kept.is_empty() {
|
||||
text.push_str(&format!("\n\nKept:\n{}", done.kept.join("\n")));
|
||||
}
|
||||
if let Some(p) = done.hub_problem {
|
||||
text.push_str(&format!("\n\nNote: {p}"));
|
||||
}
|
||||
text
|
||||
}
|
||||
Err(e) => format!("Uninstall stopped before removing anything else: {e:#}\n\nOpen Lune again to keep syncing."),
|
||||
};
|
||||
app.dialog().message(message).title("Lune").buttons(MessageDialogButtons::Ok).blocking_show();
|
||||
app.exit(0);
|
||||
}
|
||||
|
||||
/// The system's own "move to Trash" (Finder's way needs an extra permission and fails quietly without it).
|
||||
fn move_to_trash(path: &std::path::Path) -> Result<(), trash::Error> {
|
||||
let mut ctx = trash::TrashContext::default();
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use trash::macos::{DeleteMethod, TrashContextExtMacos};
|
||||
ctx.set_delete_method(DeleteMethod::NsFileManager);
|
||||
}
|
||||
ctx.delete(path)
|
||||
}
|
||||
|
||||
fn handle_links(app: &AppHandle, urls: Vec<url::Url>) {
|
||||
for url in urls {
|
||||
if let Some(c) = Connect::from_url(&url) {
|
||||
*app.state::<AppState>().pending.lock().unwrap() = Some(c);
|
||||
show_window(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_deep_link::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, None))
|
||||
.manage(AppState::default())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::overview,
|
||||
commands::connect,
|
||||
commands::choose_folder,
|
||||
commands::share_now,
|
||||
commands::held_share,
|
||||
commands::held_undo,
|
||||
commands::secret_pointer,
|
||||
commands::not_a_secret,
|
||||
commands::compare,
|
||||
commands::tidy,
|
||||
commands::open_canvas,
|
||||
commands::open_folder,
|
||||
commands::restart,
|
||||
])
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
let _ = APP.set(handle.clone());
|
||||
remote::set_client_version(&app.package_info().version.to_string());
|
||||
#[cfg(target_os = "macos")]
|
||||
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
|
||||
build_tray(&handle)?;
|
||||
|
||||
// The engine: the same one `lunesync run` uses, in this process.
|
||||
std::thread::spawn(|| {
|
||||
loop {
|
||||
if let Err(e) = supervisor::supervise(log_line) {
|
||||
log_line("app", &format!("sync stopped: {e:#} — restarting in 10 s"));
|
||||
}
|
||||
if runner::STOP.load(Ordering::Relaxed) {
|
||||
return;
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs(10));
|
||||
}
|
||||
});
|
||||
let tray_handle = handle.clone();
|
||||
std::thread::spawn(move || {
|
||||
loop {
|
||||
refresh_tray(&tray_handle);
|
||||
std::thread::sleep(Duration::from_secs(3));
|
||||
}
|
||||
});
|
||||
let update_handle = handle.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
tokio_sleep(Duration::from_secs(15)).await;
|
||||
loop {
|
||||
check_for_update(&update_handle).await;
|
||||
tokio_sleep(Duration::from_secs(6 * 3600)).await;
|
||||
}
|
||||
});
|
||||
|
||||
let link_handle = handle.clone();
|
||||
app.deep_link().on_open_url(move |event| handle_links(&link_handle, event.urls()));
|
||||
if let Ok(Some(urls)) = app.deep_link().get_current() {
|
||||
handle_links(&handle, urls);
|
||||
}
|
||||
if Config::load().map(|c| c.hubs.is_empty() && c.vaults.is_empty()).unwrap_or(true) {
|
||||
show_window(&handle);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
// Closing the window keeps Lune running in the menu bar.
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
api.prevent_close();
|
||||
let _ = window.hide();
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("Lune couldn't start");
|
||||
}
|
||||
|
||||
async fn tokio_sleep(d: Duration) {
|
||||
let _ = tauri::async_runtime::spawn_blocking(move || std::thread::sleep(d)).await;
|
||||
}
|
||||
39
desktop/tauri.conf.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Lune",
|
||||
"mainBinaryName": "lune",
|
||||
"identifier": "space.senkensha.lune",
|
||||
"build": {
|
||||
"frontendDist": "../web/dist-desktop",
|
||||
"beforeBuildCommand": "npm --prefix ../web run build:desktop"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"title": "Lune",
|
||||
"url": "desktop.html",
|
||||
"width": 440,
|
||||
"height": 620,
|
||||
"minWidth": 360,
|
||||
"minHeight": 420,
|
||||
"visible": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": ["app", "dmg"],
|
||||
"icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.png"],
|
||||
"category": "Productivity",
|
||||
"shortDescription": "Keeps shared vaults in sync",
|
||||
"macOS": { "minimumSystemVersion": "12.0", "signingIdentity": "-" }
|
||||
},
|
||||
"plugins": {
|
||||
"deep-link": { "desktop": { "schemes": ["lune"] } },
|
||||
"updater": { "pubkey": "", "requireSignedVersion": true }
|
||||
}
|
||||
}
|
||||