@@ -9,6 +9,8 @@ use std::fs::metadata;
99use std:: path:: PathBuf ;
1010
1111use std:: process:: Command ;
12+ #[ cfg( target_os = "linux" ) ]
13+ extern crate webkit2gtk;
1214
1315use regex:: Regex ;
1416extern crate percent_encoding;
@@ -105,6 +107,30 @@ fn show_in_folder(path: String) {
105107 }
106108}
107109
110+ #[ tauri:: command]
111+ fn zoom_window ( window : tauri:: Window , scale_factor : f64 ) {
112+ let _ = window. with_webview ( move |webview| {
113+ #[ cfg( target_os = "linux" ) ]
114+ {
115+ // see https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/struct.WebView.html
116+ // and https://docs.rs/webkit2gtk/0.18.2/webkit2gtk/trait.WebViewExt.html
117+ use webkit2gtk:: traits:: WebViewExt ;
118+ webview. inner ( ) . set_zoom_level ( scale_factor) ;
119+ }
120+
121+ #[ cfg( windows) ]
122+ unsafe {
123+ // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html
124+ webview. controller ( ) . SetZoomFactor ( scale_factor) . unwrap ( ) ;
125+ }
126+
127+ #[ cfg( target_os = "macos" ) ]
128+ unsafe {
129+ let ( ) = msg_send ! [ webview. inner( ) , setPageZoom: scale_factor] ;
130+ }
131+ } ) ;
132+ }
133+
108134fn process_window_event ( event : & GlobalWindowEvent ) {
109135 if let tauri:: WindowEvent :: CloseRequested { .. } = event. event ( ) {
110136 // this does nothing and is here if in future you need to persist something on window close.
@@ -170,7 +196,7 @@ fn main() {
170196 . on_window_event ( |event| process_window_event ( & event) )
171197 . invoke_handler ( tauri:: generate_handler![
172198 toggle_devtools, console_log, console_error,
173- _get_windows_drives, _rename_path, show_in_folder] )
199+ _get_windows_drives, _rename_path, show_in_folder, zoom_window ] )
174200 . setup ( |app| {
175201 init:: init_app ( app) ;
176202 Ok ( ( ) )
0 commit comments