feat: scheme apply feature.
This commit is contained in:
@@ -19,6 +19,16 @@ const double defaultBorderRadius = 8;
|
||||
|
||||
const double defaultButtonHeight = 36;
|
||||
|
||||
const userGestureConfigFilePath = 'deepin/dde-daemon/gesture.json';
|
||||
|
||||
const deepinLogoutCommands = [
|
||||
'dbus-send',
|
||||
'--type=method_call',
|
||||
'--dest=com.deepin.SessionManager',
|
||||
'/com/deepin/SessionManager',
|
||||
'com.deepin.SessionManager.RequestLogout'
|
||||
];
|
||||
|
||||
const List<String> builtInCommands = [
|
||||
'ShowWorkspace',
|
||||
'Handle4Or5FingersSwipeUp',
|
||||
@@ -45,4 +55,4 @@ enum UploadRespStatus {
|
||||
done,
|
||||
name_occupied,
|
||||
error,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:dde_gesture_manager/models/local_schemes_provider.dart';
|
||||
import 'package:dde_gesture_manager/models/scheme.dart';
|
||||
import 'package:dde_gesture_manager/models/scheme.provider.dart';
|
||||
import 'package:dde_gesture_manager/models/settings.provider.dart';
|
||||
import 'package:dde_gesture_manager/utils/apply_scheme_interface.dart';
|
||||
import 'package:dde_gesture_manager/widgets/dde_button.dart';
|
||||
import 'package:dde_gesture_manager_api/models.dart' show SchemeForDownload;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -257,10 +258,10 @@ class LocalManagerState extends State<LocalManager> {
|
||||
DButton.apply(
|
||||
enabled: true,
|
||||
onTap: () {
|
||||
var appliedId =
|
||||
localSchemes.firstWhere((ele) => ele.path == _selectedItemPath).scheme.id!;
|
||||
appliedId.sout();
|
||||
context.read<ConfigsProvider>().setProps(appliedSchemeId: appliedId);
|
||||
var appliedScheme =
|
||||
localSchemes.firstWhere((ele) => ele.path == _selectedItemPath).scheme;
|
||||
context.read<ConfigsProvider>().setProps(appliedSchemeId: appliedScheme.id);
|
||||
SchemeApplyUtil().apply(context, appliedScheme);
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import 'package:dde_gesture_manager/models/scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
export 'apply_scheme_web.dart' if (dart.library.io) 'apply_scheme_linux.dart';
|
||||
|
||||
abstract class SchemeApplyUtilStub {
|
||||
void apply(BuildContext context, Scheme scheme);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/models/scheme.dart';
|
||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||
import 'package:dde_gesture_manager/utils/notificator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'apply_scheme_interface.dart';
|
||||
import 'package:xdg_directories/xdg_directories.dart' as xdg;
|
||||
import 'package:path/path.dart' show join;
|
||||
|
||||
class SchemeApplyUtil implements SchemeApplyUtilStub {
|
||||
void apply(BuildContext context, Scheme scheme) {
|
||||
var configFilePath = join(xdg.configHome.path, userGestureConfigFilePath);
|
||||
configFilePath.sout();
|
||||
var file = File(configFilePath);
|
||||
if (scheme.id == Uuid.NAMESPACE_NIL) {
|
||||
if (file.existsSync()) file.deleteSync();
|
||||
} else {
|
||||
if (!file.existsSync()) file.createSync(recursive: true);
|
||||
file.writeAsStringSync(
|
||||
H.transGesturePropsToConfig(scheme.gestures ?? []),
|
||||
flush: true,
|
||||
);
|
||||
Notificator.showConfirm(
|
||||
title: LocaleKeys.info_apply_scheme_success.tr(),
|
||||
description: LocaleKeys.info_apply_scheme_description.tr(),
|
||||
positiveButtonTitle: LocaleKeys.info_apply_scheme_logout_immediately.tr(),
|
||||
negativeButtonTitle: LocaleKeys.str_cancel.tr(),
|
||||
).then((value) {
|
||||
if (value == CustomButton.positiveButton) {
|
||||
Process.run(deepinLogoutCommands.first, deepinLogoutCommands.skip(1).toList());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/models/scheme.dart';
|
||||
import 'package:dde_gesture_manager/utils/helper.dart';
|
||||
import 'package:dde_gesture_manager/utils/notificator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'apply_scheme_interface.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class SchemeApplyUtil implements SchemeApplyUtilStub {
|
||||
void apply(BuildContext context, Scheme scheme) {
|
||||
var cmd = scheme.id == Uuid.NAMESPACE_NIL
|
||||
? [
|
||||
'rm \$XDG_CONFIG_HOME/${userGestureConfigFilePath}',
|
||||
]
|
||||
: [
|
||||
'cat > \$XDG_CONFIG_HOME/${userGestureConfigFilePath} << EOF',
|
||||
'${H.transGesturePropsToConfig(scheme.gestures ?? [])}',
|
||||
'EOF',
|
||||
];
|
||||
cmd.add('zenity'
|
||||
' --title=${LocaleKeys.info_apply_scheme_success.tr()}'
|
||||
' --question'
|
||||
' --no-wrap'
|
||||
' --text=${LocaleKeys.info_apply_scheme_description.tr()}'
|
||||
' --ok-label=${LocaleKeys.info_apply_scheme_logout_immediately.tr()}'
|
||||
' --cancel-label=${LocaleKeys.str_cancel.tr()}'
|
||||
' && ${deepinLogoutCommands.join(' ')}');
|
||||
Clipboard.setData(ClipboardData(
|
||||
text: cmd.join('\n'),
|
||||
));
|
||||
Notificator.success(
|
||||
context,
|
||||
title: LocaleKeys.info_apply_scheme_commands_copied_title.tr(),
|
||||
description: LocaleKeys.info_apply_scheme_commands_copied_description.tr(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/models/content_layout.provider.dart';
|
||||
@@ -130,6 +132,23 @@ class H {
|
||||
|
||||
static void handleDownloadScheme(BuildContext context, SchemeForDownload value) =>
|
||||
localManagerKey.currentState?.addLocalScheme(context, value);
|
||||
|
||||
static String transGesturePropsToConfig(List<GestureProp> gestures) =>
|
||||
JsonEncoder.withIndent(' ' * 4).convert(gestures
|
||||
.map(
|
||||
(gesture) => {
|
||||
"Event": {
|
||||
"Name": gesture.gesture!.name,
|
||||
"Direction": H.getGestureDirectionName(gesture.direction),
|
||||
"Fingers": gesture.fingers,
|
||||
},
|
||||
"Action": {
|
||||
"Type": gesture.type!.name,
|
||||
"Action": gesture.command,
|
||||
},
|
||||
},
|
||||
)
|
||||
.toList());
|
||||
}
|
||||
|
||||
class PreferredPanelsStatus {
|
||||
|
||||
@@ -163,6 +163,13 @@
|
||||
"title": "Are you sure to sharing?",
|
||||
"description": "Other users can see this scheme and download it after share",
|
||||
"success": "Share success"
|
||||
},
|
||||
"apply_scheme": {
|
||||
"success": "Apply success",
|
||||
"description": "The gesture scheme will take effect after logout, pay attention to the save work data",
|
||||
"logout_immediately": "Logout",
|
||||
"commands_copied_title": "Commands copied!",
|
||||
"commands_copied_description": "Please open the terminal and paste the command to execute"
|
||||
}
|
||||
},
|
||||
"me": {
|
||||
|
||||
@@ -163,6 +163,13 @@
|
||||
"title": "确定分享?",
|
||||
"description": "分享后其他用户可以看到本方案并下载使用",
|
||||
"success": "分享成功"
|
||||
},
|
||||
"apply_scheme": {
|
||||
"success": "设置成功",
|
||||
"description": "手势方案需注销后才能生效,注销前注意保存工作进度",
|
||||
"logout_immediately": "立即注销",
|
||||
"commands_copied_title": "命令复制成功!",
|
||||
"commands_copied_description": "请打开终端后粘贴命令并执行"
|
||||
}
|
||||
},
|
||||
"me": {
|
||||
|
||||
Reference in New Issue
Block a user