blob: 43a9c42e2c98d7e64bc38bdb39e9b8465c5f9a82 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
use std::borrow::Cow;
use std::error::Error;
use reqwest::Url;
use slint::run_event_loop;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::{Window, WindowAttributes, WindowId};
use wry::http::{Response, StatusCode};
use wry::WebViewBuilder;
slint::slint! {
export component HelloWorld inherits Window {
}
}
struct Application {
window: Option<Window>
}
impl ApplicationHandler for Application {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let win = event_loop.create_window(WindowAttributes::default()).unwrap();
win.set_visible(true);
self.window = Some(win);
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
event_loop.exit();
}
WindowEvent::RedrawRequested => {
if let Some(ref window) = self.window {
window.request_redraw();
}
}
_ => { }
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
simple_logger::SimpleLogger::new().env().init().unwrap();
gtk::init()?;
let hw = HelloWorld::new().unwrap();
let wv = WebViewBuilder::new()
.with_url("https://login.live.com/oauth20_authorize.srf?client_id=00000000402b5328&redirect_uri=ms-xal-00000000402b5328://auth&response_type=token&display=touch&scope=service::user.auth.xboxlive.com::MBI_SSL%20offline_access&prompt=select_account")
.with_navigation_handler(|url| {
let mut url = match reqwest::Url::parse(url.as_str()) {
Ok(url) => url,
Err(_) => return true
};
if url.scheme() == "ms-xal-00000000402b5328" {
let fragment = url.fragment().map(|s| s.to_owned());
url.set_query(fragment.as_ref().map(|s| s.as_str()));
url.query_pairs().inspect(|p| println!("{:?}", p)).for_each(drop);
dbg!(url);
return false;
}
true
}).build_as_child(&hw.window().window_handle()).unwrap();
wv.set_visible(true).unwrap();
hw.run().unwrap();
Ok(())
}
|