Skip to content

Commit

Permalink
Merge pull request #39 from iakii/main
Browse files Browse the repository at this point in the history
新增支持Deepin
  • Loading branch information
lijy91 authored Aug 29, 2024
2 parents effcf98 + aae8125 commit c6fad6f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<CaptureMode, List<String>> _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<void> install() {
throw UnimplementedError();
}

@override
Future<ProcessResult> 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();
20 changes: 20 additions & 0 deletions packages/screen_capturer_linux/lib/src/screen_capturer_linux.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
}

0 comments on commit c6fad6f

Please sign in to comment.