Merge pull request #43 from liby/feature/support-get-fullscreen-setting-for-initialization
✨ 支持从 *tauri.config.json* 中读取 `fullscreen` 来做窗口初始化设置
This commit is contained in:
@@ -10,7 +10,7 @@ fn main() -> wry::Result<()> {
|
|||||||
keyboard::KeyCode,
|
keyboard::KeyCode,
|
||||||
menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType},
|
menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType},
|
||||||
platform::macos::WindowBuilderExtMacOS,
|
platform::macos::WindowBuilderExtMacOS,
|
||||||
window::{Window, WindowBuilder, Fullscreen},
|
window::{Fullscreen, Window, WindowBuilder},
|
||||||
},
|
},
|
||||||
webview::WebViewBuilder,
|
webview::WebViewBuilder,
|
||||||
};
|
};
|
||||||
@@ -37,38 +37,41 @@ fn main() -> wry::Result<()> {
|
|||||||
|
|
||||||
menu_bar_menu.add_submenu("App", true, first_menu);
|
menu_bar_menu.add_submenu("App", true, first_menu);
|
||||||
|
|
||||||
let config_file = File::open("./tauri.conf.json").unwrap();
|
|
||||||
let config: Config = serde_json::from_reader(config_file).unwrap();
|
|
||||||
let WindowConfig {
|
let WindowConfig {
|
||||||
url,
|
url,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
resizable,
|
resizable,
|
||||||
transparent,
|
transparent,
|
||||||
|
fullscreen,
|
||||||
..
|
..
|
||||||
} = &config.tauri.windows[0];
|
} = get_windows_config();
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_resizable(*resizable)
|
.with_resizable(resizable)
|
||||||
.with_titlebar_transparent(*transparent)
|
.with_titlebar_transparent(transparent)
|
||||||
|
.with_fullscreen(if fullscreen {
|
||||||
|
Some(Fullscreen::Borderless(None))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
})
|
||||||
.with_fullsize_content_view(true)
|
.with_fullsize_content_view(true)
|
||||||
.with_titlebar_buttons_hidden(false)
|
.with_titlebar_buttons_hidden(false)
|
||||||
.with_title_hidden(true)
|
.with_title_hidden(true)
|
||||||
.with_menu(menu_bar_menu)
|
.with_menu(menu_bar_menu)
|
||||||
.with_inner_size(wry::application::dpi::LogicalSize::new(*width, *height))
|
.with_inner_size(wry::application::dpi::LogicalSize::new(width, height))
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let handler = move |window: &Window, req: String| {
|
let handler = move |window: &Window, req: String| {
|
||||||
if req == "drag_window" {
|
if req == "drag_window" {
|
||||||
let _ = window.drag_window();
|
let _ = window.drag_window();
|
||||||
} else if req == "fullscreen" {
|
} else if req == "fullscreen" {
|
||||||
if window.fullscreen().is_some() {
|
if window.fullscreen().is_some() {
|
||||||
window.set_fullscreen(None);
|
window.set_fullscreen(None);
|
||||||
}else{
|
} else {
|
||||||
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
window.set_fullscreen(Some(Fullscreen::Borderless(None)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,3 +106,10 @@ fn main() -> wry::Result<()> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_windows_config() -> WindowConfig {
|
||||||
|
let config_file = File::open("./tauri.conf.json").unwrap();
|
||||||
|
let config: Config = serde_json::from_reader(config_file).unwrap();
|
||||||
|
|
||||||
|
config.tauri.windows[0].clone()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user