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() {
|
||||
gtk::init().unwrap();
|
||||
|
||||
let window = Window::new(WindowType::Toplevel);
|
||||
window.connect_delete_event(|_, _| {
|
||||
gtk::main_quit();
|
||||
glib::Propagation::Proceed
|
||||
});
|
||||
let mut args = std::env::args();
|
||||
args.next();
|
||||
|
||||
let webview = WebView::new();
|
||||
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
|
||||
});
|
||||
let args: Vec<_> = args.collect();
|
||||
if args.is_empty() {
|
||||
eprintln!("No URLs provided");
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
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();
|
||||
window.fullscreen();
|
||||
let webview = WebView::new();
|
||||
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();
|
||||
std::thread::spawn(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
sender
|
||||
.send("https://kitchen.pyrocufflink.blue/")
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
});
|
||||
glib::spawn_future_local(async move {
|
||||
let url = receiver.recv().await.unwrap();
|
||||
webview.load_uri(url);
|
||||
});
|
||||
window.add(&webview);
|
||||
|
||||
window.show_all();
|
||||
window.fullscreen();
|
||||
|
||||
eprintln!("Navingating to {url}");
|
||||
webview.load_uri(&url);
|
||||
}
|
||||
|
||||
gtk::main();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user