дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
Порівняти коміти
3
Коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
d6288ecb85 | ||
|
|
67cad01ba7 | ||
|
|
ad92b1577f |
No files matched your search
Створено
+39
-35
@@ -4038,7 +4038,7 @@ checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "ide-agent"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4061,7 +4061,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-analysis"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ast-grep-core",
|
||||
"ide-core",
|
||||
@@ -4075,7 +4075,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-build"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
@@ -4090,7 +4090,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-clipboard"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"objc2 0.6.5",
|
||||
"objc2-app-kit 0.3.2",
|
||||
@@ -4099,7 +4099,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-core"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4115,7 +4115,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-coverage"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4129,7 +4129,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-dap"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-jsonrpc",
|
||||
@@ -4147,7 +4147,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-db"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"bb8",
|
||||
"dirs 6.0.0",
|
||||
@@ -4169,7 +4169,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-docker"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"libc",
|
||||
@@ -4183,7 +4183,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-fonts"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-text",
|
||||
@@ -4194,7 +4194,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-github"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-vcs",
|
||||
@@ -4208,7 +4208,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-host"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
@@ -4253,7 +4253,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-http"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"parking_lot",
|
||||
@@ -4271,7 +4271,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-index"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4293,7 +4293,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-jsonrpc"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"futures",
|
||||
@@ -4309,7 +4309,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-language"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"criterion",
|
||||
@@ -4364,7 +4364,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-lsp"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"futures",
|
||||
@@ -4388,7 +4388,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-notebook"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"ide-core",
|
||||
@@ -4411,7 +4411,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-plugin"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
@@ -4429,7 +4429,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-profiler"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-run",
|
||||
@@ -4442,7 +4442,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-remote"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"globset",
|
||||
"ide-core",
|
||||
@@ -4459,7 +4459,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-run"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4482,7 +4482,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-sdk"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"ide-core",
|
||||
@@ -4501,7 +4501,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-search"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"globset",
|
||||
@@ -4521,7 +4521,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-spell"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"parking_lot",
|
||||
@@ -4534,7 +4534,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-ssh"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dirs 6.0.0",
|
||||
"flate2",
|
||||
@@ -4553,7 +4553,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-syntax"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"ide-language",
|
||||
@@ -4568,7 +4568,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-terminal"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"libc",
|
||||
@@ -4581,7 +4581,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-text"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"ide-core",
|
||||
@@ -4593,7 +4593,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-tools"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"hex",
|
||||
@@ -4614,7 +4614,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vcs"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"encoding_rs",
|
||||
@@ -4633,7 +4633,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-vfs"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"chardetng",
|
||||
"dunce",
|
||||
@@ -4655,7 +4655,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-web"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"ide-core",
|
||||
"open",
|
||||
@@ -4671,7 +4671,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ide-workspace"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"dunce",
|
||||
@@ -6141,9 +6141,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "openidea"
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"block2 0.6.2",
|
||||
"dirs 6.0.0",
|
||||
"dunce",
|
||||
"ide-agent",
|
||||
@@ -6180,6 +6181,9 @@ dependencies = [
|
||||
"ide-vfs",
|
||||
"ide-web",
|
||||
"ide-workspace",
|
||||
"objc2 0.6.5",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-foundation 0.3.2",
|
||||
"parking_lot",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
||||
members = ["crates/*", "src-tauri"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.31"
|
||||
version = "0.1.32"
|
||||
edition = "2024"
|
||||
rust-version = "1.96"
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -915,7 +915,11 @@ impl Session {
|
||||
} else {
|
||||
"end_turn"
|
||||
};
|
||||
finished = st.turn.take().map(|t| (t, TurnEnd::Stop(stop)));
|
||||
finished = st.turn.take().map(|mut t| {
|
||||
// Claude Code reports a turn that failed as cancelled here.
|
||||
let failure = t.failure.take().filter(|_| !t.cancelled);
|
||||
(t, failure.unwrap_or(TurnEnd::Stop(stop)))
|
||||
});
|
||||
}
|
||||
}
|
||||
"assistant" if msg.get("parent_tool_use_id").is_none_or(Value::is_null) => {
|
||||
@@ -1139,7 +1143,8 @@ where
|
||||
/// Whether `result` ends `turn`: it answers the turn's last message, or (stopped) any of
|
||||
/// its messages, or names none (the CLI's own error before the turn began).
|
||||
fn belongs(turn: &Turn, result: &Value) -> bool {
|
||||
if result.get("origin").is_some_and(|o| !o.is_null()) {
|
||||
// Prompts are sent with the origin `human`, and their results echo it.
|
||||
if result.get("origin").is_some_and(|o| !o.is_null() && o.get("kind").and_then(Value::as_str) != Some("human")) {
|
||||
return false;
|
||||
}
|
||||
let mut uuids = strings(result.get("user_message_uuids"));
|
||||
|
||||
@@ -738,6 +738,50 @@ async fn a_stop_ahead_of_its_prompt_cancels_it() {
|
||||
assert!(cli.sent.lock()[0].iter().all(|m| m["type"] != "user"), "nothing was sent");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_failed_turn_reports_its_failure() {
|
||||
let text = "Failed to authenticate: OAuth session expired and could not be refreshed";
|
||||
let lifecycle = |uuid: &str, state: &str| {
|
||||
Frame::Cli(json!({ "type": "command_lifecycle", "command_uuid": uuid, "state": state }))
|
||||
};
|
||||
let result = |uuid: &str| {
|
||||
Frame::Cli(json!({
|
||||
"type": "result", "subtype": "success", "is_error": true, "result": text, "stop_reason": "stop_sequence",
|
||||
"terminal_reason": "api_error", "origin": { "kind": "human" }, "user_message_uuids": [uuid],
|
||||
}))
|
||||
};
|
||||
// As Claude Code sends it, and with the turn's end ahead of its result.
|
||||
for lifecycle_first in [false, true] {
|
||||
let mut process = load_fixture("simple").remove(0);
|
||||
process.truncate(6);
|
||||
let Some(Frame::Shim(prompt)) = process.last() else { panic!("the fixture's prompt") };
|
||||
let uuid = prompt["uuid"].as_str().unwrap().to_owned();
|
||||
process.push(Frame::Cli(json!({
|
||||
"type": "assistant", "error": "authentication_failed", "parent_tool_use_id": null,
|
||||
"message": { "id": "m", "model": "<synthetic>", "content": [{ "type": "text", "text": text }] },
|
||||
})));
|
||||
if lifecycle_first {
|
||||
process.extend([lifecycle(&uuid, "cancelled"), result(&uuid)]);
|
||||
} else {
|
||||
process.extend([result(&uuid), lifecycle(&uuid, "cancelled")]);
|
||||
}
|
||||
let cli = Arc::new(Replay {
|
||||
processes: Mutex::new(VecDeque::from([process])),
|
||||
sent: Arc::default(),
|
||||
launched: Mutex::default(),
|
||||
errors: Arc::default(),
|
||||
});
|
||||
let (dir, cwd) = (tempfile::tempdir().unwrap(), tempfile::tempdir().unwrap());
|
||||
let h =
|
||||
Harness::connect(cli.clone(), dir.path().into(), dir.path().join("p"), cwd.path().into(), Vec::new()).await;
|
||||
let s = h.new_session().await;
|
||||
let Err(RpcError::Server { message, .. }) = h.prompt(&s, "hi").await else {
|
||||
panic!("the turn should fail (lifecycle first: {lifecycle_first})");
|
||||
};
|
||||
assert_eq!(message, format!("Claude Code authentication failed: {text}"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Fork and undo against the real CLI, across connections, in a symlinked directory
|
||||
/// (macOS `/tmp`).
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
@@ -829,6 +873,7 @@ fn which_result_ends_a_turn() {
|
||||
assert!(!belongs(&t, &json!({"user_message_uuids": ["a"]})), "a steer superseded it");
|
||||
assert!(belongs(&t, &json!({"subtype": "error_during_execution"})), "names no message");
|
||||
assert!(!belongs(&t, &json!({"origin": {"kind": "task-notification"}})), "Claude Code's own turn");
|
||||
assert!(belongs(&t, &json!({"origin": {"kind": "human"}, "user_message_uuids": ["b"]})), "the prompt's own result");
|
||||
assert!(belongs(&turn(&["a", "b"], true), &json!({"user_message_uuids": ["a"]})));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "openidea",
|
||||
"private": true,
|
||||
"description": "An open-source IDE inspired by IntelliJ IDEA",
|
||||
"version": "0.1.31",
|
||||
"version": "0.1.32",
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -69,3 +69,9 @@ ide-tools = { path = "../crates/ide-tools" }
|
||||
ide-plugin = { path = "../crates/ide-plugin" }
|
||||
ide-docker = { path = "../crates/ide-docker" }
|
||||
ide-github = { path = "../crates/ide-github" }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
block2 = "0.6"
|
||||
objc2 = "0.6"
|
||||
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSButton", "NSResponder", "NSView", "NSWindow"] }
|
||||
objc2-foundation = { version = "0.3", default-features = false, features = ["std", "block2", "NSNotification", "NSOperation", "NSString"] }
|
||||
@@ -356,6 +356,7 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
|
||||
window::window_open_settings,
|
||||
window::window_cycle,
|
||||
window::window_toggle_fullscreen,
|
||||
window::window_set_titlebar_height,
|
||||
window::window_take_launch,
|
||||
window::window_close_context,
|
||||
window::window_open_projects,
|
||||
|
||||
@@ -102,6 +102,20 @@ pub fn window_toggle_fullscreen(window: WebviewWindow) -> IdeResult<bool> {
|
||||
Ok(on)
|
||||
}
|
||||
|
||||
/// Height of the web title bar in native logical pixels (CSS height × IDE zoom).
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn window_set_titlebar_height(window: WebviewWindow, height: f64) -> IdeResult<()> {
|
||||
if !height.is_finite() || !(1.0..=1000.0).contains(&height) {
|
||||
return Err(IdeError::invalid("invalid title bar height"));
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
crate::titlebar::set_height(&window, height).map_err(|e| IdeError::internal(e.to_string()))?;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let _ = window;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// What this window was opened for (taken once).
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
|
||||
@@ -13,6 +13,8 @@ mod remote_dev;
|
||||
|
||||
mod state;
|
||||
mod theme_frame;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod titlebar;
|
||||
mod window_groups;
|
||||
mod windows;
|
||||
|
||||
@@ -138,6 +140,8 @@ pub fn run() {
|
||||
}
|
||||
}
|
||||
tauri::WindowEvent::Destroyed => {
|
||||
#[cfg(target_os = "macos")]
|
||||
titlebar::forget(window);
|
||||
window_groups::destroyed(window.app_handle(), window.label());
|
||||
if let Some(settings) = window.app_handle().get_webview_window(&windows::settings_label(window.label())) {
|
||||
let _ = settings.destroy();
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
//! Keep the native window buttons aligned with the web toolbar, in AppKit points.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
use block2::RcBlock;
|
||||
use objc2::rc::Retained;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_app_kit::{NSWindow, NSWindowButton, NSWindowDidUpdateNotification, NSWindowStyleMask};
|
||||
use objc2_foundation::{NSNotificationCenter, NSObjectProtocol, NSPoint};
|
||||
|
||||
struct Titlebar {
|
||||
height: Rc<Cell<f64>>,
|
||||
observer: Retained<ProtocolObject<dyn NSObjectProtocol>>,
|
||||
}
|
||||
|
||||
impl Drop for Titlebar {
|
||||
fn drop(&mut self) {
|
||||
unsafe { NSNotificationCenter::defaultCenter().removeObserver((*self.observer).as_ref()) };
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static TITLEBARS: RefCell<HashMap<String, Titlebar>> = RefCell::default();
|
||||
}
|
||||
|
||||
pub fn set_height(window: &tauri::WebviewWindow, height: f64) -> tauri::Result<()> {
|
||||
let label = window.label().to_owned();
|
||||
// with_webview runs on the AppKit thread; the observer is also delivered there.
|
||||
window.with_webview(move |webview| unsafe {
|
||||
let native = &*webview.ns_window().cast::<NSWindow>();
|
||||
TITLEBARS.with_borrow_mut(|bars| {
|
||||
let bar = bars.entry(label).or_insert_with(|| {
|
||||
let height = Rc::new(Cell::new(height));
|
||||
let current = height.clone();
|
||||
let pointer = native as *const NSWindow;
|
||||
let block = RcBlock::new(move |_| center_buttons(&*pointer, current.get()));
|
||||
let observer = NSNotificationCenter::defaultCenter().addObserverForName_object_queue_usingBlock(
|
||||
Some(NSWindowDidUpdateNotification),
|
||||
Some(native),
|
||||
None,
|
||||
&block,
|
||||
);
|
||||
Titlebar { height, observer }
|
||||
});
|
||||
bar.height.set(height);
|
||||
center_buttons(native, height);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
pub fn forget(window: &tauri::Window) {
|
||||
let label = window.label().to_owned();
|
||||
let _ = window.run_on_main_thread(move || {
|
||||
TITLEBARS.with_borrow_mut(|bars| bars.remove(&label));
|
||||
});
|
||||
}
|
||||
|
||||
unsafe fn center_buttons(window: &NSWindow, height: f64) {
|
||||
// Fullscreen uses AppKit's own revealable title bar.
|
||||
if window.styleMask().contains(NSWindowStyleMask::FullScreen) {
|
||||
return;
|
||||
}
|
||||
let Some(close) = window.standardWindowButton(NSWindowButton::CloseButton) else { return };
|
||||
let Some(minimize) = window.standardWindowButton(NSWindowButton::MiniaturizeButton) else { return };
|
||||
let spacing = minimize.frame().origin.x - close.frame().origin.x;
|
||||
let Some(container) = (unsafe { close.superview().and_then(|view| view.superview()) }) else { return };
|
||||
let Some(content) = window.contentView() else { return };
|
||||
let mut frame = container.frame();
|
||||
let top = frame.origin.y + frame.size.height;
|
||||
if (frame.size.height - height).abs() > 0.01 {
|
||||
frame.size.height = height;
|
||||
frame.origin.y = top - height;
|
||||
container.setFrame(frame);
|
||||
}
|
||||
let bounds = content.bounds();
|
||||
let y = bounds.origin.y + if content.isFlipped() { height / 2.0 } else { bounds.size.height - height / 2.0 };
|
||||
for (index, kind) in [NSWindowButton::CloseButton, NSWindowButton::MiniaturizeButton, NSWindowButton::ZoomButton]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let Some(button) = window.standardWindowButton(kind) else { continue };
|
||||
let Some(parent) = (unsafe { button.superview() }) else { continue };
|
||||
let center = parent.convertPoint_fromView(NSPoint::new(0.0, y), Some(&content));
|
||||
let frame = button.frame();
|
||||
let x = 14.0 + index as f64 * spacing;
|
||||
let target = center.y - frame.size.height / 2.0;
|
||||
if (frame.origin.x - x).abs() > 0.01 || (frame.origin.y - target).abs() > 0.01 {
|
||||
button.setFrameOrigin(NSPoint::new(x, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,6 +297,8 @@ fn build_project_window(app: &AppHandle, mut config: WindowConfig) -> IdeResult<
|
||||
.and_then(|b| b.build())
|
||||
.map_err(|e| IdeError::internal(format!("cannot create window: {e}")))?;
|
||||
apply_zoom(app, &window);
|
||||
#[cfg(target_os = "macos")]
|
||||
align_titlebar(app, &window);
|
||||
// "Sync with OS" needs the OS mode, known once the window exists.
|
||||
if let Some(a) = appearance.filter(|a| plugin_frame.is_none() && (a.sync_with_os || a.theme == "system"))
|
||||
&& window.theme().is_ok_and(|t| t == Theme::Dark)
|
||||
@@ -317,6 +319,20 @@ fn apply_zoom(app: &AppHandle, window: &WebviewWindow) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Aligns the native window buttons before the page reports its title bar height,
|
||||
/// so they don't visibly move once it loads.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn align_titlebar(app: &AppHandle, window: &WebviewWindow) {
|
||||
// `--h-titlebar` in tokens.css.
|
||||
const HEIGHT: f64 = 40.0;
|
||||
const COMPACT_HEIGHT: f64 = 32.0;
|
||||
let Some(a) = app.try_state::<AppState>().map(|s| s.global_settings.effective().appearance) else {
|
||||
return;
|
||||
};
|
||||
let height = if a.compact_mode { COMPACT_HEIGHT } else { HEIGHT };
|
||||
let _ = crate::titlebar::set_height(window, height * f64::from(a.zoom.clamp(50, 300)) / 100.0);
|
||||
}
|
||||
|
||||
/// The first window (`create: false` in tauri.conf.json so it can take the theme's colour).
|
||||
pub fn create_main_window(app: &AppHandle) -> IdeResult<WebviewWindow> {
|
||||
build_project_window(app, window_config(app)?)
|
||||
@@ -747,6 +763,8 @@ pub fn open_settings_window(
|
||||
.and_then(|b| b.build())
|
||||
.map_err(|e| IdeError::internal(format!("cannot create settings window: {e}")))?;
|
||||
apply_zoom(app, &window);
|
||||
#[cfg(target_os = "macos")]
|
||||
align_titlebar(app, &window);
|
||||
// Restore runs during build; fit its size to the parent's current display before showing.
|
||||
#[cfg(target_os = "macos")]
|
||||
if let Err(e) = fit_settings_window(&window, &parent) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "OpenIDEA",
|
||||
"version": "0.1.31",
|
||||
"version": "0.1.32",
|
||||
"identifier": "ai.l0ng.openidea",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
@@ -21,10 +21,6 @@
|
||||
"minHeight": 500,
|
||||
"titleBarStyle": "Overlay",
|
||||
"hiddenTitle": true,
|
||||
"trafficLightPosition": {
|
||||
"x": 14,
|
||||
"y": 22
|
||||
},
|
||||
"backgroundColor": "#E9EAEE",
|
||||
"dragDropEnabled": true
|
||||
}
|
||||
|
||||
@@ -720,6 +720,8 @@ export const commands = {
|
||||
/** Focuses the next / previous window (⌘` / ⇧⌘`). */
|
||||
windowCycle: (forward: boolean) => __TAURI_INVOKE<void>("window_cycle", { forward }),
|
||||
windowToggleFullscreen: () => typedError<boolean, IdeError>(__TAURI_INVOKE("window_toggle_fullscreen")),
|
||||
/** Height of the web title bar in native logical pixels (CSS height × IDE zoom). */
|
||||
windowSetTitlebarHeight: (height: number | null) => typedError<null, IdeError>(__TAURI_INVOKE("window_set_titlebar_height", { height })),
|
||||
/** What this window was opened for (taken once). */
|
||||
windowTakeLaunch: () => __TAURI_INVOKE<{
|
||||
/** Project folder to open. */
|
||||
|
||||
@@ -10,7 +10,7 @@ import { uiFontFamily } from "@/platform/fonts";
|
||||
import { call, commands, isTauri } from "@/platform/ipc";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { setDragRequiresAlt } from "@/ui";
|
||||
import { ZOOM_LIMITS } from "./model/behaviorSchema";
|
||||
import { ZOOM_LIMITS } from "@/platform/zoom";
|
||||
import { DEFAULT_SETTINGS, validateSettings, type ValidSettings } from "./model/schema";
|
||||
|
||||
const FONT_VARS = [
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import { BUILTIN_THEME_IDS, type BuiltinThemeId } from "@/platform/themes";
|
||||
import { ZOOM_LIMITS } from "@/platform/zoom";
|
||||
|
||||
export type Antialiasing = "subpixel" | "greyscale" | "none";
|
||||
export type OpenProjectIn = "ask" | "new" | "same" | "attach";
|
||||
@@ -61,7 +62,6 @@ export interface NotificationsValid {
|
||||
groups: Record<string, NotificationGroupValid>;
|
||||
}
|
||||
|
||||
export const ZOOM_LIMITS = { min: 50, max: 300 } as const;
|
||||
export const IDLE_LIMITS = { min: 1, max: 3600 } as const;
|
||||
|
||||
export const DEFAULT_APPEARANCE_EXTRAS: AppearanceExtras = {
|
||||
|
||||
@@ -11,6 +11,7 @@ import clsx from "clsx";
|
||||
import { shortcutLabel } from "@/platform/keymap";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { isTauri } from "@/platform/ipc";
|
||||
import { ZOOM_LIMITS } from "@/platform/zoom";
|
||||
import { SCHEMES as EDITOR_SCHEMES, listSchemes, customSchemes } from "@/platform/colorScheme";
|
||||
import { formatTimestamp } from "@/platform/dateFormat";
|
||||
import { Checkbox, IconButton, Input, Popup, type SelectOption, T } from "@/ui";
|
||||
@@ -18,7 +19,6 @@ import { NOTIFICATION_GROUPS } from "@/workbench/notificationStore";
|
||||
import { ColorSwatches, NumberInput, Row, SearchLabel, Select, Toggle } from "../components/Form";
|
||||
import { useLabelMatch, useSetting } from "../components/context";
|
||||
import {
|
||||
ZOOM_LIMITS,
|
||||
IDLE_LIMITS,
|
||||
type Antialiasing,
|
||||
type ConcreteTheme,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export const ZOOM_LIMITS = { min: 50, max: 300 } as const;
|
||||
|
||||
/** The IDE zoom in percent that a settings value applies as. */
|
||||
export function clampZoom(value: unknown): number {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return 100;
|
||||
return Math.min(ZOOM_LIMITS.max, Math.max(ZOOM_LIMITS.min, Math.round(value)));
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
}
|
||||
/* Room for the native macOS traffic lights (Overlay title bar). */
|
||||
.overlay {
|
||||
padding-left: 82px;
|
||||
padding-left: max(82px, calc(82px / var(--titlebar-zoom, 1)));
|
||||
}
|
||||
/* Welcome window: plain title on the frame colour with a hairline, like IntelliJ's welcome frame. */
|
||||
.minimal {
|
||||
|
||||
@@ -26,6 +26,7 @@ import { projectInitials } from "./projectColor";
|
||||
import { keymapItems, themeItems, VIEW_MODE_ITEMS } from "./quickSwitch";
|
||||
import { currentThemeId, useThemeOverride } from "./theme";
|
||||
import styles from "./TitleBar.module.css";
|
||||
import { useNativeTitlebar } from "./nativeTitlebar";
|
||||
|
||||
export function orderTitleItems(items: Iterable<TitleItemContribution>) {
|
||||
const all = [...items];
|
||||
@@ -277,12 +278,14 @@ export function TitleBar({
|
||||
const frameless = usePlatform((s) => s.framelessTitleBar);
|
||||
const { map, shown, menu } = useToolbar();
|
||||
const [menuExpanded, setMenuExpanded] = useState(false);
|
||||
const [bar, setBar] = useState<HTMLElement | null>(null);
|
||||
useNativeTitlebar(bar);
|
||||
const className = clsx(styles.bar, overlay && styles.overlay, frameless && styles.frameless);
|
||||
// Distraction Free Mode: the window frame only. Where the title bar carries the
|
||||
// main menu (Windows, Linux) it stays, or nothing would lead back out of the mode.
|
||||
if (bare)
|
||||
return (
|
||||
<header className={className} data-tauri-drag-region data-titlebar="bare">
|
||||
<header ref={setBar} className={className} data-tauri-drag-region data-titlebar="bare">
|
||||
{frameless && (
|
||||
<>
|
||||
<MainMenu />
|
||||
@@ -296,6 +299,7 @@ export function TitleBar({
|
||||
const toolbar = !minimal && !lightEdit;
|
||||
return (
|
||||
<header
|
||||
ref={setBar}
|
||||
className={clsx(className, minimal && styles.minimal, dialog && styles.dialogBar)}
|
||||
data-tauri-drag-region
|
||||
onContextMenu={(e) => {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, renderHook } from "@testing-library/react";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { useProject } from "@/platform/project";
|
||||
import type { Settings } from "@/platform/ipc";
|
||||
import { useNativeTitlebar } from "./nativeTitlebar";
|
||||
|
||||
const { setHeight } = vi.hoisted(() => ({ setHeight: vi.fn().mockResolvedValue({ status: "ok" }) }));
|
||||
vi.mock("@/platform/ipc", async (original) => {
|
||||
const ipc = await original<typeof import("@/platform/ipc")>();
|
||||
return { ...ipc, commands: { ...ipc.commands, windowSetTitlebarHeight: setHeight } };
|
||||
});
|
||||
|
||||
const platform = usePlatform.getState();
|
||||
const project = useProject.getState();
|
||||
let resize: () => void;
|
||||
const disconnect = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
setHeight.mockClear();
|
||||
disconnect.mockClear();
|
||||
usePlatform.setState({ overlayTitleBar: true });
|
||||
vi.stubGlobal(
|
||||
"ResizeObserver",
|
||||
class {
|
||||
constructor(callback: () => void) {
|
||||
resize = callback;
|
||||
}
|
||||
observe() {}
|
||||
disconnect = disconnect;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
usePlatform.setState(platform);
|
||||
useProject.setState(project);
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
function zoom(percent: number) {
|
||||
useProject.setState({ settings: { appearance: { zoom: percent } } as Settings });
|
||||
}
|
||||
|
||||
function titlebar(height: number) {
|
||||
const bar = document.createElement("header");
|
||||
const rect = vi.spyOn(bar, "getBoundingClientRect").mockReturnValue(new DOMRect(0, 0, 800, height));
|
||||
return { bar, rect };
|
||||
}
|
||||
|
||||
describe("native title bar alignment", () => {
|
||||
it.each([50, 100, 125, 150, 200, 300])("converts CSS height to AppKit points at %s%%", (percent) => {
|
||||
zoom(percent);
|
||||
const { bar } = titlebar(40);
|
||||
renderHook(() => useNativeTitlebar(bar));
|
||||
expect(setHeight).toHaveBeenLastCalledWith((40 * percent) / 100);
|
||||
});
|
||||
|
||||
it("uses the zoom the webview applies when the setting is out of range", () => {
|
||||
zoom(500);
|
||||
const { bar } = titlebar(40);
|
||||
renderHook(() => useNativeTitlebar(bar));
|
||||
expect(setHeight).toHaveBeenLastCalledWith(120);
|
||||
});
|
||||
|
||||
it("updates when zoom or compact mode changes, and disconnects on unmount", () => {
|
||||
zoom(100);
|
||||
const { bar, rect } = titlebar(40);
|
||||
const { unmount } = renderHook(() => useNativeTitlebar(bar));
|
||||
act(() => zoom(150));
|
||||
expect(setHeight).toHaveBeenLastCalledWith(60);
|
||||
rect.mockReturnValue(new DOMRect(0, 0, 800, 32));
|
||||
act(() => resize());
|
||||
expect(setHeight).toHaveBeenLastCalledWith(48);
|
||||
unmount();
|
||||
expect(disconnect).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("leaves windows without native overlay buttons alone", () => {
|
||||
usePlatform.setState({ overlayTitleBar: false });
|
||||
const { bar } = titlebar(40);
|
||||
renderHook(() => useNativeTitlebar(bar));
|
||||
expect(setHeight).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { useEffect } from "react";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { usePlatform } from "@/platform/platformInfo";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { clampZoom } from "@/platform/zoom";
|
||||
|
||||
export function useNativeTitlebar(bar: HTMLElement | null) {
|
||||
const overlay = usePlatform((s) => s.overlayTitleBar);
|
||||
const zoom = useProject((s) => clampZoom(s.settings?.appearance?.zoom));
|
||||
useEffect(() => {
|
||||
if (!overlay || !bar) return;
|
||||
bar.style.setProperty("--titlebar-zoom", String(zoom / 100));
|
||||
const update = () => {
|
||||
// Webview zoom scales CSS pixels; Retina scale is already handled by AppKit.
|
||||
const height = (bar.getBoundingClientRect().height * zoom) / 100;
|
||||
if (height > 0)
|
||||
void call(commands.windowSetTitlebarHeight(height)).catch((e) =>
|
||||
console.warn("cannot align window buttons", e),
|
||||
);
|
||||
};
|
||||
update();
|
||||
const observer = new ResizeObserver(update);
|
||||
observer.observe(bar);
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
bar.style.removeProperty("--titlebar-zoom");
|
||||
};
|
||||
}, [bar, overlay, zoom]);
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача