diff --git a/packages/screen_capturer_linux/lib/src/commands/deepin_screen_recorder.dart b/packages/screen_capturer_linux/lib/src/commands/deepin_screen_recorder.dart new file mode 100644 index 0000000..65a4aab --- /dev/null +++ b/packages/screen_capturer_linux/lib/src/commands/deepin_screen_recorder.dart @@ -0,0 +1,40 @@ +import 'dart:io'; + +import 'package:screen_capturer_platform_interface/screen_capturer_platform_interface.dart'; +import 'package:shell_executor/shell_executor.dart'; + +final Map> _knownCaptureModeArgs = { + CaptureMode.region: [''], + CaptureMode.screen: ['-f'], + CaptureMode.window: ['--dograb'], +}; + +class _Deepin extends Command with SystemScreenCapturer { + @override + String get executable { + return 'deepin-screen-recorder'; + } + + @override + Future install() { + throw UnimplementedError(); + } + + @override + Future capture({ + required CaptureMode mode, + String? imagePath, + bool copyToClipboard = true, + bool silent = true, + }) { + return exec( + [ + ..._knownCaptureModeArgs[mode]!, + ...(imagePath != null ? ['-s', imagePath] : []), + ...(silent ? ['-n'] : []), + ], + ); + } +} + +final deepinScreenRecorder = _Deepin(); diff --git a/packages/screen_capturer_linux/lib/src/screen_capturer_linux.dart b/packages/screen_capturer_linux/lib/src/screen_capturer_linux.dart index 0a62f62..7f4e808 100644 --- a/packages/screen_capturer_linux/lib/src/screen_capturer_linux.dart +++ b/packages/screen_capturer_linux/lib/src/screen_capturer_linux.dart @@ -1,3 +1,4 @@ +import 'package:screen_capturer_linux/src/commands/deepin_screen_recorder.dart'; import 'package:screen_capturer_linux/src/commands/gnome_screenshot.dart'; import 'package:screen_capturer_linux/src/commands/spectacle.dart'; import 'package:screen_capturer_platform_interface/screen_capturer_platform_interface.dart'; @@ -26,11 +27,30 @@ class ScreenCapturerLinux extends MethodChannelScreenCapturer { return _isKdeDesktop!; } + bool? _isDeepinDesktop; + + bool get isDeepinDesktop { + if (_isDeepinDesktop == null) { + try { + final result = + ShellExecutor.global.execSync('deepin-screen-recorder', ['-v']); + _isDeepinDesktop = result.exitCode == 0; + } catch (_) { + _isDeepinDesktop = false; + } + } + return _isDeepinDesktop!; + } + @override SystemScreenCapturer get systemScreenCapturer { if (isKdeDesktop) { return spectacle; } + + if (isDeepinDesktop) { + return deepinScreenRecorder; + } return gnomeScreenshot; } }