Skip to content

Commit b199853

Browse files
committed
[*] share screen ui
1 parent a48dd13 commit b199853

File tree

15 files changed

+430
-80
lines changed

15 files changed

+430
-80
lines changed

wayshot/src/config.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::slint_generatedAppWindow::{
22
Fps as UIFps, RTCIceServer as UIRTCIceServer, Resolution as UIResolution,
33
SettingControl as UISettingControl, SettingCursorTracker as UISettingCursorTracker,
44
SettingRecorder as UISettingRecorder, SettingShareScreen as UISettingShareScreen,
5-
TransitionType as UITransitionType,
5+
SettingShareScreenClient as UISettingShareScreenClient, TransitionType as UITransitionType,
66
};
77
use anyhow::{Context, Result, bail};
88
use log::debug;
@@ -82,6 +82,9 @@ pub struct Config {
8282

8383
#[serde(default)]
8484
pub share_screen: ShareScreen,
85+
86+
#[serde(default)]
87+
pub share_screen_client: ShareScreenClient,
8588
}
8689

8790
#[derive(Serialize, Deserialize, Debug, Clone, Derivative)]
@@ -198,8 +201,15 @@ pub struct CursorTracker {
198201
pub zoom_out_transition_type: UITransitionType,
199202
}
200203

201-
#[derive(Serialize, Deserialize, Debug, Clone, Derivative, SlintFromConvert)]
202-
#[derivative(Default)]
204+
#[derive(Serialize, Deserialize, Debug, Clone, Default, SlintFromConvert)]
205+
#[from("UISettingShareScreenClient")]
206+
pub struct ShareScreenClient {
207+
pub enable_auth: bool,
208+
pub auth_token: String,
209+
pub server_addr: String,
210+
}
211+
212+
#[derive(Serialize, Deserialize, Debug, Clone, Default, SlintFromConvert)]
203213
#[from("UIRTCIceServer")]
204214
pub struct RTCIceServer {
205215
pub url: String,

wayshot/src/logic/setting.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ pub fn init(ui: &AppWindow) {
115115
toast_success!(ui_weak.unwrap(), tr("save configuration successfully"));
116116
});
117117

