A1: macOS readiness: setup guide, cargo xtask mac-report, unix/macOS fixes
- docs/macos.md: step-by-step setup for a fresh Apple Silicon Mac (Xcode CLT, Homebrew, git, PHP, Composer, Node 22, pnpm, rustup, clone from Forgejo), the machine report, Gatekeeper notes, macOS differences and what Windows cannot check. - cargo xtask mac-report: versions, the gate steps, the bundled-UI desktop build and a self-check over the control channel (project, file, Phpactor, hover, git.status, terminal, screenshot, quit); every step times out and runs in a lutra_proc group; one report.md to send back. - Fixes: macOS native menu (system menus only; Cmd+W stays buffer.close, Cmd+Q runs app.quit), xcap screenshot region in points on macOS (Retina), login shell (-l, /bin/zsh fallback) and LANG for the terminal on macOS, PHP lookup in Homebrew/MacPorts dirs for Finder starts, case-insensitive LSP path mapping on macOS, rendezvous file mode re-set to 0600, CLI-started desktop in its own process group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
da58c83158
commit
1bf69ded55
18 changed files with 1795 additions and 36 deletions
|
|
@ -18,6 +18,7 @@ mod args;
|
|||
mod datadir;
|
||||
mod host;
|
||||
mod instance;
|
||||
mod menu;
|
||||
mod screenshot;
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
|
@ -88,7 +89,7 @@ fn run(args: &args::Args) -> Result<(), String> {
|
|||
let setup_slot = slot.clone();
|
||||
let initial_path = args.path.clone();
|
||||
let focus_on_start = args.control.is_none();
|
||||
let app = tauri::Builder::default()
|
||||
let app = menu::install(tauri::Builder::default())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
engine_execute,
|
||||
|
|
|
|||
102
apps/lutra-desktop/src/menu.rs
Normal file
102
apps/lutra-desktop/src/menu.rs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//! The native menu bar on macOS.
|
||||
//!
|
||||
//! Lutra's own menu lives in the window (the frontend's app menu) on every
|
||||
//! platform. macOS still needs a native menu bar: WKWebView gets Cut, Copy,
|
||||
//! Paste, Select All, Undo and Redo through the Edit menu's key equivalents
|
||||
//! (⌘X, ⌘C, ⌘V, ⌘A, ⌘Z, ⇧⌘Z) and does not handle those keys without it, and
|
||||
//! users expect the app menu (About, Hide, Quit).
|
||||
//!
|
||||
//! Tauri's default macOS menu is not used because its key equivalents take
|
||||
//! keys from Lutra's keymap before the page sees them: "Close Window" (⌘W)
|
||||
//! would close the whole window, and so quit, where Lutra closes the editor
|
||||
//! tab (`buffer.close`), and its "Quit" (⌘Q) would end the process without
|
||||
//! Lutra's `app.quit` (closing terminals, shutting the language server down).
|
||||
//! This menu leaves ⌘W to the page and routes Quit through `app.quit`.
|
||||
//!
|
||||
//! The menu is built with Tauri's cross-platform API, so it compiles and is
|
||||
//! type-checked everywhere; [`install`] adds it on macOS only.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use tauri::menu::{Menu, MenuEvent, MenuItem, PredefinedMenuItem, Submenu};
|
||||
use tauri::{AppHandle, Manager, Runtime};
|
||||
|
||||
use crate::host::Host;
|
||||
|
||||
/// Menu item id of Quit; equal to the engine command it runs.
|
||||
const QUIT_ID: &str = "app.quit";
|
||||
|
||||
/// Adds the native menu and its event handler to `builder` on macOS;
|
||||
/// returns `builder` unchanged elsewhere, where the window has no native
|
||||
/// menu bar.
|
||||
pub fn install<R: Runtime>(builder: tauri::Builder<R>) -> tauri::Builder<R> {
|
||||
if !cfg!(target_os = "macos") {
|
||||
return builder;
|
||||
}
|
||||
builder.menu(build).on_menu_event(handle)
|
||||
}
|
||||
|
||||
/// Builds the menu bar: the app menu, Edit and Window.
|
||||
///
|
||||
/// # Errors
|
||||
/// Tauri's error if a menu or item cannot be created.
|
||||
pub fn build<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Menu<R>> {
|
||||
let quit = MenuItem::with_id(app, QUIT_ID, "Quit Lutra", true, Some("CmdOrCtrl+Q"))?;
|
||||
let app_menu = Submenu::with_items(
|
||||
app,
|
||||
"Lutra",
|
||||
true,
|
||||
&[
|
||||
&PredefinedMenuItem::about(app, Some("About Lutra"), None)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&PredefinedMenuItem::services(app, None)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&PredefinedMenuItem::hide(app, None)?,
|
||||
&PredefinedMenuItem::hide_others(app, None)?,
|
||||
&PredefinedMenuItem::show_all(app, None)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&quit,
|
||||
],
|
||||
)?;
|
||||
let edit = Submenu::with_items(
|
||||
app,
|
||||
"Edit",
|
||||
true,
|
||||
&[
|
||||
&PredefinedMenuItem::undo(app, None)?,
|
||||
&PredefinedMenuItem::redo(app, None)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&PredefinedMenuItem::cut(app, None)?,
|
||||
&PredefinedMenuItem::copy(app, None)?,
|
||||
&PredefinedMenuItem::paste(app, None)?,
|
||||
&PredefinedMenuItem::select_all(app, None)?,
|
||||
],
|
||||
)?;
|
||||
let window = Submenu::with_items(
|
||||
app,
|
||||
"Window",
|
||||
true,
|
||||
&[
|
||||
&PredefinedMenuItem::minimize(app, None)?,
|
||||
&PredefinedMenuItem::maximize(app, None)?,
|
||||
&PredefinedMenuItem::separator(app)?,
|
||||
&PredefinedMenuItem::fullscreen(app, None)?,
|
||||
],
|
||||
)?;
|
||||
Menu::with_items(app, &[&app_menu, &edit, &window])
|
||||
}
|
||||
|
||||
/// Runs the engine command behind a custom menu item. Errors are ignored on
|
||||
/// purpose: `app.quit` cannot fail, and without a host (before setup) the
|
||||
/// app has nothing to shut down, so it exits directly.
|
||||
fn handle<R: Runtime>(app: &AppHandle<R>, event: MenuEvent) {
|
||||
if event.id() != QUIT_ID {
|
||||
return;
|
||||
}
|
||||
match app.try_state::<Arc<Host>>() {
|
||||
Some(host) => {
|
||||
let _ = host.run(QUIT_ID, serde_json::json!({}));
|
||||
}
|
||||
None => app.exit(0),
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,15 @@
|
|||
//! through Tauri and that region of its monitor is captured. The window is
|
||||
//! not focused or raised: anything covering it at that moment shows up in
|
||||
//! the image.
|
||||
//!
|
||||
//! Units: Tauri reports the window in physical pixels. `xcap` takes monitor
|
||||
//! coordinates in physical pixels on Linux but in points (logical pixels)
|
||||
//! on macOS, where a Retina display has two physical pixels per point; the
|
||||
//! window's geometry is converted with its scale factor there
|
||||
//! ([`window_rect`]). The image itself always comes back in physical pixels.
|
||||
//! On macOS the first capture may ask for the Screen Recording permission
|
||||
//! (System Settings ▸ Privacy & Security), granted to the app or terminal
|
||||
//! that started Lutra.
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
|
|
@ -19,14 +28,9 @@ use xcap::image::ImageFormat;
|
|||
/// A message if the window's geometry or monitor cannot be read, the window
|
||||
/// is outside its monitor, or the capture or encoding fails.
|
||||
pub fn capture_png(window: &WebviewWindow) -> Result<Vec<u8>, String> {
|
||||
let pos = window.inner_position().map_err(|e| e.to_string())?;
|
||||
let size = window.inner_size().map_err(|e| e.to_string())?;
|
||||
let centre_x = pos
|
||||
.x
|
||||
.saturating_add(i32::try_from(size.width / 2).unwrap_or(0));
|
||||
let centre_y = pos
|
||||
.y
|
||||
.saturating_add(i32::try_from(size.height / 2).unwrap_or(0));
|
||||
let (x, y, width, height) = window_rect(window)?;
|
||||
let centre_x = x.saturating_add(i32::try_from(width / 2).unwrap_or(0));
|
||||
let centre_y = y.saturating_add(i32::try_from(height / 2).unwrap_or(0));
|
||||
let monitor = Monitor::from_point(centre_x, centre_y)
|
||||
.map_err(|e| format!("cannot find the window's monitor: {e}"))?;
|
||||
let (mx, my) = (
|
||||
|
|
@ -38,10 +42,10 @@ pub fn capture_png(window: &WebviewWindow) -> Result<Vec<u8>, String> {
|
|||
monitor.height().map_err(|e| e.to_string())?,
|
||||
);
|
||||
let region = clip(
|
||||
pos.x.saturating_sub(mx),
|
||||
pos.y.saturating_sub(my),
|
||||
size.width,
|
||||
size.height,
|
||||
x.saturating_sub(mx),
|
||||
y.saturating_sub(my),
|
||||
width,
|
||||
height,
|
||||
mw,
|
||||
mh,
|
||||
)
|
||||
|
|
@ -56,6 +60,40 @@ pub fn capture_png(window: &WebviewWindow) -> Result<Vec<u8>, String> {
|
|||
Ok(png.into_inner())
|
||||
}
|
||||
|
||||
/// The window's client area as `(x, y, width, height)` in the units `xcap`
|
||||
/// uses for monitors on this platform (see the module docs).
|
||||
///
|
||||
/// # Errors
|
||||
/// A message if Tauri cannot report the geometry or the scale factor.
|
||||
fn window_rect(window: &WebviewWindow) -> Result<(i32, i32, u32, u32), String> {
|
||||
let pos = window.inner_position().map_err(|e| e.to_string())?;
|
||||
let size = window.inner_size().map_err(|e| e.to_string())?;
|
||||
if cfg!(target_os = "macos") {
|
||||
let scale = window.scale_factor().map_err(|e| e.to_string())?;
|
||||
Ok(to_points(pos.x, pos.y, size.width, size.height, scale))
|
||||
} else {
|
||||
Ok((pos.x, pos.y, size.width, size.height))
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a rectangle from physical pixels to points for a display with
|
||||
/// `scale` physical pixels per point. A scale that is not a positive finite
|
||||
/// number is treated as 1.
|
||||
fn to_points(x: i32, y: i32, w: u32, h: u32, scale: f64) -> (i32, i32, u32, u32) {
|
||||
let scale = if scale.is_finite() && scale > 0.0 {
|
||||
scale
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let point = |v: f64| (v / scale).round();
|
||||
(
|
||||
point(f64::from(x)) as i32,
|
||||
point(f64::from(y)) as i32,
|
||||
point(f64::from(w)) as u32,
|
||||
point(f64::from(h)) as u32,
|
||||
)
|
||||
}
|
||||
|
||||
/// Clips a rectangle given relative to a monitor's origin to the monitor's
|
||||
/// bounds, returning `(x, y, width, height)` or `None` if nothing is left.
|
||||
fn clip(x: i32, y: i32, w: u32, h: u32, mw: u32, mh: u32) -> Option<(u32, u32, u32, u32)> {
|
||||
|
|
@ -76,7 +114,15 @@ fn clip(x: i32, y: i32, w: u32, h: u32, mw: u32, mh: u32) -> Option<(u32, u32, u
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::clip;
|
||||
use super::{clip, to_points};
|
||||
|
||||
#[test]
|
||||
fn converts_physical_pixels_to_points() {
|
||||
assert_eq!(to_points(200, 100, 2560, 1600, 2.0), (100, 50, 1280, 800));
|
||||
assert_eq!(to_points(-300, 0, 99, 1, 1.5), (-200, 0, 66, 1));
|
||||
assert_eq!(to_points(10, 20, 30, 40, 0.0), (10, 20, 30, 40));
|
||||
assert_eq!(to_points(10, 20, 30, 40, f64::NAN), (10, 20, 30, 40));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clips_to_the_monitor() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue