fix recording start stop

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-09-21 16:03:08 +08:00
parent eff5dd2e03
commit e74f155cb6
8 changed files with 28 additions and 29 deletions

2
Cargo.lock generated
View File

@ -2444,7 +2444,7 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hwcodec"
version = "0.1.0"
source = "git+https://github.com/21pages/hwcodec#097a476a0ee249e28d99573899ed4c9c0c01f884"
source = "git+https://github.com/21pages/hwcodec#1f03d203eca24dc976c21a47228f3bc31484c2bc"
dependencies = [
"bindgen",
"cc",

View File

@ -118,6 +118,7 @@ class _RemotePageState extends State<RemotePage>
void dispose() {
debugPrint("REMOTE PAGE dispose ${widget.id}");
_ffi.dialogManager.hideMobileActionsOverlay();
_ffi.recordingModel.onClose();
_rawKeyFocusNode.dispose();
_ffi.close();
_timer?.cancel();

View File

@ -359,9 +359,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
tooltip: value.start
? translate('Stop session recording')
: translate('Start session recording'),
onPressed: () async {
await value.toggle();
},
onPressed: () => value.toggle(),
icon: Icon(
value.start
? Icons.pause_circle_filled

View File

@ -197,13 +197,13 @@ class FfiModel with ChangeNotifier {
_display.height = int.parse(evt['height']);
if (old != _pi.currentDisplay) {
parent.target?.cursorModel.updateDisplayOrigin(_display.x, _display.y);
parent.target?.recordingModel.switchDisplay();
}
// remote is mobile, and orientation changed
if ((_display.width > _display.height) != oldOrientation) {
gFFI.canvasModel.updateViewStyle();
}
parent.target?.recordingModel.onSwitchDisplay();
notifyListeners();
}
@ -979,33 +979,35 @@ class RecordingModel with ChangeNotifier {
bool _start = false;
get start => _start;
switchDisplay() {
onSwitchDisplay() {
if (!isDesktop || !_start) return;
var id = parent.target?.id;
int? width = parent.target?.canvasModel.getDisplayWidth();
int? height = parent.target?.canvasModel.getDisplayWidth();
if (id == null || width == null || height == null) return;
bind.sessionRecordScreen(
id: id, start: _start, width: width, height: height);
bind.sessionRecordScreen(id: id, start: true, width: width, height: height);
}
Future<void> toggle() async {
toggle() {
if (!isDesktop) return;
var id = parent.target?.id;
int? width = parent.target?.canvasModel.getDisplayWidth();
int? height = parent.target?.canvasModel.getDisplayWidth();
if (id == null || width == null || height == null) return;
await bind.sessionRecordScreen(
id: id, start: !_start, width: width, height: height);
if (id == null) return;
_start = !_start;
notifyListeners();
if (_start) {
Future.delayed(const Duration(milliseconds: 100), () {
bind.sessionRefresh(id: id);
});
bind.sessionRefresh(id: id);
} else {
bind.sessionRecordScreen(id: id, start: false, width: 0, height: 0);
}
}
onClose() {
if (!isDesktop) return;
var id = parent.target?.id;
if (id == null) return;
_start = false;
bind.sessionRecordScreen(id: id, start: false, width: 0, height: 0);
}
}
/// Mouse button enum.
@ -1174,7 +1176,7 @@ class FFI {
Map<String, dynamic> event = json.decode(message.field0);
await cb(event);
} catch (e) {
debugPrint('json.decode fail(): $e');
debugPrint('json.decode fail1(): $e, ${message.field0}');
}
} else if (message is Rgba) {
imageModel.onRgba(message.field0, tabBarHeight);

View File

@ -298,11 +298,9 @@ impl RecorderApi for HwRecorder {
#[cfg(feature = "hwcodec")]
impl Drop for HwRecorder {
fn drop(&mut self) {
log::info!("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD {}", self.ctx.filename);
self.muxer.write_tail().ok();
if !self.written || self.start.elapsed().as_secs() < MIN_SECS {
std::fs::remove_file(&self.ctx.filename).ok();
}
log::info!("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD ok");
}
}

View File

@ -257,7 +257,7 @@ impl InvokeUiSession for FlutterHandler {
self.push_event(
"switch_display",
vec![
("display", &display.to_string()),
("display", &display.display.to_string()),
("x", &display.x.to_string()),
("y", &display.y.to_string()),
("width", &display.width.to_string()),
@ -485,4 +485,4 @@ pub fn make_fd_flutter(id: i32, entries: &Vec<FileEntry>, only_count: bool) -> S
}
m.insert("total_size".into(), json!(n as f64));
serde_json::to_string(&m).unwrap_or("".into())
}
}

View File

@ -93,7 +93,6 @@ function editOSPassword(login=false) {
}
var recording = false;
var recording_refresh = false;
class Header: Reactor.Component {
this var conn_note = "";
@ -286,10 +285,12 @@ class Header: Reactor.Component {
}
event click $(span#recording) (_, me) {
handler.record_screen(!recording, display_width, display_height);
recording = !recording;
header.update();
if (recording) self.timer(100ms, function() { recording_refresh = true; handler.refresh_video(); });
if (recording)
handler.refresh_video();
else
handler.record_screen(false, display_width, display_height);
}
event click $(#screen) (_, me) {

View File

@ -20,9 +20,7 @@ handler.setDisplay = function(x, y, w, h) {
display_origin_x = x;
display_origin_y = y;
adaptDisplay();
if (recording && !recording_refresh) handler.record_screen(true, w, h);
recording_refresh = false;
if (recording) handler.record_screen(true, w, h);
}
// in case toolbar not shown correclty
@ -470,6 +468,7 @@ function self.closing() {
var (x, y, w, h) = view.box(#rectw, #border, #screen);
if (is_file_transfer) save_file_transfer_close_state();
if (is_file_transfer || is_port_forward || size_adapted) handler.save_size(x, y, w, h);
if (recording) handler.record_screen(false, display_width, display_height);
}
var qualityMonitor;