H6: isolated data directory for dev and live-check instances
`--data-dir DIR` / `LUTRA_DATA_DIR` move settings, the recovery journal, the rendezvous file and the WebView2 user data folder into one directory. `--control PORT` without either uses `<temp>/lutra-control/<port>/`. The SHA-256-checked Phpactor cache stays shared from the user's data dir (`Engine::share_tools_from`). An isolated instance never forwards to or registers as the user's main instance; `rendezvous::dir()` honours `LUTRA_DATA_DIR` after `LUTRA_RENDEZVOUS_DIR`, so the CLI finds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e5891ddeb4
commit
ba70b0f43a
10 changed files with 418 additions and 29 deletions
|
|
@ -6,11 +6,14 @@
|
|||
//! (see [`host`]), opens the project given on the command line, and
|
||||
//! optionally serves the JSON control channel (`--control PORT`). A normal
|
||||
//! start is a single instance (see [`instance`]): a second start forwards
|
||||
//! its path to the running app and exits.
|
||||
//! its path to the running app and exits. A start with `--data-dir`,
|
||||
//! `LUTRA_DATA_DIR` or `--control` keeps its files away from the user's
|
||||
//! (see [`datadir`]).
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod args;
|
||||
mod datadir;
|
||||
mod host;
|
||||
mod instance;
|
||||
mod screenshot;
|
||||
|
|
@ -53,18 +56,27 @@ fn main() -> ExitCode {
|
|||
}
|
||||
|
||||
/// Forwards to a running instance if there is one; otherwise builds the
|
||||
/// Tauri app, starts the engine with the app's config and data directories,
|
||||
/// Tauri app, starts the engine with the app's config and data directories
|
||||
/// (or the isolated data directory, sharing the user's managed tools),
|
||||
/// the host, the control channel and the single-instance listener, and runs
|
||||
/// the event loop. The window is created in the setup hook, which runs once
|
||||
/// the event loop has started. A single-instance listener or rendezvous
|
||||
/// file that cannot be set up is reported and the app runs without it.
|
||||
///
|
||||
/// # Errors
|
||||
/// A message if a running instance refused the forwarded path, Tauri cannot
|
||||
/// build the app or resolve its directories, the engine cannot start, or
|
||||
/// the control port cannot be bound.
|
||||
/// A message if a running instance refused the forwarded path, the
|
||||
/// isolated data directory cannot be created, Tauri cannot build the app or
|
||||
/// resolve its directories, the engine cannot start, or the control port
|
||||
/// cannot be bound.
|
||||
fn run(args: &args::Args) -> Result<(), String> {
|
||||
let instance_dir = instance::rendezvous_dir(args);
|
||||
let isolated = datadir::isolated(args);
|
||||
if let Some(dir) = &isolated {
|
||||
std::fs::create_dir_all(dir)
|
||||
.map_err(|e| format!("cannot create the data directory {}: {e}", dir.display()))?;
|
||||
eprintln!("lutra: data directory {}", dir.display());
|
||||
}
|
||||
let webview_dir = isolated.as_deref().map(datadir::webview_dir);
|
||||
let instance_dir = instance::rendezvous_dir(args, isolated.as_deref());
|
||||
if let Some(dir) = &instance_dir
|
||||
&& instance::forward(dir, args.path.as_deref())?
|
||||
{
|
||||
|
|
@ -90,6 +102,9 @@ fn run(args: &args::Args) -> Result<(), String> {
|
|||
.inner_size(1200.0, 800.0)
|
||||
.min_inner_size(640.0, 400.0)
|
||||
.initialization_script(theme::init_script(&setting));
|
||||
if let Some(dir) = &webview_dir {
|
||||
window = window.data_directory(dir.clone());
|
||||
}
|
||||
if let Some(color) = token_color(&theme::resolve(&setting, None), "bg") {
|
||||
window = window.background_color(color);
|
||||
}
|
||||
|
|
@ -106,7 +121,15 @@ fn run(args: &args::Args) -> Result<(), String> {
|
|||
})
|
||||
.build(tauri::generate_context!())
|
||||
.map_err(|e| e.to_string())?;
|
||||
let mut engine = Engine::with_config(engine_config(&app)?).map_err(|e| e.to_string())?;
|
||||
let user = engine_config(&app)?;
|
||||
let config = match &isolated {
|
||||
Some(dir) => datadir::engine_config(dir),
|
||||
None => user.clone(),
|
||||
};
|
||||
let mut engine = Engine::with_config(config).map_err(|e| e.to_string())?;
|
||||
if isolated.is_some() {
|
||||
engine.share_tools_from(user.data_dir);
|
||||
}
|
||||
engine.allow_downloads().map_err(|e| e.to_string())?;
|
||||
let startup = engine.take_events();
|
||||
let host = Host::new(engine);
|
||||
|
|
@ -141,8 +164,9 @@ fn run(args: &args::Args) -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// The engine directories from Tauri's path resolver: the app config dir
|
||||
/// for settings, the app data dir for the recovery journal.
|
||||
/// The user's engine directories from Tauri's path resolver: the app config
|
||||
/// dir for settings, the app data dir for the recovery journal and the
|
||||
/// managed tools. Resolving creates nothing.
|
||||
///
|
||||
/// # Errors
|
||||
/// A message if the platform has no such directories.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue