Skip to content

Commit e2daa3a

Browse files
feat(Mountain/Window): Explicitly create and customize main window
This commit restructures the main window creation process in Mountain's entrypoint to provide explicit control over window configuration: - **Window Customization**: Integrated `WebviewWindowBuilder` to explicitly create the main window with platform-specific settings (title: "FIDDEE", maximized, decorations disabled for custom title bar, shadow enabled). Added secure context via `use_https_scheme` and enabled browser zoom controls. - **Error Handling**: Added panic-on-error for window creation to ensure critical UI availability. - **Developer Experience**: Automated devtools opening in debug builds for desktop platforms. - **Shutdown Refinement**: Improved graceful shutdown sequence by using `Arc::try_unwrap` for exclusive scheduler access before exit. - **Build Artifacts**: Updated debug/release executables and installers reflect the new window configuration. This change advances the Application Startup workflow by establishing the foundation for Land's custom UI framework in `Sky` while maintaining Mountain's responsibility for native window lifecycle management. The explicit window creation aligns with Tauri best practices and enables future custom title bar integration.
1 parent d276d12 commit e2daa3a

10 files changed

Lines changed: 84 additions & 6 deletions

Source/Binary.rs

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! This file orchestrates the entire application lifecycle. It is responsible
44
//! for setting up logging, initializing the `Echo` scheduler, the core
55
//! `ApplicationState`, the `ApplicationRunTime`, the `Vine` gRPC server, the
6-
//! `Cocoon` sidecar process, and the Tauri application window and event loop.
6+
//! `Cocoon` sidecar process, and explicitly creating and customizing the main
7+
//! Tauri application window before starting the event loop.
78
89
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
910
#![allow(non_snake_case, non_camel_case_types)]
@@ -23,7 +24,8 @@ use crate::{
2324
};
2425

