Skip to content

Commit 71e0ffe

Browse files
committed
update
1 parent d9168da commit 71e0ffe

File tree

8 files changed

+251
-10
lines changed

8 files changed

+251
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ members = [
1010
#
1111
#
1212
#
13-
# "crates/rs-cms",
1413
"crates/rs-leetcode",
1514
"crates/rs-cli",
1615
"crates/rs-ffi/*",
1716
"crates/rs-os/rs-macos/try-notification",
1817
"crates/rs-os/rs-cross/try-notify",
18+
"crates/rs-gui/try-wry",
1919
# "crates/rs-tonic",
2020
# "crates/rs-tauri-vue/src-tauri",
2121
# "crates/rs-sqlcipher",

Taskfile.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ includes:
3838
dir: ./crates/rs-rpc/rs-volo/
3939
optional: true
4040

41+
gui:
42+
taskfile: ./crates/rs-gui/
43+
dir: ./crates/rs-gui/
44+
optional: true
45+
4146
tauri:
4247
taskfile: ./crates/rs-gui/rs-tauri-vue/
4348
dir: ./crates/rs-gui/rs-tauri-vue/
@@ -51,7 +56,6 @@ includes:
5156
taskfile: crates/rs-pkg
5257
dir: crates/rs-pkg
5358

54-
5559
#
5660
# global vars: https://taskfile.dev/#/usage?id=variables
5761
#
@@ -129,12 +133,11 @@ tasks:
129133
vars:
130134
APP_NAME: "crates/rs-cms-migration"
131135

132-
133136
# usage:
134137
# - task n -- --lib tmp/demo1
135138
# - task n -- --bin tmp/demo2
136139
new:
137-
aliases: [ "n" ]
140+
aliases: ["n"]
138141
cmds:
139142
- cargo new {{.CLI_ARGS}}
140143

@@ -186,11 +189,10 @@ tasks:
186189
cmds:
187190
- cargo search
188191

189-
190192
###########################################################################
191193

192194
quick:
193-
aliases: [ "q" ]
195+
aliases: ["q"]
194196
cmds:
195197
- task: commit
196198
- task: commit
@@ -199,20 +201,19 @@ tasks:
199201
ignore_error: true
200202

201203
commit:
202-
aliases: [ "c" ]
204+
aliases: ["c"]
203205
cmds:
204206
- git add .
205207
- git commit -m "update" --no-verify
206208
ignore_error: true
207209

208-
209210
pull:
210-
aliases: [ "pl" ]
211+
aliases: ["pl"]
211212
cmds:
212213
- git pull
213214

214215
push:
215-
aliases: [ "p" ]
216+
aliases: ["p"]
216217
cmds:
217218
- git push origin main --tags
218219
- repo_url=`git remote -v | grep push | awk -F ":" '{print $2}' | awk -F ".git" '{print "https://github.com/"$1}'`; open $repo_url

crates/rs-gui/Taskfile.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3"
2+
3+
includes:
4+
wry:
5+
aliases: ["w"]
6+
taskfile: ./try-wry/
7+
dir: ./try-wry/
8+
optional: true
9+
10+
tauri:
11+
aliases: ["t"]
12+
taskfile: ./rs-tauri-vue/
13+
dir: ./rs-tauri-vue/
14+
optional: true

crates/rs-gui/try-wry/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "try-wry"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
tao = "0.32.6"
8+
winit = "0.30.9"
9+
wry = "0.50.3"

crates/rs-gui/try-wry/Taskfile.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "3"
2+
3+
tasks:
4+
cargo:
5+
aliases: ["pkg", "pm"]
6+
cmds:
7+
- cargo {{.CLI_ARGS}}
8+
9+
run:
10+
aliases: ["r"]
11+
cmds:
12+
- cargo run {{.CLI_ARGS}}
13+
dir: .
14+
15+
build:
16+
aliases: ["b"]
17+
cmds:
18+
- cargo build {{.CLI_ARGS}}
19+
20+
test:
21+
aliases: ["t"]
22+
cmds:
23+
- cargo test {{.CLI_ARGS}}
24+
25+
clean:
26+
aliases: ["cl"]
27+
cmds:
28+
- cargo clean
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
use winit::{
2+
application::ApplicationHandler,
3+
event::WindowEvent,
4+
event_loop::{ActiveEventLoop, EventLoop},
5+
window::{Window, WindowId},
6+
};
7+
use wry::{
8+
Rect, WebViewBuilder,
9+
dpi::{LogicalPosition, LogicalSize},
10+
};
11+
12+
#[derive(Default)]
13+
struct State {
14+
window: Option<Window>,
15+
webview1: Option<wry::WebView>,
16+
webview2: Option<wry::WebView>,
17+
webview3: Option<wry::WebView>,
18+
webview4: Option<wry::WebView>,
19+
}
20+
21+
impl ApplicationHandler for State {
22+
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
23+
let mut attributes = Window::default_attributes();
24+
attributes.inner_size = Some(LogicalSize::new(800, 800).into());
25+
let window = event_loop.create_window(attributes).unwrap();
26+
27+
let size = window.inner_size().to_logical::<u32>(window.scale_factor());
28+
29+
let webview1 = WebViewBuilder::new()
30+
.with_bounds(Rect {
31+
position: LogicalPosition::new(0, 0).into(),
32+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
33+
})
34+
.with_url("https://tauri.app")
35+
.build_as_child(&window)
36+
.unwrap();
37+
38+
let webview2 = WebViewBuilder::new()
39+
.with_bounds(Rect {
40+
position: LogicalPosition::new(size.width / 2, 0).into(),
41+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
42+
})
43+
.with_url("https://github.com/tauri-apps/wry")
44+
.build_as_child(&window)
45+
.unwrap();
46+
47+
let webview3 = WebViewBuilder::new()
48+
.with_bounds(Rect {
49+
position: LogicalPosition::new(0, size.height / 2).into(),
50+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
51+
})
52+
.with_url("https://twitter.com/TauriApps")
53+
.build_as_child(&window)
54+
.unwrap();
55+
56+
let webview4 = WebViewBuilder::new()
57+
.with_bounds(Rect {
58+
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
59+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
60+
})
61+
.with_url("https://google.com")
62+
.build_as_child(&window)
63+
.unwrap();
64+
65+
self.window = Some(window);
66+
self.webview1 = Some(webview1);
67+
self.webview2 = Some(webview2);
68+
self.webview3 = Some(webview3);
69+
self.webview4 = Some(webview4);
70+
}
71+
72+
fn window_event(
73+
&mut self,
74+
_event_loop: &ActiveEventLoop,
75+
_window_id: WindowId,
76+
event: WindowEvent,
77+
) {
78+
match event {
79+
WindowEvent::Resized(size) => {
80+
if let (
81+
Some(window),
82+
Some(webview1),
83+
Some(webview2),
84+
Some(webview3),
85+
Some(webview4),
86+
) =
87+
(&self.window, &self.webview1, &self.webview2, &self.webview3, &self.webview4)
88+
{
89+
let size = size.to_logical::<u32>(window.scale_factor());
90+
91+
webview1
92+
.set_bounds(Rect {
93+
position: LogicalPosition::new(0, 0).into(),
94+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
95+
})
96+
.unwrap();
97+
98+
webview2
99+
.set_bounds(Rect {
100+
position: LogicalPosition::new(size.width / 2, 0).into(),
101+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
102+
})
103+
.unwrap();
104+
105+
webview3
106+
.set_bounds(Rect {
107+
position: LogicalPosition::new(0, size.height / 2).into(),
108+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
109+
})
110+
.unwrap();
111+
112+
webview4
113+
.set_bounds(Rect {
114+
position: LogicalPosition::new(size.width / 2, size.height / 2).into(),
115+
size: LogicalSize::new(size.width / 2, size.height / 2).into(),
116+
})
117+
.unwrap();
118+
}
119+
},
120+
WindowEvent::CloseRequested => {
121+
std::process::exit(0);
122+
},
123+
_ => {},
124+
}
125+
}
126+
127+
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
128+
#[cfg(any(
129+
target_os = "linux",
130+
target_os = "dragonfly",
131+
target_os = "freebsd",
132+
target_os = "netbsd",
133+
target_os = "openbsd",
134+
))]
135+
{
136+
while gtk::events_pending() {
137+
gtk::main_iteration_do(false);
138+
}
139+
}
140+
}
141+
}
142+
143+
fn main() -> wry::Result<()> {
144+
#[cfg(any(
145+
target_os = "linux",
146+
target_os = "dragonfly",
147+
target_os = "freebsd",
148+
target_os = "netbsd",
149+
target_os = "openbsd",
150+
))]
151+
{
152+
use gtk::prelude::DisplayExtManual;
153+
154+
gtk::init()?;
155+
if gtk::gdk::Display::default().unwrap().backend().is_wayland() {
156+
panic!("This example doesn't support wayland!");
157+
}
158+
159+
winit::platform::x11::register_xlib_error_hook(Box::new(|_display, error| {
160+
let error = error as *mut x11_dl::xlib::XErrorEvent;
161+
(unsafe { (*error).error_code }) == 170
162+
}));
163+
}
164+
165+
let event_loop = EventLoop::new().unwrap();
166+
let mut state = State::default();
167+
event_loop.run_app(&mut state).unwrap();
168+
169+
Ok(())
170+
}

crates/rs-gui/try-wry/readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# rust wry
2+
3+
## Development
4+
5+
```ruby
6+
7+
cargo add wry
8+
9+
10+
```
11+
12+
## Reference
13+
14+
- https://crates.io/crates/wry
15+
- https://crates.io/crates/tao
16+
- https://crates.io/crates/winit

crates/rs-gui/try-wry/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)