forked from tauri-apps/wry
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookies.rs
More file actions
73 lines (63 loc) · 1.8 KB
/
cookies.rs
File metadata and controls
73 lines (63 loc) · 1.8 KB
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
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tao::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
use wry::WebViewBuilder;
fn main() -> wry::Result<()> {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let builder = WebViewBuilder::new().with_url("https://www.httpbin.org/cookies/set?foo=bar");
#[cfg(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
))]
let webview = builder.build(&window)?;
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
let webview = {
use tao::platform::unix::WindowExtUnix;
use wry::WebViewBuilderExtUnix;
let vbox = window.default_vbox().unwrap();
builder.build_gtk(vbox)?
};
webview.set_cookie(
cookie::Cookie::build(("foo1", "bar1"))
.domain("www.httpbin.org")
.path("/")
.secure(true)
.http_only(true)
.max_age(cookie::time::Duration::seconds(10))
.inner(),
)?;
let cookie_deleted = cookie::Cookie::build(("will_be_deleted", "will_be_deleted"));
webview.set_cookie(cookie_deleted.inner())?;
println!("Setting Cookies:");
for cookie in webview.cookies()? {
println!("\t{cookie}");
}
println!("After Deleting:");
webview.delete_cookie(cookie_deleted.inner())?;
for cookie in webview.cookies()? {
println!("\t{cookie}");
}
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
if let Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} = event
{
*control_flow = ControlFlow::Exit;
}
});
}