2526
/// Initializes the application's logging infrastructure using `env_logger`.
26-
/// In debug builds, it defaults to a more verbose log level.
27+
/// In debug builds, it defaults to a more verbose log level with colored
28+
/// output.
2729
fn InitializeLogging() {
2830
let LogLevel = if cfg!(debug_assertions) { "debug" } else { "info" };
2931
if std::env::var("RUST_LOG").is_err() {
@@ -63,7 +65,7 @@ pub fn Fn() {
6365
tokio::runtime::Builder::new_multi_thread()
6466
.enable_all()
6567
.build()
66-
.expect("Cannot build.")
68+
.expect("Cannot build Tokio runtime.")
6769
.block_on(async {
6870
InitializeLogging();
6971
info!("[Main] Starting Mountain application...");
@@ -79,6 +81,8 @@ pub fn Fn() {
7981
#[allow(unused_mut)]
8082
let mut Builder = tauri::Builder::default();
8183

84+
// Conditionally enable `any_thread` for the Tauri builder on Windows and Linux.
85+
// This allows Tauri event handlers and commands to run on any thread.
8286
#[cfg(any(windows, target_os = "linux"))]
8387
{
8488
Builder = Builder.any_thread();
@@ -90,6 +94,55 @@ pub fn Fn() {
9094
info!("[Setup] Tauri setup hook initiated.");
9195
let ApplicationHandle = Application.handle().clone();
9296

97+
// --- Main Window Creation ---
98+
// Explicitly build and configure the main application window.
99+
// This logic is integrated from the second example.
100+
let mut WindowBuilder = tauri::WebviewWindowBuilder::new(
101+
Application,
102+
"Application", // Internal label for the window
103+
// URL to load in the webview. `App` variant loads from bundled assets.
104+
tauri::WebviewUrl::App(std::path::PathBuf::from("Application/index.html")),
105+
)
106+
// Use an internal HTTPS scheme (e.g., `https://tauri.localhost`).
107+
// This can enable certain web APIs that require a secure context.
108+
.use_https_scheme(true)
109+
// Allow standard browser zoom hotkeys (Ctrl+Plus, Ctrl+Minus, Ctrl+0).
110+
.zoom_hotkeys_enabled(true)
111+
// Disable browser extension loading in the webview.
112+
.browser_extensions_enabled(false);
113+
114+
// Platform-specific window styling (title, maximization, decorations).
115+
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
116+
{
117+
WindowBuilder = WindowBuilder
118+
.title("FIDDEE") // Set the user-visible window title.
119+
.maximized(true) // Start the window maximized.
120+
// Remove default OS window decorations (title bar, buttons).
121+
// This implies a custom title bar will be implemented in the frontend.
122+
.decorations(false)
123+
.shadow(true); // Enable window shadow.
124+
}
125+
126+
// Build the main window and handle potential errors.
127+
let MainWindow = match WindowBuilder.build() {
128+
Ok(Instance) => Instance,
129+
Err(Error) => {
130+
error!("[Setup] Main application window build failed: {:?}", Error);
131+
// Panic to halt execution as the main UI cannot be displayed.
132+
panic!("Main application window build failed: {:?}", Error);
133+
},
134+
};
135+
136+
// --- Developer Tools (Debug Builds, Desktop Platforms Only) ---
137+
#[cfg(all(debug_assertions, not(any(target_os = "android", target_os = "ios"))))]
138+
{
139+
// Open the webview's developer tools automatically in debug builds.
140+
info!("[Setup] Opening webview developer tools.");
141+
MainWindow.open_devtools();
142+
}
143+
144+
// --- Backend Initialization (continues after window creation) ---
145+
93146
// 2. Create the application Environment and the Echo-powered
94147
// ApplicationRunTime.
95148
let Environment = Arc::new(MountainEnvironment::Create(ApplicationHandle.clone()));
@@ -135,21 +188,22 @@ pub fn Fn() {
135188
.run(move |ApplicationHandle, Event| {
136189
if let RunEvent::ExitRequested { api, .. } = Event {
137190
info!("[RunEvent] Exit requested. Initiating graceful shutdown...");
138-
api.prevent_exit();
191+
api.prevent_exit(); // Prevent the app from closing immediately.
139192
let SchedulerHandle = SchedulerForShutdown.clone();
140193
let ApplicationHandleClone = ApplicationHandle.clone();
141194

142195
// Spawn a new async task to handle the shutdown to avoid blocking the
143196
// Tauri event loop.
144197
tokio::spawn(async move {
145198
info!("[Shutdown] Shutting down Echo scheduler...");
199+
// Attempt to get exclusive ownership of the Arc to shut down the scheduler.
146200
if let Ok(mut Scheduler) = Arc::try_unwrap(SchedulerHandle) {
147201
Scheduler.Stop().await;
148202
} else {
149203
error!("[Shutdown] Could not get exclusive access to scheduler for shutdown.");
150204
}
151205
info!("[Shutdown] Shutdown complete. Exiting application.");
152-
ApplicationHandleClone.exit(0);
206+
ApplicationHandleClone.exit(0); // Now, exit the application.
153207
});
154208
}
155209
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:38bcde7b26199f69f0b6c7099be0c9c0c335e68ee919b054102aeb079a1cfc2c
3+
size 75036672
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ba9935cb194ae7553865aee73c25f22101db933370599ec6969ad56bfd1dae99
3+
size 56561664
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bb83362a5d6041ef4f45a3af30860246e5707b429826587c1bbb5b7029143ab8
3+
size 53533116
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f095bda5f0d9108dca48a017b819f9092cc8e938dca2e5d8c244e0c8960d7db1
3+
size 17323008
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:00487ade58fa8c7d49412c9ceea0d65c4b2f0f2c77d6c14fb6eae6d7e6162d96
3+
size 40628224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:03fe7eacd57664dcd03fce5a76b3f04a71184648e47ef5ee575e1964615e9c60
3+
size 14192640
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bee0651498aabb5a07070a636667bf744affb56985feaacf3aa32fa0f5c85ad8
3+
size 39841661
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:ebf52df13b3e42f0a4f19e113a838cc3f91c90f86701f8b92edd4279a0b4746a
3+
size 13246710

tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,4 @@
146146
"identifier": "land.editor.binary",
147147
"productName": "Mountain",
148148
"version": "0.0.1"
149-
}
149+
}

0 commit comments

Comments
 (0)