mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Use the built-in editor to edit the config file if vscode is not installed.
This commit is contained in:
@@ -111,13 +111,12 @@ class _BodyState extends State<_Body> {
|
|||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
if (App.isDesktop)
|
Tooltip(
|
||||||
Tooltip(
|
message: "Edit".tl,
|
||||||
message: "Edit".tl,
|
child: IconButton(
|
||||||
child: IconButton(
|
onPressed: () => edit(source),
|
||||||
onPressed: () => edit(source),
|
icon: const Icon(Icons.edit_note)),
|
||||||
icon: const Icon(Icons.edit_note)),
|
),
|
||||||
),
|
|
||||||
Tooltip(
|
Tooltip(
|
||||||
message: "Update".tl,
|
message: "Update".tl,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
@@ -165,7 +164,8 @@ class _BodyState extends State<_Body> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
current = item.value['options']
|
current = item.value['options']
|
||||||
.firstWhere((e) => e['value'] == current)['text'] ?? current;
|
.firstWhere((e) => e['value'] == current)['text'] ??
|
||||||
|
current;
|
||||||
}
|
}
|
||||||
yield ListTile(
|
yield ListTile(
|
||||||
title: Text((item.value['title'] as String).ts(source.key)),
|
title: Text((item.value['title'] as String).ts(source.key)),
|
||||||
@@ -249,27 +249,35 @@ class _BodyState extends State<_Body> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void edit(ComicSource source) async {
|
void edit(ComicSource source) async {
|
||||||
try {
|
if (App.isDesktop) {
|
||||||
await Process.run("code", [source.filePath], runInShell: true);
|
try {
|
||||||
await showDialog(
|
await Process.run("code", [source.filePath], runInShell: true);
|
||||||
|
await showDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text("Reload Configs"),
|
title: const Text("Reload Configs"),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("cancel")),
|
child: const Text("cancel")),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ComicSource.reload();
|
await ComicSource.reload();
|
||||||
App.forceRebuild();
|
App.forceRebuild();
|
||||||
},
|
},
|
||||||
child: const Text("continue")),
|
child: const Text("continue")),
|
||||||
],
|
],
|
||||||
));
|
),
|
||||||
} catch (e) {
|
);
|
||||||
context.showMessage(message: "Failed to launch vscode");
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
context.to(() => _EditFilePage(source.filePath)).then((value) async {
|
||||||
|
await ComicSource.reload();
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> update(ComicSource source) async {
|
static Future<void> update(ComicSource source) async {
|
||||||
@@ -300,12 +308,14 @@ class _BodyState extends State<_Body> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildCard(BuildContext context) {
|
Widget buildCard(BuildContext context) {
|
||||||
Widget buildButton({required Widget child, required VoidCallback onPressed}) {
|
Widget buildButton(
|
||||||
|
{required Widget child, required VoidCallback onPressed}) {
|
||||||
return Button.normal(
|
return Button.normal(
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
child: child,
|
child: child,
|
||||||
).fixHeight(32);
|
).fixHeight(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
@@ -561,3 +571,51 @@ void _addAllPagesWithComicSource(ComicSource source) {
|
|||||||
|
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _EditFilePage extends StatefulWidget {
|
||||||
|
const _EditFilePage(this.path);
|
||||||
|
|
||||||
|
final String path;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_EditFilePage> createState() => __EditFilePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __EditFilePageState extends State<_EditFilePage> {
|
||||||
|
var current = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
current = File(widget.path).readAsStringSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
File(widget.path).writeAsStringSync(current);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: Appbar(
|
||||||
|
title: Text("Edit".tl),
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 0.6,
|
||||||
|
color: context.colorScheme.outlineVariant,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: CodeEditor(
|
||||||
|
initialValue: current,
|
||||||
|
onChanged: (value) => current = value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user