Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions packages/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogResult};
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
use tauri_plugin_store::StoreExt;
use tokio::sync::oneshot;
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
use tokio::sync::{mpsc, oneshot};

use crate::window_customizer::PinchZoomDisablePlugin;

const SETTINGS_STORE: &str = "opencode.settings.dat";
const DEFAULT_SERVER_URL_KEY: &str = "defaultServerUrl";

fn window_state_flags() -> StateFlags {
StateFlags::all() - StateFlags::DECORATIONS
}

#[derive(Clone, serde::Serialize, specta::Type)]
struct ServerReadyData {
url: String,
Expand Down Expand Up @@ -293,10 +298,7 @@ pub fn run() {
.plugin(tauri_plugin_os::init())
.plugin(
tauri_plugin_window_state::Builder::new()
.with_state_flags(
tauri_plugin_window_state::StateFlags::all()
- tauri_plugin_window_state::StateFlags::DECORATIONS,
)
.with_state_flags(window_state_flags())
.build(),
)
.plugin(tauri_plugin_store::Builder::new().build())
Expand Down Expand Up @@ -365,6 +367,8 @@ pub fn run() {

let window = window_builder.build().expect("Failed to create window");

setup_window_state_listener(&app, &window);

#[cfg(windows)]
let _ = window.create_overlay_titlebar();

Expand Down Expand Up @@ -560,3 +564,34 @@ async fn spawn_local_server(
}
}
}

fn setup_window_state_listener(app: &tauri::AppHandle, window: &tauri::WebviewWindow) {
let (tx, mut rx) = mpsc::channel::<()>(1);

window.on_window_event(move |event| {
if !matches!(event, WindowEvent::Moved(_) | WindowEvent::Resized(_)) {
return;
}
let _ = tx.try_send(());
});

tauri::async_runtime::spawn({
let app = app.clone();

async move {
let save = || {
let handle = app.clone();
let app = app.clone();
let _ = handle.run_on_main_thread(move || {
let _ = app.save_window_state(window_state_flags());
});
};

while rx.recv().await.is_some() {
tokio::time::sleep(Duration::from_millis(200)).await;

save();
}
}
});
}
4 changes: 2 additions & 2 deletions packages/desktop/src-tauri/src/window_customizer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use tauri::{plugin::Plugin, Manager, Runtime, Window};
use tauri::{Manager, Runtime, Window, plugin::Plugin};

pub struct PinchZoomDisablePlugin;

Expand All @@ -21,8 +21,8 @@ impl<R: Runtime> Plugin<R> for PinchZoomDisablePlugin {
let _ = webview_window.with_webview(|_webview| {
#[cfg(target_os = "linux")]
unsafe {
use gtk::glib::ObjectExt;
use gtk::GestureZoom;
use gtk::glib::ObjectExt;
use webkit2gtk::glib::gobject_ffi;

if let Some(data) = _webview.inner().data::<GestureZoom>("wk-view-zoom-gesture") {
Expand Down
Loading