mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
@@ -243,11 +243,4 @@ class AppRoutes {
|
||||
static AppRoutes pve({Key? key, required ServerPrivateInfo spi}) {
|
||||
return AppRoutes(PvePage(key: key, spi: spi), 'pve');
|
||||
}
|
||||
|
||||
static AppRoutes kvEditor({Key? key, required Map<String, String> data}) {
|
||||
return AppRoutes(
|
||||
KvEditor(key: key, args: KvEditorArgs(data: data)),
|
||||
'kv_editor',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,14 @@ class Snippet implements TagPickable {
|
||||
r'${ctrl': TerminalKey.control,
|
||||
r'${alt': TerminalKey.alt,
|
||||
};
|
||||
|
||||
static const example = Snippet(
|
||||
name: 'example',
|
||||
script: 'echo hello',
|
||||
tags: ['tag'],
|
||||
note: 'note',
|
||||
autoRunOn: ['server_id'],
|
||||
);
|
||||
}
|
||||
|
||||
class SnippetResult {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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/core/route.dart';
|
||||
import 'package:server_box/core/utils/misc.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
import 'package:server_box/view/page/setting/platform/platform_pub.dart';
|
||||
@@ -111,8 +110,11 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
|
||||
|
||||
void _onTapWatchApp(Map<String, dynamic> map) async {
|
||||
final urls = Map<String, String>.from(map['urls'] as Map? ?? {});
|
||||
final result = await AppRoutes.kvEditor(data: urls).go(context);
|
||||
if (result == null || result is! Map<String, String>) return;
|
||||
final result = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: urls),
|
||||
);
|
||||
if (result == null) return;
|
||||
|
||||
final (suc, err) = await context.showLoadingDialog(fn: () async {
|
||||
await wc.updateApplicationContext({'urls': result});
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/data/model/server/snippet.dart';
|
||||
import 'package:server_box/data/res/provider.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
|
||||
class SnippetEditPage extends StatefulWidget {
|
||||
const SnippetEditPage({super.key, this.snippet});
|
||||
@@ -102,8 +105,9 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
|
||||
Widget _buildBody() {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(13),
|
||||
padding: const EdgeInsets.symmetric(horizontal:13),
|
||||
children: [
|
||||
_buildImport(),
|
||||
Input(
|
||||
autoFocus: true,
|
||||
controller: _nameController,
|
||||
@@ -183,6 +187,61 @@ class _SnippetEditPageState extends State<SnippetEditPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImport() {
|
||||
return Btn.tile(
|
||||
text: l10n.import,
|
||||
icon: const Icon(BoxIcons.bx_import),
|
||||
onTap: (c) async {
|
||||
final data = await c.showImportDialog(
|
||||
title: l10n.snippet,
|
||||
modelDef: Snippet.example.toJson(),
|
||||
);
|
||||
if (data == null) return;
|
||||
final str = String.fromCharCodes(data);
|
||||
final list = json.decode(str) as List;
|
||||
if (list.isEmpty) return;
|
||||
final snippets = <Snippet>[];
|
||||
final errs = <String>[];
|
||||
for (final item in list) {
|
||||
try {
|
||||
final snippet = Snippet.fromJson(item);
|
||||
snippets.add(snippet);
|
||||
} catch (e) {
|
||||
errs.add(e.toString());
|
||||
}
|
||||
}
|
||||
if (snippets.isEmpty) {
|
||||
c.showSnackBar(libL10n.empty);
|
||||
return;
|
||||
}
|
||||
if (errs.isNotEmpty) {
|
||||
c.showRoundDialog(
|
||||
title: l10n.error,
|
||||
child: SingleChildScrollView(child: Text(errs.join('\n'))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final snippetNames = snippets.map((e) => e.name).join(', ');
|
||||
c.showRoundDialog(
|
||||
title: l10n.attention,
|
||||
child: SingleChildScrollView(
|
||||
child: Text(l10n.askContinue('${l10n.import} [$snippetNames]')),
|
||||
),
|
||||
actions: Btn.ok(
|
||||
onTap: (c) {
|
||||
for (final snippet in snippets) {
|
||||
Pros.snippet.add(snippet);
|
||||
}
|
||||
c.pop();
|
||||
context.pop();
|
||||
},
|
||||
).toList,
|
||||
);
|
||||
},
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTip() {
|
||||
return CardX(
|
||||
child: Padding(
|
||||
|
||||
@@ -385,8 +385,8 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "v1.0.105"
|
||||
resolved-ref: "0804b1363d451b6d25028ca393f552fbe1a32690"
|
||||
ref: "v1.0.106"
|
||||
resolved-ref: "31735eee1d42e6bcb6c3ccd061047401b4a23421"
|
||||
url: "https://github.com/lppcg/fl_lib"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
||||
@@ -62,7 +62,7 @@ dependencies:
|
||||
fl_lib:
|
||||
git:
|
||||
url: https://github.com/lppcg/fl_lib
|
||||
ref: v1.0.105
|
||||
ref: v1.0.106
|
||||
|
||||
dependency_overrides:
|
||||
# dartssh2:
|
||||
|
||||
Reference in New Issue
Block a user