From 733d425b04313d3948ed07bd922b181bbcd64ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lollipopkit=F0=9F=8F=B3=EF=B8=8F=E2=80=8D=E2=9A=A7?= =?UTF-8?q?=EF=B8=8F?= <10864310+lollipopkit@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:59:39 +0800 Subject: [PATCH] fix: builtin editor Fixes #502 --- lib/data/model/sftp/req.dart | 14 ++------- lib/data/model/sftp/worker.dart | 16 ++++------ lib/data/provider/sftp.dart | 3 +- lib/data/res/github_id.dart | 2 ++ lib/l10n/app_tr.arb | 6 ++-- lib/view/page/server/edit.dart | 32 +++++--------------- lib/view/page/setting/platform/ios.dart | 6 +++- lib/view/page/storage/local.dart | 2 +- lib/view/page/storage/sftp.dart | 39 +++++++++++++------------ lib/view/page/storage/sftp_mission.dart | 5 ++-- pubspec.lock | 4 +-- pubspec.yaml | 2 +- 12 files changed, 53 insertions(+), 78 deletions(-) diff --git a/lib/data/model/sftp/req.dart b/lib/data/model/sftp/req.dart index 0417c2809..8a23e0172 100644 --- a/lib/data/model/sftp/req.dart +++ b/lib/data/model/sftp/req.dart @@ -1,11 +1,4 @@ -import 'dart:async'; - -import 'package:fl_lib/fl_lib.dart'; -import 'package:server_box/data/res/store.dart'; - -import '../../../core/utils/server.dart'; -import '../server/server_private_info.dart'; -import 'worker.dart'; +part of 'worker.dart'; class SftpReq { final ServerPrivateInfo spi; @@ -69,9 +62,8 @@ class SftpReqStatus { int get hashCode => id ^ super.hashCode; void dispose() { - // ignore: deprecated_member_use_from_same_package - worker.dispose(); - completer?.complete(); + worker._dispose(); + completer?.complete(true); } void onNotify(dynamic event) { diff --git a/lib/data/model/sftp/worker.dart b/lib/data/model/sftp/worker.dart index f2f333fb3..6deec3a0b 100644 --- a/lib/data/model/sftp/worker.dart +++ b/lib/data/model/sftp/worker.dart @@ -5,9 +5,12 @@ import 'dart:typed_data'; import 'package:dartssh2/dartssh2.dart'; import 'package:easy_isolate/easy_isolate.dart'; +import 'package:fl_lib/fl_lib.dart'; +import 'package:server_box/core/utils/server.dart'; +import 'package:server_box/data/model/server/server_private_info.dart'; +import 'package:server_box/data/res/store.dart'; -import '../../../core/utils/server.dart'; -import 'req.dart'; +part 'req.dart'; class SftpWorker { final Function(Object event) onNotify; @@ -20,14 +23,7 @@ class SftpWorker { required this.req, }); - /// Use [@Deprecated] to prevent calling [SftpWorker.dispose] directly - /// - /// Don't delete this method - @Deprecated( - "Use [SftpWorkerStatus.dispose] to dispose the worker, " - "instead of [SftpWorker.dispose]", - ) - void dispose() { + void _dispose() { worker.dispose(); } diff --git a/lib/data/provider/sftp.dart b/lib/data/provider/sftp.dart index 75f1ddabc..0d4e030e6 100644 --- a/lib/data/provider/sftp.dart +++ b/lib/data/provider/sftp.dart @@ -1,8 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; - -import '../model/sftp/req.dart'; +import 'package:server_box/data/model/sftp/worker.dart'; class SftpProvider extends ChangeNotifier { final List _status = []; diff --git a/lib/data/res/github_id.dart b/lib/data/res/github_id.dart index 78e29f05a..fb066bf67 100644 --- a/lib/data/res/github_id.dart +++ b/lib/data/res/github_id.dart @@ -15,6 +15,7 @@ abstract final class GithubIds { 'FrancXPT', 'Liloupar', 'dccif', + 'mikropsoft', }; static const participants = { @@ -95,6 +96,7 @@ abstract final class GithubIds { 'logce', 'h-lyf', '88484396', + 'honggeigei', }; } diff --git a/lib/l10n/app_tr.arb b/lib/l10n/app_tr.arb index a0ba795cc..99dcffb3f 100644 --- a/lib/l10n/app_tr.arb +++ b/lib/l10n/app_tr.arb @@ -75,7 +75,7 @@ "disk": "Disk", "diskIgnorePath": "Disk için göz ardı edilen yol", "displayCpuIndex": "CPU dizinini görüntüle", - "displayName": "Görünen ad", + "displayName": "Görünen ad", "dl2Local": "{fileName} dosyasını yerel olarak indirmek istiyor musunuz?", "doc": "Dokümantasyon", "dockerEditHost": "DOCKER_HOST'u düzenle", @@ -117,7 +117,7 @@ "fullScreen": "Tam ekran modu", "fullScreenJitter": "Tam ekran titremesi", "fullScreenJitterHelp": "Ekran yanıklarını önlemek için", - "fullScreenTip": "Cihaz yatay moda döndürüldüğünde tam ekran modu etkinleştirilsin mi? Bu seçenek yalnızca sunucu sekmesi için geçerlidir." + "fullScreenTip": "Cihaz yatay moda döndürüldüğünde tam ekran modu etkinleştirilsin mi? Bu seçenek yalnızca sunucu sekmesi için geçerlidir.", "getPushTokenFailed": "Push token alınamıyor", "gettingToken": "Token alınıyor...", "goBackQ": "Geri dön?", @@ -225,7 +225,7 @@ "primaryColorSeed": "Birincil renk tohumu", "privateKey": "Özel Anahtar", "process": "Süreç", - "pushToken": "Push token" + "pushToken": "Push token", "pveIgnoreCertTip": "Etkinleştirilmesi önerilmez, güvenlik risklerine dikkat edin! PVE'nin varsayılan sertifikasını kullanıyorsanız, bu seçeneği etkinleştirmeniz gerekir.", "pveLoginFailed": "Giriş başarısız. Linux PAM girişi için sunucu yapılandırmasındaki kullanıcı adı/şifre ile kimlik doğrulaması yapılamadı.", "pveVersionLow": "Bu özellik şu anda test aşamasında ve sadece PVE 8+ üzerinde test edilmiştir. Lütfen dikkatli kullanın.", diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index d633aa543..0bf5791d7 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -296,10 +296,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { final subtitle = val.isEmpty ? null : Text(val.keys.join(','), style: UIs.textGrey); return ListTile( - leading: const Padding( - padding: EdgeInsets.only(left: 10), - child: Icon(HeroIcons.variable), - ), + leading: const Icon(HeroIcons.variable), subtitle: subtitle, title: Text(l10n.envVars), trailing: const Icon(Icons.keyboard_arrow_right), @@ -388,10 +385,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { ), ), ListTile( - leading: const Padding( - padding: EdgeInsets.only(left: 10), - child: Icon(MingCute.certificate_line), - ), + leading: const Icon(MingCute.certificate_line), title: Text('PVE ${l10n.ignoreCert}'), subtitle: Text(l10n.pveIgnoreCertTip, style: UIs.text12Grey), trailing: ListenableBuilder( @@ -414,7 +408,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { _customCmds.listenVal( (vals) { return ListTile( - leading: const Icon(BoxIcons.bxs_file_json).paddingOnly(left: 10), + leading: const Icon(BoxIcons.bxs_file_json), title: const Text('JSON'), subtitle: vals.isEmpty ? null @@ -432,10 +426,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { }, ).cardx, ListTile( - leading: const Padding( - padding: EdgeInsets.only(left: 10), - child: Icon(MingCute.doc_line), - ), + leading: const Icon(MingCute.doc_line), title: Text(l10n.doc), trailing: const Icon(Icons.open_in_new, size: 17), onTap: () => l10n.customCmdDocUrl.launch(), @@ -448,10 +439,7 @@ class _ServerEditPageState extends State with AfterLayoutMixin { const Text('Wake On LAN', style: UIs.text13Grey), UIs.height7, ListTile( - leading: const Padding( - padding: EdgeInsets.only(left: 10), - child: Icon(BoxIcons.bxs_help_circle), - ), + leading: const Icon(BoxIcons.bxs_help_circle), title: Text(l10n.about), subtitle: Text(l10n.wolTip, style: UIs.text12Grey), ).cardx, @@ -513,19 +501,13 @@ class _ServerEditPageState extends State with AfterLayoutMixin { .toList(); children.add(ListTile( title: Text(l10n.clear), - trailing: const Padding( - padding: EdgeInsets.only(right: 13), - child: Icon(Icons.clear), - ), + trailing: const Icon(Icons.clear), onTap: () => _jumpServer.value = null, contentPadding: const EdgeInsets.symmetric(horizontal: 17), )); return CardX( child: ExpandTile( - leading: const Padding( - padding: EdgeInsets.only(left: 10), - child: Icon(Icons.map), - ), + leading: const Icon(Icons.map), initiallyExpanded: _jumpServer.value != null, title: Text(l10n.jumpServer), children: children, diff --git a/lib/view/page/setting/platform/ios.dart b/lib/view/page/setting/platform/ios.dart index f1c51e24c..f6406f149 100644 --- a/lib/view/page/setting/platform/ios.dart +++ b/lib/view/page/setting/platform/ios.dart @@ -114,8 +114,12 @@ class _IOSSettingsPageState extends State { final result = await AppRoutes.kvEditor(data: urls).go(context); if (result == null || result is! Map) return; - await context.showLoadingDialog(fn: () async { + final suc = await context.showLoadingDialog(fn: () async { await wc.updateApplicationContext({'urls': result}); + return true; }); + if (suc == true) { + context.showSnackBar(l10n.success); + } } } diff --git a/lib/view/page/storage/local.dart b/lib/view/page/storage/local.dart index 93ccb9938..46a4753f7 100644 --- a/lib/view/page/storage/local.dart +++ b/lib/view/page/storage/local.dart @@ -4,7 +4,7 @@ import 'package:fl_lib/fl_lib.dart'; import 'package:flutter/material.dart'; import 'package:server_box/core/extension/context/locale.dart'; import 'package:server_box/data/model/server/server_private_info.dart'; -import 'package:server_box/data/model/sftp/req.dart'; +import 'package:server_box/data/model/sftp/worker.dart'; import 'package:server_box/data/res/misc.dart'; import 'package:server_box/data/res/provider.dart'; import 'package:server_box/view/widget/omit_start_text.dart'; diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index 0b9ec52e7..0f3ca6aa2 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -11,16 +11,16 @@ import 'package:server_box/core/utils/comparator.dart'; import 'package:server_box/data/model/server/server_private_info.dart'; import 'package:server_box/data/model/sftp/absolute_path.dart'; import 'package:server_box/data/model/sftp/browser_status.dart'; -import 'package:server_box/data/model/sftp/req.dart'; +import 'package:server_box/data/model/sftp/worker.dart'; import 'package:server_box/data/res/misc.dart'; import 'package:server_box/data/res/provider.dart'; import 'package:server_box/data/res/store.dart'; import 'package:server_box/view/widget/omit_start_text.dart'; - -import 'package:icons_plus/icons_plus.dart'; import 'package:server_box/view/widget/two_line_text.dart'; import 'package:server_box/view/widget/unix_perm.dart'; +import 'package:icons_plus/icons_plus.dart'; + class SftpPage extends StatefulWidget { final ServerPrivateInfo spi; final String? initPath; @@ -401,16 +401,10 @@ class _SftpPageState extends State with AfterLayoutMixin { final permStr = newPerm.perm; if (ok == true && permStr != perm.perm) { - await context.showLoadingDialog( - fn: () async { - await _client!.run('chmod $permStr "${_getRemotePath(file)}"'); - await _listDir(); - }, - onErr: (e, s) { - context.showErrDialog(e: e, s: s, operation: l10n.permission); - return false; - }, - ); + await context.showLoadingDialog(fn: () async { + await _client!.run('chmod $permStr "${_getRemotePath(file)}"'); + await _listDir(); + }); } }, ), @@ -758,15 +752,22 @@ class _SftpPageState extends State with AfterLayoutMixin { context.showRoundDialog( title: l10n.error, child: Text('Unsupport file: ${name.filename}'), - actions: [ - TextButton( - onPressed: () => context.pop(), - child: Text(l10n.ok), - ), - ], + actions: Btns.oks(onTap: () => context.pop()), ); return; } + + final confirm = await context.showRoundDialog( + title: l10n.attention, + child: SimpleMarkdown(data: '```sh\n$cmd\n```'), + actions: Btns.okCancels( + onTapOk: () => context.pop(true), + onTapCancel: () => context.pop(false), + red: true, + ), + ); + if (confirm != true) return; + final suc = await context.showLoadingDialog( fn: () => _client?.run(cmd) ?? Future.value(false), ); diff --git a/lib/view/page/storage/sftp_mission.dart b/lib/view/page/storage/sftp_mission.dart index 4bf157179..d2b23d736 100644 --- a/lib/view/page/storage/sftp_mission.dart +++ b/lib/view/page/storage/sftp_mission.dart @@ -3,11 +3,10 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:server_box/core/extension/context/locale.dart'; import 'package:server_box/core/route.dart'; +import 'package:server_box/data/model/sftp/worker.dart'; +import 'package:server_box/data/provider/sftp.dart'; import 'package:server_box/data/res/provider.dart'; -import '../../../data/model/sftp/req.dart'; -import '../../../data/provider/sftp.dart'; - class SftpMissionPage extends StatefulWidget { const SftpMissionPage({super.key}); diff --git a/pubspec.lock b/pubspec.lock index 820959c5b..16a116477 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -385,8 +385,8 @@ packages: dependency: "direct main" description: path: "." - ref: "v1.0.89" - resolved-ref: "2ea7a87e7f4c1bd68902557799a4e9406e559dcf" + ref: "v1.0.90" + resolved-ref: "9f17bfce9f6cc9e071c40648bcac8d94e2dee919" url: "https://github.com/lppcg/fl_lib" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 7d8026d1f..51afb46bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,7 +62,7 @@ dependencies: fl_lib: git: url: https://github.com/lppcg/fl_lib - ref: v1.0.89 + ref: v1.0.90 dependency_overrides: # dartssh2: