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,7 +111,6 @@ class _BodyState extends State<_Body> {
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (App.isDesktop)
|
||||
Tooltip(
|
||||
message: "Edit".tl,
|
||||
child: IconButton(
|
||||
@@ -165,7 +164,8 @@ class _BodyState extends State<_Body> {
|
||||
}
|
||||
} else {
|
||||
current = item.value['options']
|
||||
.firstWhere((e) => e['value'] == current)['text'] ?? current;
|
||||
.firstWhere((e) => e['value'] == current)['text'] ??
|
||||
current;
|
||||
}
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
@@ -249,6 +249,7 @@ class _BodyState extends State<_Body> {
|
||||
}
|
||||
|
||||
void edit(ComicSource source) async {
|
||||
if (App.isDesktop) {
|
||||
try {
|
||||
await Process.run("code", [source.filePath], runInShell: true);
|
||||
await showDialog(
|
||||
@@ -266,11 +267,18 @@ class _BodyState extends State<_Body> {
|
||||
},
|
||||
child: const Text("continue")),
|
||||
],
|
||||
));
|
||||
),
|
||||
);
|
||||
return;
|
||||
} catch (e) {
|
||||
context.showMessage(message: "Failed to launch vscode");
|
||||
//
|
||||
}
|
||||
}
|
||||
context.to(() => _EditFilePage(source.filePath)).then((value) async {
|
||||
await ComicSource.reload();
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> update(ComicSource source) async {
|
||||
if (!source.url.isURL) {
|
||||
@@ -300,12 +308,14 @@ class _BodyState extends State<_Body> {
|
||||
}
|
||||
|
||||
Widget buildCard(BuildContext context) {
|
||||
Widget buildButton({required Widget child, required VoidCallback onPressed}) {
|
||||
Widget buildButton(
|
||||
{required Widget child, required VoidCallback onPressed}) {
|
||||
return Button.normal(
|
||||
onPressed: onPressed,
|
||||
child: child,
|
||||
).fixHeight(32);
|
||||
}
|
||||
|
||||
return SliverToBoxAdapter(
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
@@ -561,3 +571,51 @@ void _addAllPagesWithComicSource(ComicSource source) {
|
||||
|
||||
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