Skip to content

Commit 95f598c

Browse files
committed
[-] remove unused codes and add open crate for opening output mp4 file
1 parent ffa9c09 commit 95f598c

File tree

11 files changed

+82
-60
lines changed

11 files changed

+82
-60
lines changed

Cargo.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ platform-dirs = "0.3"
8585
yuv = "0.8"
8686
mp4 = "0.14"
8787
x264 = "0.5"
88+
open = "5.3"
8889
cpal = "0.16"
8990
hound = "3.5"
9091
which = "8.0"

lib/recorder/src/recorder.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ use mp4m::{
1212
AudioConfig, AudioProcessor, AudioProcessorConfigBuilder, Mp4Processor,
1313
Mp4ProcessorConfigBuilder, OutputDestination, VideoConfig, VideoFrameType,
1414
};
15-
use once_cell::sync::OnceCell;
16-
use screen_capture::{Capture, CaptureStreamConfig, ScreenCapture, ScreenCaptureError};
15+
use screen_capture::{Capture, CaptureStreamConfig, ScreenCapture};
1716
use spin_sleep::SpinSleeper;
1817
use std::{
1918
path::PathBuf,
2019
sync::{
21-
Arc, Mutex,
20+
Arc,
2221
atomic::{AtomicBool, AtomicU64, Ordering},
2322
},
2423
thread::{self, JoinHandle},
@@ -32,8 +31,6 @@ const USER_CHANNEL_SIZE: usize = 64;
3231
const ENCODER_WORKER_CHANNEL_SIZE: usize = 128;
3332
const AUDIO_MIXER_CHANNEL_SIZE: usize = 1024;
3433

35-
static CAPTURE_MEAN_TIME: OnceCell<Mutex<Result<Duration, ScreenCaptureError>>> = OnceCell::new();
36-
3734
#[derive(Setters)]
3835
#[setters(prefix = "with_")]
3936
#[setters(generate = false)]
@@ -711,41 +708,12 @@ impl RecordingSession {
711708
self.speaker_level_receiver.clone()
712709
}
713710

714-
pub fn init_capture_mean_time(
715-
screen_name: &str,
716-
screen_capturer: &mut impl ScreenCapture,
717-
) -> Result<(), RecorderError> {
718-
let mean_time = CAPTURE_MEAN_TIME.get_or_init(|| {
719-
let mean_time = screen_capturer.capture_mean_time(screen_name, 10);
720-
Mutex::new(mean_time)
721-
});
722-
723-
let mean_ms = mean_time
724-
.lock()
725-
.unwrap()
726-
.clone()
727-
.map_err(|e| RecorderError::CaptureFailed(e))?
728-
.as_millis() as f64;
729-
730-
log::info!("capture mean time: {mean_ms:.2?}ms");
731-
732-
Ok(())
733-
}
734-
735711
fn evaluate_need_threads(
736712
&self,
737713
screen_capturer: &mut impl ScreenCapture,
738714
) -> Result<u32, RecorderError> {
739-
let mean_time = CAPTURE_MEAN_TIME.get_or_init(|| {
740-
let mean_time = screen_capturer.capture_mean_time(&self.config.screen_name, 10);
741-
Mutex::new(mean_time)
742-
});
743-
744-
let mean_ms = mean_time
745-
.lock()
746-
.unwrap()
747-
.clone()
748-
.map_err(|e| RecorderError::CaptureFailed(e))?
715+
let mean_ms = screen_capturer
716+
.capture_mean_time(&self.config.screen_name, 3)?
749717
.as_millis() as f64;
750718

751719
log::info!("capture mean time: {mean_ms:.2?}ms");

tr-helper/src/tr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ fn cn() -> &'static HashMap<&'static str, &'static str> {
246246
("Disabled noise reduction", "禁用降噪功能"),
247247
("Don't convert audio to mono", "不要将音频转换为单声道"),
248248
("Enabled noise reduction", "启用降噪功能"),
249+
("Open file failed", "打开文件失败"),
249250
])
250251
})
251252
}

wayshot/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ serde = { workspace = true, features = ["serde_derive"] }
3636
cutil = { workspace = true, features = ["str", "time", "number", "fs"] }
3737

3838
[target.'cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))'.dependencies]
39+
open.workspace = true
3940
tempfile.workspace = true
4041
recorder.workspace = true
4142
clipboard.workspace = true

wayshot/src/logic/recorder.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ pub fn init(ui: &AppWindow) {
8484
logic_cb!(choose_save_dir, ui);
8585
logic_cb!(update_sources, ui, setting);
8686

87-
logic_cb!(screen_changed, ui, name);
88-
8987
logic_cb!(audio_changed, ui, name, show_toast);
9088
logic_cb!(audio_gain_changed, ui, v);
9189

@@ -94,6 +92,8 @@ pub fn init(ui: &AppWindow) {
9492

9593
logic_cb!(start_recording, ui);
9694
logic_cb!(stop_recording, ui);
95+
96+
logic_cb!(open_file, ui, file);
9797
}
9898

9999
fn inner_init(ui: &AppWindow) {
@@ -307,8 +307,6 @@ fn init_video(ui: &AppWindow) -> Result<()> {
307307
name: name.clone(),
308308
});
309309

310-
global_logic!(ui).invoke_screen_changed(name);
311-
312310
Ok(())
313311
}
314312

@@ -489,16 +487,6 @@ fn inner_audio_changed(ui: &AppWindow, name: SharedString) -> Result<()> {
489487
Ok(())
490488
}
491489

492-
fn screen_changed(_ui: &AppWindow, name: SharedString) {
493-
tokio::spawn(async move {
494-
if let Err(e) =
495-
RecordingSession::init_capture_mean_time(name.as_str(), &mut platform_screen_capture())
496-
{
497-
log::warn!("init capture mean time failed: {e}")
498-
}
499-
});
500-
}
501-
502490
fn start_recording(ui: &AppWindow) {
503491
let all_config = config::all();
504492

@@ -653,6 +641,14 @@ fn stop_recording(ui: &AppWindow) {
653641
global_store!(ui).set_record_status(UIRecordStatus::Stopped);
654642
}
655643

644+
fn open_file(ui: &AppWindow, file: SharedString) {
645+
if !file.is_empty()
646+
&& let Err(e) = open::that_detached(file.as_str())
647+
{
648+
toast_warn!(ui, format!("{}: `{}`. {e}", tr("Open file failed"), file));
649+
}
650+
}
651+
656652
pub fn picker_directory(ui: Weak<AppWindow>, title: &str, filename: &str) -> Option<PathBuf> {
657653
let result = native_dialog::DialogBuilder::file()
658654
.set_title(title)

wayshot/src/logic/tr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ fn cn() -> &'static HashMap<&'static str, &'static str> {
248248
("Disabled noise reduction", "禁用降噪功能"),
249249
("Don't convert audio to mono", "不要将音频转换为单声道"),
250250
("Enabled noise reduction", "启用降噪功能"),
251+
("Open file failed", "打开文件失败"),
251252
])
252253
})
253254
}

wayshot/src/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub static VERSION: &str = "v0.1.2";
1+
pub static VERSION: &str = "v0.2.0";

wayshot/ui/logic.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ export global Logic {
9191
callback choose-save-dir();
9292
callback update-sources(setting: SettingControl);
9393

94-
callback screen-changed(name: string);
95-
9694
callback audio-changed(name: string, show-toast: bool);
9795
callback audio-gain-changed(value: float);
9896

@@ -102,6 +100,8 @@ export global Logic {
102100
callback start-recording();
103101
callback stop-recording();
104102

103+
callback open-file(file: string);
104+
105105
pure public function fps-to-int(fps: Fps) -> int {
106106
if (fps == Fps.Fps24) {
107107
return 24;

wayshot/ui/panel/desktop/home.slint

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ComponentPosition,
1818
} from "../../base/widgets.slint";
1919
import { LogIn } from "../../base/log-in.slint";
20+
import { Divider } from "../../base/divider.slint";
2021

2122
component PreviewPanel inherits Rectangle {
2223
background: Theme.dark-text-color;
@@ -403,10 +404,29 @@ component Banners inherits VerticalLayout {
403404
HorizontalLayout {
404405
spacing: Theme.spacing;
405406

406-
Label {
407-
color: Theme.light-text-color;
408-
text: Store.final-video-path;
409-
font-weight: Theme.bold-font-weight;
407+
VerticalLayout {
408+
alignment: start;
409+
410+
lb := Label {
411+
color: Theme.light-text-color;
412+
text: Store.final-video-path;
413+
font-weight: Theme.bold-font-weight;
414+
415+
lb-ta := TouchArea {
416+
mouse-cursor: MouseCursor.pointer;
417+
418+
clicked => {
419+
Logic.open-file(Store.final-video-path);
420+
}
421+
}
422+
}
423+
424+
Divider {
425+
visible: lb-ta.has-hover;
426+
background: lb.color;
427+
height: Theme.default-border-width;
428+
width: lb.preferred-width;
429+
}
410430
}
411431

412432
IconBtn {

0 commit comments

Comments
 (0)