Show windows from URL command-line arguments
URLs can now be provided as command-line arguments. Each one provided will be opened in a separate window. It will have to be up to the window manager to place each window on a separate monitor, as although there is a `Window::fullscreen_on_monitor` method, it doesn't actually work.
This commit is contained in:
82
src/main.rs
82
src/main.rs
@@ -6,50 +6,52 @@ use webkit2gtk::{WebView, WebViewExt};
|
|||||||
fn main() {
|
fn main() {
|
||||||
gtk::init().unwrap();
|
gtk::init().unwrap();
|
||||||
|
|
||||||
let window = Window::new(WindowType::Toplevel);
|
let mut args = std::env::args();
|
||||||
window.connect_delete_event(|_, _| {
|
args.next();
|
||||||
gtk::main_quit();
|
|
||||||
glib::Propagation::Proceed
|
|
||||||
});
|
|
||||||
|
|
||||||
let webview = WebView::new();
|
let args: Vec<_> = args.collect();
|
||||||
webview.connect_load_changed(|_, load_event| {
|
if args.is_empty() {
|
||||||
eprintln!("Loaded: {load_event:?}");
|
eprintln!("No URLs provided");
|
||||||
});
|
std::process::exit(2);
|
||||||
webview.connect_load_failed(|_, load_event, failing_uri, error| {
|
}
|
||||||
eprintln!(
|
|
||||||
"Load failed: {load_event:?} while loading {failing_uri} - {}",
|
|
||||||
error.message()
|
|
||||||
);
|
|
||||||
false
|
|
||||||
});
|
|
||||||
webview.connect_load_failed_with_tls_errors(|_, host, _, errors| {
|
|
||||||
eprintln!("Load failed: {errors:?} while contacting {host}");
|
|
||||||
false
|
|
||||||
});
|
|
||||||
|
|
||||||
window.add(&webview);
|
for url in args {
|
||||||
|
let window = Window::new(WindowType::Toplevel);
|
||||||
|
window.connect_delete_event(|_, _| {
|
||||||
|
gtk::main_quit();
|
||||||
|
glib::Propagation::Proceed
|
||||||
|
});
|
||||||
|
|
||||||
window.show_all();
|
let webview = WebView::new();
|
||||||
window.fullscreen();
|
webview.connect_load_changed(|_, load_event| {
|
||||||
|
eprintln!("Loaded: {load_event:?}");
|
||||||
|
});
|
||||||
|
webview.connect_load_failed(|_, load_event, failing_uri, error| {
|
||||||
|
eprintln!(
|
||||||
|
"Load failed: {load_event:?} while loading {failing_uri} - {}",
|
||||||
|
error.message()
|
||||||
|
);
|
||||||
|
false
|
||||||
|
});
|
||||||
|
webview.connect_load_failed_with_tls_errors(|_, host, _, errors| {
|
||||||
|
eprintln!("Load failed: {errors:?} while contacting {host}");
|
||||||
|
false
|
||||||
|
});
|
||||||
|
webview.connect_resource_load_started(|_, resource, uri| {
|
||||||
|
eprintln!("Resource load started: {resource:?} {uri:?}");
|
||||||
|
});
|
||||||
|
webview.connect_web_process_terminated(|_, reason| {
|
||||||
|
eprintln!("Web process crashed: {reason:?}");
|
||||||
|
});
|
||||||
|
|
||||||
let (sender, receiver) = async_channel::unbounded();
|
window.add(&webview);
|
||||||
std::thread::spawn(move || {
|
|
||||||
tokio::runtime::Builder::new_current_thread()
|
window.show_all();
|
||||||
.enable_all()
|
window.fullscreen();
|
||||||
.build()
|
|
||||||
.unwrap()
|
eprintln!("Navingating to {url}");
|
||||||
.block_on(async {
|
webview.load_uri(&url);
|
||||||
sender
|
}
|
||||||
.send("https://kitchen.pyrocufflink.blue/")
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
glib::spawn_future_local(async move {
|
|
||||||
let url = receiver.recv().await.unwrap();
|
|
||||||
webview.load_uri(url);
|
|
||||||
});
|
|
||||||
|
|
||||||
gtk::main();
|
gtk::main();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user