118+
global_logic!(ui).on_get_setting_share_screen_client(move || {
119+
let config = config::all().share_screen_client;
120+
config.into()
121+
});
122+
123+
let ui_weak = ui.as_weak();
124+
global_logic!(ui).on_set_setting_share_screen_client(move |setting| {
125+
let mut all = config::all();
126+
all.share_screen_client = setting.into();
127+
_ = config::save(all);
128+
});
129+
118130
global_logic!(ui).on_get_setting_share_screen(move || {
119131
let config = config::all().share_screen;
120132
config.into()

wayshot/src/logic/share_screen.rs

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use crate::{
22
config, global_store,
33
logic::{toast, tr::tr},
44
logic_cb,
5-
slint_generatedAppWindow::{AppWindow, SettingShareScreen as UISettingShareScreen},
5+
slint_generatedAppWindow::{
6+
AppWindow, SettingShareScreen as UISettingShareScreen,
7+
SettingShareScreenClient as UISettingShareScreenClient,
8+
},
69
};
710
use recorder::{RTCIceServer, ShareScreenConfig};
811
use slint::{ComponentHandle, Model, ModelRc, SharedString, VecModel, Weak};
@@ -18,26 +21,35 @@ macro_rules! host_ips {
1821
}
1922

2023
pub fn init(ui: &AppWindow) {
21-
logic_cb!(add_host_ip, ui, ips, ip);
22-
logic_cb!(remove_host_ip, ui, ips, index);
23-
logic_cb!(load_share_screen_cert_file, ui);
24-
logic_cb!(load_share_screen_key_file, ui);
25-
logic_cb!(verify_setting_share_screen, ui, setting);
24+
// share screen server
25+
logic_cb!(share_screen_add_host_ip, ui, ips, ip);
26+
logic_cb!(share_screen_remove_host_ip, ui, ips, index);
27+
logic_cb!(share_screen_load_cert_file, ui);
28+
logic_cb!(share_screen_load_key_file, ui);
29+
logic_cb!(share_screen_verify_setting, ui, setting);
30+
31+
// share screen client
32+
logic_cb!(share_screen_player_play, ui);
33+
logic_cb!(share_screen_player_stop, ui);
34+
logic_cb!(share_screen_player_sound_changed, ui, progress);
35+
logic_cb!(share_screen_client_disconnect, ui);
36+
logic_cb!(share_screen_client_connect, ui, setting);
37+
logic_cb!(convert_to_meida_time, ui, duration);
2638
}
2739

28-
fn add_host_ip(_ui: &AppWindow, ips: ModelRc<SharedString>, ip: SharedString) {
40+
fn share_screen_add_host_ip(_ui: &AppWindow, ips: ModelRc<SharedString>, ip: SharedString) {
2941
host_ips!(ips).insert(0, ip);
3042
}
3143

32-
fn remove_host_ip(_ui: &AppWindow, ips: ModelRc<SharedString>, index: i32) {
44+
fn share_screen_remove_host_ip(_ui: &AppWindow, ips: ModelRc<SharedString>, index: i32) {
3345
if index < 0 || index >= host_ips!(ips).row_count() as i32 {
3446
return;
3547
}
3648

3749
host_ips!(ips).remove(index as usize);
3850
}
3951

40-
fn load_share_screen_cert_file(ui: &AppWindow) {
52+
fn share_screen_load_cert_file(ui: &AppWindow) {
4153
let ui_weak = ui.as_weak();
4254

4355
tokio::spawn(async move {
@@ -57,7 +69,7 @@ fn load_share_screen_cert_file(ui: &AppWindow) {
5769
});
5870
}
5971

60-
fn load_share_screen_key_file(ui: &AppWindow) {
72+
fn share_screen_load_key_file(ui: &AppWindow) {
6173
let ui_weak = ui.as_weak();
6274

6375
tokio::spawn(async move {
@@ -77,7 +89,7 @@ fn load_share_screen_key_file(ui: &AppWindow) {
7789
});
7890
}
7991

80-
fn verify_setting_share_screen(_ui: &AppWindow, config: UISettingShareScreen) -> SharedString {
92+
fn share_screen_verify_setting(_ui: &AppWindow, config: UISettingShareScreen) -> SharedString {
8193
if config.enable_stun_server && !config.stun_server.url.starts_with("stun") {
8294
return tr("Invalid STUN server url format. Should start with `stun:`").into();
8395
}
@@ -89,6 +101,30 @@ fn verify_setting_share_screen(_ui: &AppWindow, config: UISettingShareScreen) ->
89101
SharedString::default()
90102
}
91103

104+
fn share_screen_player_play(ui: &AppWindow) {
105+
todo!()
106+
}
107+
108+
fn share_screen_player_stop(ui: &AppWindow) {
109+
todo!()
110+
}
111+
112+
fn share_screen_player_sound_changed(ui: &AppWindow, progress: f32) {
113+
todo!()
114+
}
115+
116+
fn share_screen_client_disconnect(ui: &AppWindow) {
117+
todo!()
118+
}
119+
120+
fn share_screen_client_connect(ui: &AppWindow, setting: UISettingShareScreenClient) {
121+
// todo!()
122+
}
123+
124+
fn convert_to_meida_time(ui: &AppWindow, duration: i32) -> SharedString {
125+
cutil::time::seconds_to_media_timestamp(duration.max(0) as f64).into()
126+
}
127+
92128
pub fn picker_file(
93129
ui: Weak<AppWindow>,
94130
title: &str,

wayshot/ui/base/icon.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export global Icons {
253253
out property <image> ipv6-light: @image-url("../images/icons/ipv6-light.svg");
254254
out property <image> stun-light: @image-url("../images/icons/stun-light.svg");
255255
out property <image> video-recorder-light: @image-url("../images/icons/video-recorder-light.svg");
256+
out property <image> share-screen-fill: @image-url("../images/icons/share-screen-fill.svg");
256257

257258
out property <image> landing-account: @image-url("../images/landing/landing-account.svg");
258259
out property <image> landing-language-switch: @image-url("../images/landing/landing-language-switch.svg");

wayshot/ui/base/theme.slint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export global Theme {
1010
out property <length> spacing: padding;
1111
out property <length> scrollbar-size: padding * 2;
1212
out property <length> border-radius: padding;
13+
out property <length> sidebar-width: header-height * 1.5;
1314
out property <length> header-height: Math.max(32px, icon-size + padding * 2);
1415
out property <length> footer-height: Math.max(40px, icon-size + default-font-size);
1516

wayshot/ui/base/video-player.slint

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ export component VideoPlayer inherits Rectangle {
1818
in-out property <float> current-sound: 50;
1919
in-out property <float> current-speed: 1.0;
2020
in-out property <float> progress: 0;
21+
in-out property <bool> show-time-label: true;
2122
in-out property <string> current-time: "0:00";
2223
in-out property <string> end-time: "4:00";
24+
in-out property <string> time-label: root.current-time + " / " + root.end-time;
2325
in-out property <bool> show-controls: false;
2426
in-out property <length> control-height: Theme.icon-size * 3;
2527
in-out property <float> center-icon-opacity: Theme.golden-ratio;
28+
in-out property <bool> show-progress-bar: true;
2629
in-out property <bool> show-prev-buttons: true;
2730
in-out property <bool> show-next-buttons: true;
2831
in-out property <bool> show-playlist-button: true;
@@ -83,6 +86,7 @@ export component VideoPlayer inherits Rectangle {
8386
key-pressed(event) => {
8487
if (event.text == Key.Escape) {
8588
if (root.show-full-screen-btn && root.is-full-screen) {
89+
root.is-full-screen = !root.is-full-screen;
8690
root.exit-full-screen();
8791
}
8892
} else if (event.text == Key.Space) {
@@ -300,10 +304,11 @@ export component VideoPlayer inherits Rectangle {
300304
}
301305

302306
progress-bar := Slider {
307+
visible: root.show-progress-bar;
303308
y: Theme.padding * 2;
304309
x: Theme.padding * 2;
305310
width: parent.width - Theme.padding * 4;
306-
height: Theme.default-font-size * 0.33;
311+
height: self.visible ? Theme.default-font-size * 0.33 : 0;
307312
value: root.progress;
308313
finished-progress-color: Theme.is-dark ? Theme.success-color.brighter(20%) : Theme.success-color;
309314
unfinished-progress-color: Theme.light-text-color.darker(80%);
@@ -470,7 +475,7 @@ export component VideoPlayer inherits Rectangle {
470475
}
471476

472477
Label {
473-
text: root.current-time + " / " + root.end-time;
478+
text: root.time-label;
474479
color: Theme.light-text-color;
475480
font-size: Theme.title4-font-size;
476481
vertical-alignment: TextVerticalAlignment.center;
Lines changed: 1 addition & 0 deletions
Loading

wayshot/ui/logic.slint

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
Resolution,
1717
HistoryEntry,
1818
ProcessMode,
19+
SettingShareScreenClient,
1920
} from "store.slint";
2021

2122
import { PlaylistItem } from "base/def.slint";
@@ -110,6 +111,9 @@ export global Logic {
110111
callback get-setting-share-screen() -> SettingShareScreen;
111112
callback set-setting-share-screen(setting: SettingShareScreen);
112113

114+
callback get-setting-share-screen-client() -> SettingShareScreenClient;
115+
callback set-setting-share-screen-client(setting: SettingShareScreenClient);
116+
113117
callback init-sources-dialog();
114118
callback choose-save-dir();
115119
callback update-sources(setting: SettingControl);
@@ -151,11 +155,21 @@ export global Logic {
151155
return -1;
152156
}
153157

154-
callback add-host-ip(host-ips: [string], ip: string);
155-
callback remove-host-ip(host-ips: [string], index: int);
156-
callback load-share-screen-cert-file();
157-
callback load-share-screen-key-file();
158-
callback verify-setting-share-screen(setting: SettingShareScreen) -> string;
158+
// share screen server
159+
callback share-screen-add-host-ip(host-ips: [string], ip: string);
160+
callback share-screen-remove-host-ip(host-ips: [string], index: int);
161+
callback share-screen-load-cert-file();
162+
callback share-screen-load-key-file();
163+
callback share-screen-verify-setting(setting: SettingShareScreen) -> string;
164+
165+
// share screen client
166+
callback share-screen-player-play();
167+
callback share-screen-player-stop();
168+
callback share-screen-player-sound-changed(progress: float);
169+
callback share-screen-client-disconnect();
170+
callback share-screen-client-connect(setting: SettingShareScreenClient);
171+
172+
pure callback convert-to-meida-time(duration: int) -> string;
159173

160174
pure public function fps-to-int(fps: Fps) -> int {
161175
if (fps == Fps.Fps24) {

wayshot/ui/panel/def.slint

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
SettingShareScreen,
1818
SettingPlayer,
1919
FeatureType,
20+
SettingShareScreenClient,
2021
} from "../store.slint";
2122

22-
export { Theme, Logic, Store, Util, Icons, TabIndex, PopupIndex, SettingPreference, SettingBackup, SettingDetailIndex, MobileSettingDetailIndex, DeviceType, MobileTabIndex, SettingRecorder, SettingCursorTracker, TransitionType, SettingPlayer, FeatureType, SettingShareScreen }
23+
export { Theme, Logic, Store, Util, Icons, TabIndex, PopupIndex, SettingPreference, SettingBackup, SettingDetailIndex, MobileSettingDetailIndex, DeviceType, MobileTabIndex, SettingRecorder, SettingCursorTracker, TransitionType, SettingPlayer, FeatureType, SettingShareScreen, SettingShareScreenClient }

0 commit comments

Comments
 (0)