Compare commits
10 Commits
v0.1.0-alp
...
v0.1.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba846aa2db | ||
|
|
19a402be4d | ||
|
|
b10db23311 | ||
|
|
1bc4ac4bc9 | ||
|
|
4c1b350583 | ||
|
|
57ab313150 | ||
|
|
df89b049de | ||
|
|
0c8687eb00 | ||
|
|
7e0771c9e0 | ||
|
|
ec229db303 |
26
CHANGELOG.md
26
CHANGELOG.md
@@ -7,6 +7,32 @@ and this project follows early MVP/alpha versioning with tags like `v0.1.0-alpha
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [v0.1.0-alpha.6] - 2026-02-23
|
||||
|
||||
### Added
|
||||
- `chromium` compatibility backend via `--backend chromium` using an installed Chromium-based browser in app mode (no local Tauri build for generated apps)
|
||||
- `build` / `update` flags for Chromium backend selection and runtime control:
|
||||
- `--backend <tauri|chromium>`
|
||||
- `--browser-bin <PATH>`
|
||||
- `--profile-scope <isolated|shared>`
|
||||
- Chromium app install flow with XDG `.desktop` launchers and per-app metadata (`X-Deskify-Backend=chromium`)
|
||||
- Optional isolated Chromium profiles under `~/.local/share/deskify/profiles/<id>`
|
||||
- `doctor` now reports whether a Chromium-based browser is available in `PATH`
|
||||
|
||||
### Changed
|
||||
- `update <id>` now keeps the internal app ID stable even when the display name changes
|
||||
- `list` now derives the internal ID from the `.desktop` filename (works for both Tauri and Chromium backends)
|
||||
- `remove` now also cleans up Chromium profile directories (when present)
|
||||
- `update` keeps Chromium isolated profiles by default to preserve sessions/cookies during reinstall
|
||||
|
||||
### Fixed
|
||||
- Tauri wrapper generation now consistently uses the existing internal ID for generated app identifiers (prevents accidental ID drift during updates)
|
||||
- `.desktop` command generation for Chromium backend now escapes arguments (URLs / user agents with spaces or special characters)
|
||||
|
||||
### Documentation
|
||||
- README now documents backend modes (`tauri` vs `chromium`) and recommends `--backend chromium` for sites that fail in the system WebView backend
|
||||
- Added Chromium backend usage examples (`--browser-bin`, `--profile-scope`) and updated compatibility notes
|
||||
|
||||
### Added
|
||||
- `build --no-decorations` option to create frameless windows (`decorations: false`) for kiosk/dashboard-style setups
|
||||
- README screenshots for KDE/Arch showing launcher integration, running app window, and `deskify list` workflow
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -351,6 +351,7 @@ dependencies = [
|
||||
"directories",
|
||||
"image",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"ureq",
|
||||
@@ -1334,6 +1335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -9,6 +9,7 @@ clap = { version = "4.5.60", features = ["derive"] }
|
||||
directories = "6.0.0"
|
||||
image = "0.25.9"
|
||||
regex = "1.12.3"
|
||||
serde = { version = "1.0.218", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
tempfile = "3.25.0"
|
||||
ureq = "2.9"
|
||||
|
||||
132
README.md
132
README.md
@@ -10,6 +10,8 @@
|
||||
<img src="https://img.shields.io/badge/Language-Rust-orange?style=flat-square" alt="Written in Rust" />
|
||||
<img src="https://img.shields.io/badge/Powered_by-Tauri_v2-grey?style=flat-square" alt="Tauri v2" />
|
||||
<img src="https://img.shields.io/badge/Status-Alpha-yellow?style=flat-square" alt="Alpha status" />
|
||||
<img src="https://img.shields.io/github/v/release/spalencsar/deskify?label=Latest%20Release&style=flat-square" alt="Latest release" />
|
||||
<img src="https://img.shields.io/badge/License-MIT-green?style=flat-square" alt="MIT license" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
@@ -25,6 +27,34 @@
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
Two tracks, depending on what you want:
|
||||
|
||||
### Option A: Chromium mode (fastest, best compatibility)
|
||||
|
||||
Requirements: any Chromium-based browser installed (`chromium`, `google-chrome`, `brave`, etc.)
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.local/bin
|
||||
curl -L -o ~/.local/bin/deskify \
|
||||
https://github.com/spalencsar/deskify/releases/latest/download/deskify-linux-x86_64
|
||||
chmod +x ~/.local/bin/deskify
|
||||
|
||||
# If `deskify` is not found, ensure ~/.local/bin is in PATH (common on Ubuntu/Debian):
|
||||
command -v deskify >/dev/null || { echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc; }
|
||||
|
||||
deskify build --url "https://chat.com" --name "Chat" --backend chromium
|
||||
```
|
||||
|
||||
### Option B: Native Tauri mode (system WebView, no Chromium dependency)
|
||||
|
||||
Follow the full install section below (Tauri/WebKitGTK prerequisites), then:
|
||||
|
||||
```bash
|
||||
deskify build --url "https://chat.com" --name "Chat"
|
||||
```
|
||||
|
||||
## Why Deskify Exists
|
||||
|
||||
Web apps are now core tools, but Linux desktops still treat them like second-class citizens.
|
||||
@@ -91,8 +121,10 @@ flowchart TD
|
||||
|
||||
- Requires Tauri/Linux system dependencies to be installed locally before `deskify build`
|
||||
- Generated app build success can vary by distro/system setup (WebKitGTK/Tauri prerequisites)
|
||||
- Some modern sites fail or degrade in the system WebView backend (`tauri`) due to engine/runtime differences
|
||||
- No official cross-platform support (Windows/macOS) yet
|
||||
- GitHub Releases / binary automation for `deskify` itself may lag behind source updates during early MVP
|
||||
- DRM/protected-media services may not work reliably in the system WebView backend even if they work in a full browser (depends on WebView/DRM support)
|
||||
|
||||
## Where Deskify Is Going
|
||||
|
||||
@@ -115,7 +147,7 @@ flowchart TD
|
||||
A --> C[App config files]
|
||||
A --> D[Icons + .desktop entries]
|
||||
C --> E[apps/chatgpt.json]
|
||||
C --> F[apps/netflix.json]
|
||||
C --> F[apps/home-assistant.json]
|
||||
B --> G[Load app config at launch]
|
||||
G --> H[Open site in system webview]
|
||||
D --> I[Linux app menu integration]
|
||||
@@ -143,6 +175,25 @@ The table above covers the technical tradeoffs in more detail. In practice, `des
|
||||
|
||||
## 🚀 Installation
|
||||
|
||||
### Option A: Install a prebuilt binary (recommended)
|
||||
|
||||
Deskify provides Linux release binaries. Download the latest release and install it into `~/.local/bin`:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.local/bin
|
||||
curl -L -o ~/.local/bin/deskify \
|
||||
https://github.com/spalencsar/deskify/releases/latest/download/deskify-linux-x86_64
|
||||
chmod +x ~/.local/bin/deskify
|
||||
deskify --help
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
- The `tauri` backend still requires Tauri/WebKitGTK system dependencies to build wrappers locally.
|
||||
- The `chromium` backend does not require Tauri prerequisites (but it requires an installed Chromium-based browser).
|
||||
|
||||
### Option B: Build from source (Tauri mode)
|
||||
|
||||
### 1. System Dependencies
|
||||
Because `deskify` compiles Tauri applications natively on your machine, you need the standard Tauri prerequisites installed before using it.
|
||||
|
||||
@@ -210,11 +261,25 @@ Once the build finishes, `ChatGPT` will instantly appear in your system Applicat
|
||||
|
||||
`deskify` derives a safe internal ID from the app name (for example, `ChatGPT` becomes `chatgpt`).
|
||||
|
||||
### Backend Modes (`--backend`)
|
||||
|
||||
Deskify supports two backend modes:
|
||||
|
||||
- `tauri` (default): Uses the system WebView (`webkit2gtk` on Linux). Produces small wrappers and strong Linux desktop integration, but some sites may fail due to engine compatibility.
|
||||
- `chromium`: Uses an already installed Chromium-based browser (`chromium`, `google-chrome`, `brave`, etc.) in app mode. Better site compatibility and no local Tauri build, but depends on a browser installed on the system.
|
||||
|
||||
If a site does not work in the default `tauri` backend, try `--backend chromium`.
|
||||
|
||||
Quick decision rule:
|
||||
|
||||
- Start with the default `tauri` backend for small wrappers and native Linux integration.
|
||||
- If the site fails to load, behaves incorrectly, or needs a newer browser engine, rebuild/update with `--backend chromium`.
|
||||
|
||||
#### Advanced Build Options
|
||||
```bash
|
||||
deskify build \
|
||||
--url "https://netflix.com" \
|
||||
--name "Netflix" \
|
||||
--url "https://example.com/dashboard" \
|
||||
--name "Dashboard" \
|
||||
--fullscreen \
|
||||
--user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0 Safari/537.36" \
|
||||
--dark-mode \
|
||||
@@ -239,6 +304,32 @@ Preview the generated Tauri config without building/installing:
|
||||
deskify build --url "https://chat.com" --name "Chat" --print-config
|
||||
```
|
||||
|
||||
Chromium compatibility mode (no local Tauri build):
|
||||
|
||||
```bash
|
||||
deskify build --url "https://mail.proton.me" --name "Proton Mail" --backend chromium
|
||||
```
|
||||
|
||||
Chromium with shared browser profile (uses existing browser profile/session model):
|
||||
|
||||
```bash
|
||||
deskify build \
|
||||
--url "https://app.slack.com" \
|
||||
--name "Slack" \
|
||||
--backend chromium \
|
||||
--profile-scope shared
|
||||
```
|
||||
|
||||
Chromium with explicit browser binary:
|
||||
|
||||
```bash
|
||||
deskify build \
|
||||
--url "https://github.com" \
|
||||
--name "GitHub" \
|
||||
--backend chromium \
|
||||
--browser-bin /usr/bin/brave-browser
|
||||
```
|
||||
|
||||
Preview planned actions only (dry run):
|
||||
|
||||
```bash
|
||||
@@ -251,20 +342,34 @@ deskify build --url "https://chat.com" --name "Chat" --dry-run
|
||||
* `--user-agent <UA>`: Useful to bypass webview restrictions on certain platforms.
|
||||
* `--dark-mode`: Forces the Tauri webview into a dark theme.
|
||||
* `--width <PX>` / `--height <PX>`: Sets the startup resolution.
|
||||
* `--backend <tauri|chromium>`: Choose system WebView (`tauri`) or Chromium app mode (`chromium`).
|
||||
* `--browser-bin <PATH>`: Use a specific Chromium-based browser binary (Chromium backend only).
|
||||
* `--profile-scope <isolated|shared>`: Chromium backend profile behavior (`isolated` creates a per-app profile under `~/.local/share/deskify/profiles/`).
|
||||
* `--print-config`: Prints the generated `tauri.conf.json` and exits.
|
||||
* `--dry-run`: Shows planned actions without building/installing.
|
||||
|
||||
Note for Chromium backend:
|
||||
|
||||
- `--no-decorations` is best-effort and may be ignored by the browser/window manager.
|
||||
- `--width` and `--height` are applied together (`--window-size`) only when both are provided.
|
||||
|
||||
### Managing Apps (`list` & `remove`)
|
||||
You can view all applications generated by `deskify`:
|
||||
```bash
|
||||
deskify list
|
||||
```
|
||||
|
||||
Verbose list (includes URL/backend when metadata is available):
|
||||
|
||||
```bash
|
||||
deskify list --verbose
|
||||
```
|
||||
*Output:*
|
||||
|
||||
```text
|
||||
Installed Deskify Apps:
|
||||
- ChatGPT (Internal ID: chatgpt)
|
||||
- Netflix (Internal ID: netflix)
|
||||
- ChatGPT (Internal ID: chatgpt, Backend: tauri)
|
||||
- Proton Mail (Internal ID: proton-mail, Backend: chromium)
|
||||
```
|
||||
|
||||
To entirely uninstall an app (including the binary, desktop entry, and icons):
|
||||
@@ -282,7 +387,9 @@ Rebuild and reinstall an existing app ID without manually running `remove` + `bu
|
||||
deskify update chat --url "https://chat.com" --name "Chat" --no-decorations
|
||||
```
|
||||
|
||||
Alpha note: `update` currently requires `--url` because Deskify does not persist app URLs/config metadata yet.
|
||||
Deskify persists app metadata under `~/.local/share/deskify/apps/<id>.json`. With persisted metadata, `update` can be used without `--url`.
|
||||
If an older app has no metadata yet, provide `--url` once (or rebuild once) to migrate it.
|
||||
`update <id>` keeps the existing internal ID stable even if you change the display name.
|
||||
|
||||
You can also preview an update:
|
||||
|
||||
@@ -291,6 +398,12 @@ deskify update chat --url "https://chat.com" --dry-run
|
||||
deskify update chat --url "https://chat.com" --print-config
|
||||
```
|
||||
|
||||
Switch an existing app to Chromium compatibility mode while keeping the same internal ID:
|
||||
|
||||
```bash
|
||||
deskify update chat --url "https://chat.com" --name "Chat" --backend chromium
|
||||
```
|
||||
|
||||
### Diagnostics (`doctor`)
|
||||
|
||||
Check local prerequisites and common environment issues (Rust/Cargo, `cargo tauri`, `pkg-config`, directories):
|
||||
@@ -299,6 +412,8 @@ Check local prerequisites and common environment issues (Rust/Cargo, `cargo taur
|
||||
deskify doctor
|
||||
```
|
||||
|
||||
`doctor` also checks whether a Chromium-based browser is available in `PATH` for `--backend chromium`.
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Manual Smoke Test Checklist (Before a Public Release)
|
||||
@@ -323,10 +438,9 @@ Expected: clean validation error and no unintended file deletion.
|
||||
## 🏷️ Versioning & GitHub Releases (MVP)
|
||||
|
||||
- Recommended tag format during MVP: `v0.1.0-alpha.N`
|
||||
- Start with **source-first** releases (repository + tags)
|
||||
- Add automated binary releases later via GitHub Actions
|
||||
- GitHub Releases publish a Linux `deskify` CLI binary on tags (`v*`)
|
||||
|
||||
For the current public alpha, use `v0.1.0-alpha.2` (and continue with `v0.1.0-alpha.N` for follow-up releases).
|
||||
For the latest alpha, see GitHub Releases (and continue with `v0.1.0-alpha.N` for follow-up releases).
|
||||
|
||||
---
|
||||
|
||||
|
||||
22
packaging/PKGBUILD
Normal file
22
packaging/PKGBUILD
Normal file
@@ -0,0 +1,22 @@
|
||||
pkgname=deskify-bin
|
||||
pkgver=0.1.0_alpha.6
|
||||
pkgrel=1
|
||||
pkgdesc="Turn websites into Linux desktop apps (prebuilt binary package)"
|
||||
arch=('x86_64')
|
||||
url="https://github.com/spalencsar/deskify"
|
||||
license=('MIT')
|
||||
depends=('glibc')
|
||||
provides=('deskify')
|
||||
conflicts=('deskify')
|
||||
|
||||
_tag="v0.1.0-alpha.6"
|
||||
source=("deskify::https://github.com/spalencsar/deskify/releases/download/${_tag}/deskify-linux-x86_64"
|
||||
"LICENSE::https://raw.githubusercontent.com/spalencsar/deskify/${_tag}/LICENSE")
|
||||
|
||||
sha256sums=('6962571579b32fcf3119d0d749770b584ce57ef1efe4feea8813314d2ed61d7a'
|
||||
'd4e53458cd2dd461f234186497b6d9b21566c477737a4d31fa6f018ef610486f')
|
||||
|
||||
package() {
|
||||
install -Dm755 "${srcdir}/deskify" "${pkgdir}/usr/bin/deskify"
|
||||
install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
|
||||
}
|
||||
26
packaging/README.md
Normal file
26
packaging/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
## AUR package template (manual)
|
||||
|
||||
This folder contains a minimal `PKGBUILD` template for a future AUR package:
|
||||
|
||||
- `deskify-bin` (prebuilt GitHub Releases binary)
|
||||
|
||||
Notes:
|
||||
|
||||
- Update `_tag` and `pkgver` when you publish a new release tag.
|
||||
- Update `sha256sums` to match the release asset + LICENSE for that tag.
|
||||
|
||||
Local build test:
|
||||
|
||||
```bash
|
||||
cd packaging
|
||||
makepkg -sf
|
||||
```
|
||||
|
||||
To compute sha256 sums for a tag:
|
||||
|
||||
```bash
|
||||
TAG="v0.1.0-alpha.6"
|
||||
curl -fL -o /tmp/deskify-linux-x86_64 "https://github.com/spalencsar/deskify/releases/download/${TAG}/deskify-linux-x86_64"
|
||||
curl -fL -o /tmp/LICENSE "https://raw.githubusercontent.com/spalencsar/deskify/${TAG}/LICENSE"
|
||||
sha256sum /tmp/deskify-linux-x86_64 /tmp/LICENSE
|
||||
```
|
||||
746
src/main.rs
746
src/main.rs
@@ -4,6 +4,7 @@ use directories::BaseDirs;
|
||||
use image::{DynamicImage, ImageFormat};
|
||||
use regex::Regex;
|
||||
use serde_json::{Map, Value, json};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -11,10 +12,29 @@ use std::process::Command;
|
||||
use tempfile::tempdir;
|
||||
use url::Url;
|
||||
|
||||
#[derive(
|
||||
clap::ValueEnum, serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
enum Backend {
|
||||
Tauri,
|
||||
Chromium,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
clap::ValueEnum, serde::Serialize, serde::Deserialize, Debug, Clone, Copy, PartialEq, Eq,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
enum ProfileScope {
|
||||
Isolated,
|
||||
Shared,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct BuildArgs {
|
||||
url: String,
|
||||
name: String,
|
||||
internal_id: String,
|
||||
icon: Option<String>,
|
||||
fullscreen: bool,
|
||||
no_decorations: bool,
|
||||
@@ -22,6 +42,9 @@ struct BuildArgs {
|
||||
width: Option<f64>,
|
||||
height: Option<f64>,
|
||||
dark_mode: bool,
|
||||
backend: Backend,
|
||||
browser_bin: Option<String>,
|
||||
profile_scope: ProfileScope,
|
||||
}
|
||||
|
||||
/// Deskify - Turn any URL into a native Linux desktop application using Tauri.
|
||||
@@ -72,6 +95,18 @@ enum Commands {
|
||||
#[arg(short, long)]
|
||||
dark_mode: bool,
|
||||
|
||||
/// Backend to use for the generated app
|
||||
#[arg(long, value_enum, default_value_t = Backend::Tauri)]
|
||||
backend: Backend,
|
||||
|
||||
/// Path to a Chromium-based browser binary (only for `--backend chromium`)
|
||||
#[arg(long)]
|
||||
browser_bin: Option<String>,
|
||||
|
||||
/// Profile isolation for Chromium backend (only for `--backend chromium`)
|
||||
#[arg(long, value_enum, default_value_t = ProfileScope::Isolated)]
|
||||
profile_scope: ProfileScope,
|
||||
|
||||
/// Print the generated Tauri config JSON and exit
|
||||
#[arg(long)]
|
||||
print_config: bool,
|
||||
@@ -81,7 +116,11 @@ enum Commands {
|
||||
dry_run: bool,
|
||||
},
|
||||
/// List all installed apps created by deskify
|
||||
List,
|
||||
List {
|
||||
/// Show additional metadata (URL, backend) when available
|
||||
#[arg(long)]
|
||||
verbose: bool,
|
||||
},
|
||||
/// Check local prerequisites and environment diagnostics
|
||||
Doctor,
|
||||
/// Remove a specific app by its internal ID
|
||||
@@ -89,14 +128,14 @@ enum Commands {
|
||||
/// The safe name/ID of the app (e.g., "youtube")
|
||||
id: String,
|
||||
},
|
||||
/// Rebuild and reinstall an existing app ID with new settings (alpha: URL is required)
|
||||
/// Rebuild and reinstall an existing app ID with new settings (URL is optional when persisted)
|
||||
Update {
|
||||
/// The existing internal ID (e.g., "chatgpt")
|
||||
id: String,
|
||||
|
||||
/// The URL to wrap (required in current alpha because URLs are not persisted yet)
|
||||
/// The URL to wrap (optional if Deskify has persisted app metadata for this ID)
|
||||
#[arg(short, long)]
|
||||
url: String,
|
||||
url: Option<String>,
|
||||
|
||||
/// Optional new display name (defaults to current desktop entry name or the ID)
|
||||
#[arg(short, long)]
|
||||
@@ -107,12 +146,12 @@ enum Commands {
|
||||
icon: Option<String>,
|
||||
|
||||
/// Launch the application in fullscreen (Kiosk) mode
|
||||
#[arg(short, long)]
|
||||
fullscreen: bool,
|
||||
#[arg(short, long, action = clap::ArgAction::SetTrue)]
|
||||
fullscreen: Option<bool>,
|
||||
|
||||
/// Disable native window decorations (frameless window)
|
||||
#[arg(long)]
|
||||
no_decorations: bool,
|
||||
#[arg(long, action = clap::ArgAction::SetTrue)]
|
||||
no_decorations: Option<bool>,
|
||||
|
||||
/// Set a custom User-Agent string for the webview
|
||||
#[arg(short = 'A', long)]
|
||||
@@ -127,8 +166,20 @@ enum Commands {
|
||||
height: Option<f64>,
|
||||
|
||||
/// Force the webview into Dark Mode
|
||||
#[arg(short, long)]
|
||||
dark_mode: bool,
|
||||
#[arg(short, long, action = clap::ArgAction::SetTrue)]
|
||||
dark_mode: Option<bool>,
|
||||
|
||||
/// Backend to use for the updated app
|
||||
#[arg(long, value_enum)]
|
||||
backend: Option<Backend>,
|
||||
|
||||
/// Path to a Chromium-based browser binary (only for `--backend chromium`)
|
||||
#[arg(long)]
|
||||
browser_bin: Option<String>,
|
||||
|
||||
/// Profile isolation for Chromium backend (only for `--backend chromium`)
|
||||
#[arg(long, value_enum)]
|
||||
profile_scope: Option<ProfileScope>,
|
||||
|
||||
/// Show planned update actions without rebuilding/installing
|
||||
#[arg(long)]
|
||||
@@ -140,6 +191,23 @@ enum Commands {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
|
||||
struct DeskifyAppConfig {
|
||||
schema_version: u32,
|
||||
id: String,
|
||||
name: String,
|
||||
url: String,
|
||||
backend: Backend,
|
||||
browser_bin: Option<String>,
|
||||
profile_scope: ProfileScope,
|
||||
fullscreen: bool,
|
||||
no_decorations: bool,
|
||||
user_agent: Option<String>,
|
||||
width: Option<f64>,
|
||||
height: Option<f64>,
|
||||
dark_mode: bool,
|
||||
}
|
||||
|
||||
fn sanitize_app_id(name: &str) -> String {
|
||||
let re = Regex::new(r"[^a-z0-9-]").unwrap();
|
||||
let lower_name = name.to_lowercase().replace(' ', "-");
|
||||
@@ -163,6 +231,82 @@ fn validate_remove_id(id: &str) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
fn profile_scope_str(scope: ProfileScope) -> &'static str {
|
||||
match scope {
|
||||
ProfileScope::Isolated => "isolated",
|
||||
ProfileScope::Shared => "shared",
|
||||
}
|
||||
}
|
||||
|
||||
fn backend_str(backend: Backend) -> &'static str {
|
||||
match backend {
|
||||
Backend::Tauri => "tauri",
|
||||
Backend::Chromium => "chromium",
|
||||
}
|
||||
}
|
||||
|
||||
fn deskify_data_dir() -> Result<PathBuf> {
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
Ok(base_dirs.data_local_dir().join("deskify"))
|
||||
}
|
||||
|
||||
fn app_config_path(id: &str) -> Result<PathBuf> {
|
||||
validate_remove_id(id)?;
|
||||
Ok(deskify_data_dir()?
|
||||
.join("apps")
|
||||
.join(format!("{}.json", id)))
|
||||
}
|
||||
|
||||
fn read_app_config(id: &str) -> Result<Option<DeskifyAppConfig>> {
|
||||
let path = app_config_path(id)?;
|
||||
if !path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
let content = fs::read_to_string(&path)
|
||||
.with_context(|| format!("Failed to read app config {}", path.display()))?;
|
||||
let cfg: DeskifyAppConfig =
|
||||
serde_json::from_str(&content).context("Failed to parse app config JSON")?;
|
||||
Ok(Some(cfg))
|
||||
}
|
||||
|
||||
fn write_app_config_from_args(args: &BuildArgs) -> Result<()> {
|
||||
validate_remove_id(&args.internal_id)?;
|
||||
let path = app_config_path(&args.internal_id)?;
|
||||
if let Some(dir) = path.parent() {
|
||||
fs::create_dir_all(dir).context("Failed to create app config directory")?;
|
||||
}
|
||||
let cfg = DeskifyAppConfig {
|
||||
schema_version: 1,
|
||||
id: args.internal_id.clone(),
|
||||
name: args.name.clone(),
|
||||
url: args.url.clone(),
|
||||
backend: args.backend,
|
||||
browser_bin: args.browser_bin.clone(),
|
||||
profile_scope: args.profile_scope,
|
||||
fullscreen: args.fullscreen,
|
||||
no_decorations: args.no_decorations,
|
||||
user_agent: args.user_agent.clone(),
|
||||
width: args.width,
|
||||
height: args.height,
|
||||
dark_mode: args.dark_mode,
|
||||
};
|
||||
fs::write(
|
||||
&path,
|
||||
serde_json::to_string_pretty(&cfg).context("Failed to serialize app config")?,
|
||||
)
|
||||
.with_context(|| format!("Failed to write app config {}", path.display()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove_app_config(id: &str) -> Result<()> {
|
||||
let path = app_config_path(id)?;
|
||||
if path.exists() {
|
||||
fs::remove_file(&path).with_context(|| format!("Failed to remove {}", path.display()))?;
|
||||
println!("Removed app config: {:?}", path);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_tauri_config_value(args: &BuildArgs, safe_identifier: &str, bundle_active: bool) -> Value {
|
||||
let mut window_config = Map::<String, Value>::new();
|
||||
window_config.insert("title".to_string(), json!(args.name));
|
||||
@@ -207,27 +351,188 @@ fn build_tauri_config_value(args: &BuildArgs, safe_identifier: &str, bundle_acti
|
||||
})
|
||||
}
|
||||
|
||||
fn desktop_exec_escape(arg: &str) -> String {
|
||||
if arg.is_empty() {
|
||||
return "\"\"".to_string();
|
||||
}
|
||||
|
||||
let needs_quotes = arg
|
||||
.chars()
|
||||
.any(|c| c.is_whitespace() || c == '"' || c == '\\');
|
||||
if !needs_quotes {
|
||||
return arg.to_string();
|
||||
}
|
||||
|
||||
let escaped = arg.replace('\\', "\\\\").replace('"', "\\\"");
|
||||
format!("\"{}\"", escaped)
|
||||
}
|
||||
|
||||
fn desktop_exec_join(args: &[String]) -> String {
|
||||
args.iter()
|
||||
.map(|arg| desktop_exec_escape(arg))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
fn chromium_candidates() -> &'static [&'static str] {
|
||||
&[
|
||||
"google-chrome",
|
||||
"chromium",
|
||||
"chromium-browser",
|
||||
"brave-browser",
|
||||
"vivaldi",
|
||||
"microsoft-edge",
|
||||
]
|
||||
}
|
||||
|
||||
fn find_binary_in_path(name: &str) -> Option<PathBuf> {
|
||||
let path_var = env::var_os("PATH")?;
|
||||
for dir in env::split_paths(&path_var) {
|
||||
let candidate = dir.join(name);
|
||||
if candidate.is_file() {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn resolve_chromium_binary(explicit: Option<&str>) -> Result<PathBuf> {
|
||||
if let Some(path) = explicit {
|
||||
let candidate = PathBuf::from(path);
|
||||
if candidate.is_file() {
|
||||
return Ok(candidate);
|
||||
}
|
||||
return Err(anyhow!(
|
||||
"Specified browser binary does not exist or is not a file: {}",
|
||||
candidate.display()
|
||||
));
|
||||
}
|
||||
|
||||
for candidate in chromium_candidates() {
|
||||
if let Some(path) = find_binary_in_path(candidate) {
|
||||
return Ok(path);
|
||||
}
|
||||
}
|
||||
|
||||
Err(anyhow!(
|
||||
"No Chromium-based browser found in PATH. Install Chromium/Chrome/Brave or use --browser-bin /path/to/browser."
|
||||
))
|
||||
}
|
||||
|
||||
fn chromium_profile_dir(internal_id: &str) -> Result<PathBuf> {
|
||||
validate_remove_id(internal_id)?;
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
Ok(base_dirs
|
||||
.data_local_dir()
|
||||
.join("deskify")
|
||||
.join("profiles")
|
||||
.join(internal_id))
|
||||
}
|
||||
|
||||
fn chromium_window_size_arg(width: Option<f64>, height: Option<f64>) -> Option<String> {
|
||||
match (width, height) {
|
||||
(Some(w), Some(h)) => Some(format!("--window-size={},{}", w as i64, h as i64)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn build_chromium_exec(
|
||||
args: &BuildArgs,
|
||||
browser_path: &Path,
|
||||
profile_dir: Option<&Path>,
|
||||
) -> String {
|
||||
let mut parts = vec![browser_path.display().to_string()];
|
||||
parts.push("--no-first-run".to_string());
|
||||
parts.push("--no-default-browser-check".to_string());
|
||||
parts.push(format!("--class={}", args.internal_id));
|
||||
parts.push(format!("--app={}", args.url));
|
||||
|
||||
if let Some(profile_dir) = profile_dir {
|
||||
parts.push(format!("--user-data-dir={}", profile_dir.display()));
|
||||
}
|
||||
if args.fullscreen {
|
||||
parts.push("--start-fullscreen".to_string());
|
||||
}
|
||||
if let Some(window_size) = chromium_window_size_arg(args.width, args.height) {
|
||||
parts.push(window_size);
|
||||
}
|
||||
if let Some(user_agent) = &args.user_agent {
|
||||
parts.push(format!("--user-agent={}", user_agent));
|
||||
}
|
||||
if args.dark_mode {
|
||||
parts.push("--force-dark-mode".to_string());
|
||||
}
|
||||
|
||||
desktop_exec_join(&parts)
|
||||
}
|
||||
|
||||
fn print_generated_config(args: &BuildArgs) -> Result<()> {
|
||||
let safe_identifier = sanitize_app_id(&args.name);
|
||||
let config = build_tauri_config_value(args, &safe_identifier, false);
|
||||
match args.backend {
|
||||
Backend::Tauri => {
|
||||
let config = build_tauri_config_value(args, &args.internal_id, false);
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&config).context("Failed to serialize generated config")?
|
||||
serde_json::to_string_pretty(&config)
|
||||
.context("Failed to serialize generated config")?
|
||||
);
|
||||
}
|
||||
Backend::Chromium => {
|
||||
let browser = resolve_chromium_binary(args.browser_bin.as_deref())?;
|
||||
let profile_dir = chromium_profile_dir(&args.internal_id)?;
|
||||
let profile_dir = match args.profile_scope {
|
||||
ProfileScope::Isolated => Some(profile_dir),
|
||||
ProfileScope::Shared => None,
|
||||
};
|
||||
let exec = build_chromium_exec(args, &browser, profile_dir.as_deref());
|
||||
let value = json!({
|
||||
"backend": "chromium",
|
||||
"name": args.name,
|
||||
"id": args.internal_id,
|
||||
"url": args.url,
|
||||
"browser": browser.display().to_string(),
|
||||
"profileScope": profile_scope_str(args.profile_scope),
|
||||
"exec": exec,
|
||||
});
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&value)
|
||||
.context("Failed to serialize generated config")?
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_build_plan(action: &str, args: &BuildArgs, existing_id: Option<&str>) {
|
||||
let safe_name = sanitize_app_id(&args.name);
|
||||
let id = existing_id.unwrap_or(&args.internal_id);
|
||||
println!("{} plan:", action);
|
||||
if let Some(id) = existing_id {
|
||||
println!("- Existing app ID: {}", id);
|
||||
}
|
||||
println!("- URL: {}", args.url);
|
||||
println!("- Name: {}", args.name);
|
||||
println!("- New internal ID: {}", safe_name);
|
||||
println!("- Internal ID: {}", id);
|
||||
match args.backend {
|
||||
Backend::Tauri => {
|
||||
println!("- Backend: tauri (system WebView)");
|
||||
println!("- Local build: cargo tauri build (temporary generated project)");
|
||||
println!("- Install targets: local binary + XDG icon + .desktop entry");
|
||||
}
|
||||
Backend::Chromium => {
|
||||
println!("- Backend: chromium (installed browser runtime)");
|
||||
println!("- Local build: none");
|
||||
println!("- Install targets: XDG icon + .desktop entry (+ optional isolated profile)");
|
||||
println!("- Profile scope: {}", profile_scope_str(args.profile_scope));
|
||||
if let Some(path) = &args.browser_bin {
|
||||
println!("- Browser binary: {}", path);
|
||||
} else {
|
||||
println!("- Browser binary: auto-detect from PATH");
|
||||
}
|
||||
if args.no_decorations {
|
||||
println!("- Note: --no-decorations is not guaranteed in Chromium app mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
if args.fullscreen {
|
||||
println!("- Window: fullscreen enabled");
|
||||
}
|
||||
@@ -402,8 +707,6 @@ fn main() {
|
||||
fs::write(src_dir.join("main.rs"), main_rs).context("Failed to write src/main.rs")?;
|
||||
|
||||
// 4. tauri.conf.json
|
||||
let safe_identifier = sanitize_app_id(&args.name);
|
||||
|
||||
let dist_dir = project_dir.join("dist");
|
||||
fs::create_dir_all(&dist_dir).context("Failed to create dist directory")?;
|
||||
fs::write(
|
||||
@@ -417,7 +720,7 @@ fn main() {
|
||||
|
||||
fetch_or_create_icon(&args.url, args.icon.as_ref(), &icons_dir.join("icon.png"))?;
|
||||
|
||||
let tauri_conf = build_tauri_config_value(args, &safe_identifier, false);
|
||||
let tauri_conf = build_tauri_config_value(args, &args.internal_id, false);
|
||||
fs::write(
|
||||
project_dir.join("tauri.conf.json"),
|
||||
serde_json::to_string_pretty(&tauri_conf).context("Failed to serialize tauri.conf.json")?,
|
||||
@@ -466,9 +769,7 @@ fn build_project(project_dir: &Path) -> Result<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
fn install_app(name: &str, bin_path: &Path, project_dir: &Path) -> Result<()> {
|
||||
let safe_name = sanitize_app_id(name);
|
||||
|
||||
fn desktop_paths(internal_id: &str) -> Result<(PathBuf, PathBuf, PathBuf, PathBuf)> {
|
||||
let base_dirs =
|
||||
BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs (e.g. $HOME)"))?;
|
||||
let data_local_dir = base_dirs.data_local_dir(); // Usually ~/.local/share
|
||||
@@ -480,23 +781,46 @@ fn install_app(name: &str, bin_path: &Path, project_dir: &Path) -> Result<()> {
|
||||
base_dirs.home_dir().join(".local/bin")
|
||||
});
|
||||
|
||||
let applications_dir = data_local_dir.join("applications");
|
||||
let icon_dir = data_local_dir.join("icons/hicolor/128x128/apps");
|
||||
let target_bin = executable_dir.join(internal_id);
|
||||
let target_icon = icon_dir.join(format!("{}.png", internal_id));
|
||||
let desktop_file_path = applications_dir.join(format!("{}.desktop", internal_id));
|
||||
|
||||
Ok((
|
||||
target_bin,
|
||||
target_icon,
|
||||
desktop_file_path,
|
||||
data_local_dir.to_path_buf(),
|
||||
))
|
||||
}
|
||||
|
||||
fn install_tauri_app(args: &BuildArgs, bin_path: &Path, project_dir: &Path) -> Result<()> {
|
||||
let (target_bin, target_icon, desktop_file_path, _data_local_dir) =
|
||||
desktop_paths(&args.internal_id)?;
|
||||
let executable_dir = target_bin
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid executable target path"))?;
|
||||
let icon_dir = target_icon
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid icon target path"))?;
|
||||
let applications_dir = desktop_file_path
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid applications target path"))?;
|
||||
|
||||
// 1. Move binary
|
||||
fs::create_dir_all(&executable_dir).context("Failed to create ~/.local/bin directory")?;
|
||||
let target_bin = executable_dir.join(&safe_name);
|
||||
fs::create_dir_all(executable_dir).context("Failed to create ~/.local/bin directory")?;
|
||||
fs::copy(bin_path, &target_bin).context("Failed to move binary to installation directory")?;
|
||||
|
||||
// 2. Install Icon
|
||||
let icon_dir = data_local_dir.join("icons/hicolor/128x128/apps");
|
||||
fs::create_dir_all(&icon_dir).context("Failed to create icons directory")?;
|
||||
let target_icon = icon_dir.join(format!("{}.png", safe_name));
|
||||
fs::create_dir_all(icon_dir).context("Failed to create icons directory")?;
|
||||
let source_icon = project_dir.join("icons/icon.png");
|
||||
if source_icon.exists() {
|
||||
let _ = fs::copy(&source_icon, &target_icon);
|
||||
}
|
||||
|
||||
// 3. Create .desktop file
|
||||
let applications_dir = data_local_dir.join("applications");
|
||||
fs::create_dir_all(&applications_dir).context("Failed to create applications directory")?;
|
||||
fs::create_dir_all(applications_dir).context("Failed to create applications directory")?;
|
||||
|
||||
let desktop_entry = format!(
|
||||
r#"
|
||||
@@ -510,23 +834,107 @@ Terminal=false
|
||||
Type=Application
|
||||
Categories=Network;WebBrowser;
|
||||
X-Deskify-Managed=true
|
||||
X-Deskify-Backend=tauri
|
||||
"#,
|
||||
name,
|
||||
args.name,
|
||||
target_bin.to_string_lossy(),
|
||||
safe_name, // Icon name
|
||||
safe_name // Window class for wayland/x11 proper grouping
|
||||
args.internal_id, // Icon name
|
||||
args.internal_id // Window class for wayland/x11 proper grouping
|
||||
);
|
||||
|
||||
let desktop_file_path = applications_dir.join(format!("{}.desktop", safe_name));
|
||||
fs::write(&desktop_file_path, desktop_entry.trim()).context("Failed to write .desktop file")?;
|
||||
|
||||
println!("App successfully installed!");
|
||||
println!("You can now launch '{}' from your application menu.", name);
|
||||
println!(
|
||||
"You can now launch '{}' from your application menu.",
|
||||
args.name
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_apps() -> Result<()> {
|
||||
fn install_chromium_app(args: &BuildArgs) -> Result<()> {
|
||||
let browser = resolve_chromium_binary(args.browser_bin.as_deref())?;
|
||||
let profile_dir = match args.profile_scope {
|
||||
ProfileScope::Isolated => Some(chromium_profile_dir(&args.internal_id)?),
|
||||
ProfileScope::Shared => None,
|
||||
};
|
||||
|
||||
if matches!((args.width, args.height), (Some(_), None) | (None, Some(_))) {
|
||||
eprintln!(
|
||||
"Warning: Chromium backend requires both --width and --height for --window-size; ignoring partial size override."
|
||||
);
|
||||
}
|
||||
if args.no_decorations {
|
||||
eprintln!(
|
||||
"Warning: --no-decorations is not reliably supported in Chromium app mode and may be ignored."
|
||||
);
|
||||
}
|
||||
|
||||
let (target_bin, target_icon, desktop_file_path, _data_local_dir) =
|
||||
desktop_paths(&args.internal_id)?;
|
||||
let icon_dir = target_icon
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid icon target path"))?;
|
||||
let applications_dir = desktop_file_path
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("Invalid applications target path"))?;
|
||||
|
||||
fs::create_dir_all(icon_dir).context("Failed to create icons directory")?;
|
||||
fs::create_dir_all(applications_dir).context("Failed to create applications directory")?;
|
||||
if let Some(profile_dir) = &profile_dir {
|
||||
fs::create_dir_all(profile_dir).context("Failed to create Chromium profile directory")?;
|
||||
}
|
||||
|
||||
let temp = tempdir().context("Failed to create temporary directory for icon fetch")?;
|
||||
let temp_icon = temp.path().join("icon.png");
|
||||
fetch_or_create_icon(&args.url, args.icon.as_ref(), &temp_icon)?;
|
||||
let _ = fs::copy(&temp_icon, &target_icon);
|
||||
|
||||
let exec = build_chromium_exec(args, &browser, profile_dir.as_deref());
|
||||
let desktop_entry = format!(
|
||||
r#"
|
||||
[Desktop Entry]
|
||||
Version=1.0
|
||||
Name={}
|
||||
Exec={}
|
||||
Icon={}
|
||||
StartupWMClass={}
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Network;WebBrowser;
|
||||
X-Deskify-Managed=true
|
||||
X-Deskify-Backend=chromium
|
||||
X-Deskify-URL={}
|
||||
X-Deskify-ProfileScope={}
|
||||
X-Deskify-Browser={}
|
||||
"#,
|
||||
args.name,
|
||||
exec,
|
||||
args.internal_id,
|
||||
args.internal_id,
|
||||
args.url,
|
||||
profile_scope_str(args.profile_scope),
|
||||
browser.display()
|
||||
);
|
||||
fs::write(&desktop_file_path, desktop_entry.trim()).context("Failed to write .desktop file")?;
|
||||
|
||||
if target_bin.exists() {
|
||||
println!(
|
||||
"Note: existing binary {} left in place (Chromium backend does not use it).",
|
||||
target_bin.display()
|
||||
);
|
||||
}
|
||||
|
||||
println!("App successfully installed (Chromium backend)!");
|
||||
println!(
|
||||
"You can now launch '{}' from your application menu.",
|
||||
args.name
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_apps_with_options(verbose: bool) -> Result<()> {
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
let applications_dir = base_dirs.data_local_dir().join("applications");
|
||||
|
||||
@@ -549,18 +957,48 @@ fn list_apps() -> Result<()> {
|
||||
.and_then(|l| l.strip_prefix("Name="))
|
||||
.unwrap_or("Unknown");
|
||||
|
||||
let exec = content
|
||||
let internal_id = path
|
||||
.file_stem()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("Unknown");
|
||||
let backend = content
|
||||
.lines()
|
||||
.find(|l| l.starts_with("Exec="))
|
||||
.and_then(|l| l.strip_prefix("Exec="))
|
||||
.unwrap_or("Unknown");
|
||||
.find(|l| l.starts_with("X-Deskify-Backend="))
|
||||
.and_then(|l| l.strip_prefix("X-Deskify-Backend="))
|
||||
.unwrap_or("legacy");
|
||||
|
||||
let bin_name = Path::new(exec)
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.unwrap_or("Unknown");
|
||||
|
||||
println!("- {} (Internal ID: {})", name, bin_name);
|
||||
if verbose && validate_remove_id(internal_id).is_ok() {
|
||||
if let Some(cfg) = read_app_config(internal_id)? {
|
||||
println!(
|
||||
"- {} (Internal ID: {}, Backend: {}, URL: {})",
|
||||
name,
|
||||
internal_id,
|
||||
backend_str(cfg.backend),
|
||||
cfg.url
|
||||
);
|
||||
} else {
|
||||
let url = content
|
||||
.lines()
|
||||
.find(|l| l.starts_with("X-Deskify-URL="))
|
||||
.and_then(|l| l.strip_prefix("X-Deskify-URL="));
|
||||
if let Some(url) = url {
|
||||
println!(
|
||||
"- {} (Internal ID: {}, Backend: {}, URL: {})",
|
||||
name, internal_id, backend, url
|
||||
);
|
||||
} else {
|
||||
println!(
|
||||
"- {} (Internal ID: {}, Backend: {})",
|
||||
name, internal_id, backend
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
"- {} (Internal ID: {}, Backend: {})",
|
||||
name, internal_id, backend
|
||||
);
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@@ -573,6 +1011,29 @@ fn list_apps() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn read_desktop_entry_value(id: &str, key: &str) -> Result<Option<String>> {
|
||||
validate_remove_id(id)?;
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
let desktop_path = base_dirs
|
||||
.data_local_dir()
|
||||
.join("applications")
|
||||
.join(format!("{}.desktop", id));
|
||||
if !desktop_path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
let content = fs::read_to_string(&desktop_path)
|
||||
.with_context(|| format!("Failed to read desktop entry {}", desktop_path.display()))?;
|
||||
if !is_deskify_desktop_entry(&content) {
|
||||
return Ok(None);
|
||||
}
|
||||
let prefix = format!("{}=", key);
|
||||
Ok(content
|
||||
.lines()
|
||||
.find(|line| line.starts_with(&prefix))
|
||||
.and_then(|line| line.strip_prefix(&prefix))
|
||||
.map(str::to_string))
|
||||
}
|
||||
|
||||
fn read_installed_app_display_name(id: &str) -> Result<Option<String>> {
|
||||
validate_remove_id(id)?;
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
@@ -653,6 +1114,11 @@ fn run_doctor() -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
match resolve_chromium_binary(None) {
|
||||
Ok(path) => println!("[ok] chromium browser found: {}", path.display()),
|
||||
Err(_) => println!("[warn] no chromium-based browser found in PATH"),
|
||||
}
|
||||
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
let executable_dir = base_dirs
|
||||
.executable_dir()
|
||||
@@ -665,6 +1131,9 @@ fn run_doctor() -> Result<()> {
|
||||
println!("[info] executable dir: {}", executable_dir.display());
|
||||
println!("[info] applications dir: {}", applications_dir.display());
|
||||
println!("[info] icons dir: {}", icons_dir.display());
|
||||
if let Ok(exe) = env::current_exe() {
|
||||
println!("[info] deskify path: {}", exe.display());
|
||||
}
|
||||
|
||||
if failed {
|
||||
Err(anyhow!("Doctor found critical issues"))
|
||||
@@ -675,6 +1144,10 @@ fn run_doctor() -> Result<()> {
|
||||
}
|
||||
|
||||
fn remove_app(safe_name: &str) -> Result<()> {
|
||||
remove_app_with_options(safe_name, true)
|
||||
}
|
||||
|
||||
fn remove_app_with_options(safe_name: &str, remove_profile: bool) -> Result<()> {
|
||||
validate_remove_id(safe_name)?;
|
||||
|
||||
let base_dirs = BaseDirs::new().ok_or_else(|| anyhow!("Could not find system BaseDirs"))?;
|
||||
@@ -716,7 +1189,21 @@ fn remove_app(safe_name: &str) -> Result<()> {
|
||||
println!("Icon not found: {:?}", icon_path);
|
||||
}
|
||||
|
||||
// 4. Remove Chromium profile (optional)
|
||||
let profile_path = data_local_dir.join("deskify/profiles").join(safe_name);
|
||||
if remove_profile {
|
||||
if profile_path.exists() {
|
||||
fs::remove_dir_all(&profile_path).context("Failed to remove Chromium profile")?;
|
||||
println!("Removed Chromium profile: {:?}", profile_path);
|
||||
} else {
|
||||
println!("Chromium profile not found: {:?}", profile_path);
|
||||
}
|
||||
} else if profile_path.exists() {
|
||||
println!("Keeping Chromium profile: {:?}", profile_path);
|
||||
}
|
||||
|
||||
println!("Successfully removed app '{}'.", safe_name);
|
||||
let _ = remove_app_config(safe_name);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -730,6 +1217,8 @@ fn execute_build(args: &BuildArgs, dry_run: bool, print_config: bool) -> Result<
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match args.backend {
|
||||
Backend::Tauri => {
|
||||
println!(
|
||||
"Generating native app '{}' for URL: {}",
|
||||
args.name, args.url
|
||||
@@ -748,8 +1237,20 @@ fn execute_build(args: &BuildArgs, dry_run: bool, print_config: bool) -> Result<
|
||||
}
|
||||
};
|
||||
|
||||
install_app(&args.name, &bin_path, dir.path())?;
|
||||
install_tauri_app(args, &bin_path, dir.path())?;
|
||||
write_app_config_from_args(args)?;
|
||||
Ok(())
|
||||
}
|
||||
Backend::Chromium => {
|
||||
println!(
|
||||
"Installing Chromium app '{}' for URL: {}",
|
||||
args.name, args.url
|
||||
);
|
||||
install_chromium_app(args)?;
|
||||
write_app_config_from_args(args)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_update(id: &str, args: &BuildArgs, dry_run: bool, print_config: bool) -> Result<()> {
|
||||
@@ -769,7 +1270,11 @@ fn execute_update(id: &str, args: &BuildArgs, dry_run: bool, print_config: bool)
|
||||
}
|
||||
|
||||
println!("Updating app '{}' -> '{}' ({})", id, args.name, args.url);
|
||||
remove_app(id)?;
|
||||
let remove_profile = match args.backend {
|
||||
Backend::Chromium => false,
|
||||
Backend::Tauri => true,
|
||||
};
|
||||
remove_app_with_options(id, remove_profile)?;
|
||||
execute_build(args, false, false)
|
||||
}
|
||||
|
||||
@@ -787,12 +1292,17 @@ fn main() -> Result<()> {
|
||||
width,
|
||||
height,
|
||||
dark_mode,
|
||||
backend,
|
||||
browser_bin,
|
||||
profile_scope,
|
||||
print_config,
|
||||
dry_run,
|
||||
} => {
|
||||
let internal_id = sanitize_app_id(&name);
|
||||
let args = BuildArgs {
|
||||
url,
|
||||
name,
|
||||
internal_id,
|
||||
icon,
|
||||
fullscreen,
|
||||
no_decorations,
|
||||
@@ -800,11 +1310,14 @@ fn main() -> Result<()> {
|
||||
width,
|
||||
height,
|
||||
dark_mode,
|
||||
backend,
|
||||
browser_bin,
|
||||
profile_scope,
|
||||
};
|
||||
execute_build(&args, dry_run, print_config)?;
|
||||
}
|
||||
Commands::List => {
|
||||
list_apps()?;
|
||||
Commands::List { verbose } => {
|
||||
list_apps_with_options(verbose)?;
|
||||
}
|
||||
Commands::Doctor => {
|
||||
run_doctor()?;
|
||||
@@ -823,24 +1336,90 @@ fn main() -> Result<()> {
|
||||
width,
|
||||
height,
|
||||
dark_mode,
|
||||
backend,
|
||||
browser_bin,
|
||||
profile_scope,
|
||||
dry_run,
|
||||
print_config,
|
||||
} => {
|
||||
let existing_cfg = read_app_config(&id)?;
|
||||
let resolved_url = if let Some(url) = url {
|
||||
url
|
||||
} else if let Some(cfg) = &existing_cfg {
|
||||
cfg.url.clone()
|
||||
} else if let Some(url) = read_desktop_entry_value(&id, "X-Deskify-URL")? {
|
||||
url
|
||||
} else {
|
||||
return Err(anyhow!(
|
||||
"Missing --url for update. Provide --url or rebuild once with a recent Deskify version so metadata can be persisted."
|
||||
));
|
||||
};
|
||||
|
||||
let resolved_name = if let Some(name) = name {
|
||||
name
|
||||
} else if let Some(cfg) = &existing_cfg {
|
||||
cfg.name.clone()
|
||||
} else {
|
||||
read_installed_app_display_name(&id)?.unwrap_or_else(|| id.clone())
|
||||
};
|
||||
|
||||
let resolved_backend = if let Some(backend) = backend {
|
||||
backend
|
||||
} else if let Some(cfg) = &existing_cfg {
|
||||
cfg.backend
|
||||
} else if let Some(b) = read_desktop_entry_value(&id, "X-Deskify-Backend")? {
|
||||
match b.as_str() {
|
||||
"chromium" => Backend::Chromium,
|
||||
"tauri" => Backend::Tauri,
|
||||
_ => Backend::Tauri,
|
||||
}
|
||||
} else {
|
||||
Backend::Tauri
|
||||
};
|
||||
|
||||
let resolved_profile_scope = if let Some(scope) = profile_scope {
|
||||
scope
|
||||
} else if let Some(cfg) = &existing_cfg {
|
||||
cfg.profile_scope
|
||||
} else {
|
||||
ProfileScope::Isolated
|
||||
};
|
||||
|
||||
let resolved_user_agent = if user_agent.is_some() {
|
||||
user_agent
|
||||
} else {
|
||||
existing_cfg.as_ref().and_then(|c| c.user_agent.clone())
|
||||
};
|
||||
let resolved_width = width.or_else(|| existing_cfg.as_ref().and_then(|c| c.width));
|
||||
let resolved_height = height.or_else(|| existing_cfg.as_ref().and_then(|c| c.height));
|
||||
let resolved_browser_bin =
|
||||
browser_bin.or_else(|| existing_cfg.as_ref().and_then(|c| c.browser_bin.clone()));
|
||||
|
||||
let resolved_fullscreen =
|
||||
fullscreen.unwrap_or(existing_cfg.as_ref().map(|c| c.fullscreen).unwrap_or(false));
|
||||
let resolved_no_decorations = no_decorations.unwrap_or(
|
||||
existing_cfg
|
||||
.as_ref()
|
||||
.map(|c| c.no_decorations)
|
||||
.unwrap_or(false),
|
||||
);
|
||||
let resolved_dark_mode =
|
||||
dark_mode.unwrap_or(existing_cfg.as_ref().map(|c| c.dark_mode).unwrap_or(false));
|
||||
|
||||
let args = BuildArgs {
|
||||
url,
|
||||
url: resolved_url,
|
||||
name: resolved_name,
|
||||
internal_id: id.clone(),
|
||||
icon,
|
||||
fullscreen,
|
||||
no_decorations,
|
||||
user_agent,
|
||||
width,
|
||||
height,
|
||||
dark_mode,
|
||||
fullscreen: resolved_fullscreen,
|
||||
no_decorations: resolved_no_decorations,
|
||||
user_agent: resolved_user_agent,
|
||||
width: resolved_width,
|
||||
height: resolved_height,
|
||||
dark_mode: resolved_dark_mode,
|
||||
backend: resolved_backend,
|
||||
browser_bin: resolved_browser_bin,
|
||||
profile_scope: resolved_profile_scope,
|
||||
};
|
||||
execute_update(&id, &args, dry_run, print_config)?;
|
||||
}
|
||||
@@ -851,7 +1430,11 @@ fn main() -> Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{is_deskify_desktop_entry, sanitize_app_id, validate_remove_id};
|
||||
use super::{
|
||||
Backend, BuildArgs, ProfileScope, build_chromium_exec, chromium_window_size_arg,
|
||||
is_deskify_desktop_entry, sanitize_app_id, validate_remove_id,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn sanitize_app_id_replaces_spaces_and_strips_symbols() {
|
||||
@@ -891,4 +1474,55 @@ mod tests {
|
||||
let content = "[Desktop Entry]\nExec=/usr/bin/firefox\nCategories=Network;WebBrowser;\n";
|
||||
assert!(!is_deskify_desktop_entry(content));
|
||||
}
|
||||
|
||||
fn sample_build_args() -> BuildArgs {
|
||||
BuildArgs {
|
||||
url: "https://chat.com".to_string(),
|
||||
name: "Chat".to_string(),
|
||||
internal_id: "chat".to_string(),
|
||||
icon: None,
|
||||
fullscreen: false,
|
||||
no_decorations: false,
|
||||
user_agent: None,
|
||||
width: None,
|
||||
height: None,
|
||||
dark_mode: false,
|
||||
backend: Backend::Chromium,
|
||||
browser_bin: None,
|
||||
profile_scope: ProfileScope::Isolated,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chromium_window_size_requires_both_dimensions() {
|
||||
assert_eq!(
|
||||
chromium_window_size_arg(Some(1200.0), Some(800.0)).as_deref(),
|
||||
Some("--window-size=1200,800")
|
||||
);
|
||||
assert!(chromium_window_size_arg(Some(1200.0), None).is_none());
|
||||
assert!(chromium_window_size_arg(None, Some(800.0)).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chromium_exec_contains_required_args() {
|
||||
let mut args = sample_build_args();
|
||||
args.fullscreen = true;
|
||||
args.dark_mode = true;
|
||||
args.user_agent = Some("UA Test".to_string());
|
||||
args.width = Some(1280.0);
|
||||
args.height = Some(720.0);
|
||||
let exec = build_chromium_exec(
|
||||
&args,
|
||||
Path::new("/usr/bin/chromium"),
|
||||
Some(Path::new("/tmp/profile")),
|
||||
);
|
||||
assert!(exec.contains("/usr/bin/chromium"));
|
||||
assert!(exec.contains("--app=https://chat.com"));
|
||||
assert!(exec.contains("--class=chat"));
|
||||
assert!(exec.contains("--user-data-dir=/tmp/profile"));
|
||||
assert!(exec.contains("--start-fullscreen"));
|
||||
assert!(exec.contains("--window-size=1280,720"));
|
||||
assert!(exec.contains("--force-dark-mode"));
|
||||
assert!(exec.contains("--user-agent="));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user