From b3695d02c140f496c1c969f5d2f184b2809d7a41 Mon Sep 17 00:00:00 2001 From: liuyuxin Date: Sat, 27 Jan 2024 14:39:41 +0800 Subject: [PATCH] feat: spectacle support on Linux (#27) --- .../system_screen_capturer_impl_linux.dart | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/src/system_screen_capturer_impl_linux.dart b/lib/src/system_screen_capturer_impl_linux.dart index ca1e4ee..f46ff98 100644 --- a/lib/src/system_screen_capturer_impl_linux.dart +++ b/lib/src/system_screen_capturer_impl_linux.dart @@ -2,10 +2,17 @@ import 'package:screen_capturer/src/capture_mode.dart'; import 'package:screen_capturer/src/system_screen_capturer.dart'; import 'package:shell_executor/shell_executor.dart'; -final Map> _knownCaptureModeArgs = { - CaptureMode.region: ['-a'], - CaptureMode.screen: [], - CaptureMode.window: ['-w'], +final Map>> _knownCaptureModeArgs = { + 'gnome-screenshot': { + CaptureMode.region: ['-a'], + CaptureMode.screen: [], + CaptureMode.window: ['-w'], + }, + 'spectacle': { + CaptureMode.region: ['-r'], + CaptureMode.screen: ['-f'], + CaptureMode.window: ['-a'], + } }; class SystemScreenCapturerImplLinux extends SystemScreenCapturer { @@ -18,11 +25,26 @@ class SystemScreenCapturerImplLinux extends SystemScreenCapturer { bool copyToClipboard = true, bool silent = true, }) async { - List arguments = [ - ..._knownCaptureModeArgs[mode]!, - ...(copyToClipboard ? ['-c'] : []), - ...(imagePath != null ? ['-f', imagePath] : []), - ]; - await $('gnome-screenshot', arguments); + try { + List arguments = [ + ..._knownCaptureModeArgs['gnome-screenshot']![mode]!, + ...(copyToClipboard ? ['-c'] : []), + ...(imagePath != null ? ['-f', imagePath] : []), + ]; + await $('gnome-screenshot', arguments); + } catch (e) { + try { + List arguments = [ + '-b', + '-n', + ..._knownCaptureModeArgs['spectacle']![mode]!, + ...(copyToClipboard ? ['-c'] : []), + ...(imagePath != null ? ['-o', imagePath] : []), + ]; + await $('spectacle', arguments); + } catch (e) { + rethrow; + } + } } }