parent
							
								
									40eba0ddd7
								
							
						
					
					
						commit
						d2e07cd89d
					
				| @ -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(), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue