Add meilisearch config settings dialogue
This commit is contained in:
123
lib/main.dart
123
lib/main.dart
@@ -13,6 +13,7 @@ import 'dart:math';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:ps_list/ps_list.dart';
|
import 'package:ps_list/ps_list.dart';
|
||||||
import 'package:journaler/meilisearch.dart';
|
import 'package:journaler/meilisearch.dart';
|
||||||
|
import 'package:journaler/meilisearch_config.dart';
|
||||||
|
|
||||||
// TODO: Sound does not play when ran from a different workdir? Weird
|
// TODO: Sound does not play when ran from a different workdir? Weird
|
||||||
// TODO: Fix saving the same scratch over and over again
|
// TODO: Fix saving the same scratch over and over again
|
||||||
@@ -67,8 +68,15 @@ Future<void> runPrimaryInstance(File ipcFile) async {
|
|||||||
startIpcWatcher(ipcFile);
|
startIpcWatcher(ipcFile);
|
||||||
|
|
||||||
// Initialize the app
|
// Initialize the app
|
||||||
// await DB.init();
|
try {
|
||||||
await init();
|
// Initialize Meilisearch first
|
||||||
|
await init();
|
||||||
|
debugPrint('Meilisearch initialized successfully');
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error initializing Meilisearch: $e');
|
||||||
|
// Continue anyway - the app will work with default values
|
||||||
|
}
|
||||||
|
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
|
|
||||||
WindowOptions windowOptions = const WindowOptions(
|
WindowOptions windowOptions = const WindowOptions(
|
||||||
@@ -1091,6 +1099,108 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show Meilisearch settings dialog
|
||||||
|
void _showMeilisearchSettings() {
|
||||||
|
final endpointController = TextEditingController();
|
||||||
|
final apiKeyController = TextEditingController();
|
||||||
|
bool isLoading = true;
|
||||||
|
String? errorMessage;
|
||||||
|
|
||||||
|
// Load current values
|
||||||
|
getMeilisearchEndpoint().then((value) {
|
||||||
|
endpointController.text = value;
|
||||||
|
isLoading = false;
|
||||||
|
}).catchError((e) {
|
||||||
|
errorMessage = 'Failed to load endpoint: $e';
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
getMeilisearchApiKey().then((value) {
|
||||||
|
apiKeyController.text = value;
|
||||||
|
}).catchError((e) {
|
||||||
|
errorMessage = 'Failed to load API key: $e';
|
||||||
|
});
|
||||||
|
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return StatefulBuilder(
|
||||||
|
builder: (context, setState) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Meilisearch Settings'),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (isLoading)
|
||||||
|
const Center(child: CircularProgressIndicator())
|
||||||
|
else if (errorMessage != null)
|
||||||
|
Text(
|
||||||
|
errorMessage!,
|
||||||
|
style: const TextStyle(color: Colors.red),
|
||||||
|
)
|
||||||
|
else ...[
|
||||||
|
TextField(
|
||||||
|
controller: endpointController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Endpoint URL',
|
||||||
|
hintText: 'http://localhost:7700',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
TextField(
|
||||||
|
controller: apiKeyController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'API Key',
|
||||||
|
hintText: 'masterKey',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
obscureText: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: isLoading ? null : () async {
|
||||||
|
try {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
errorMessage = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await setMeilisearchEndpoint(endpointController.text);
|
||||||
|
await setMeilisearchApiKey(apiKeyController.text);
|
||||||
|
|
||||||
|
// Try to reinitialize Meilisearch with new settings
|
||||||
|
await init();
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
errorMessage = 'Failed to save settings: $e';
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Save'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
// Wrap Scaffold with RawKeyboardListener as workaround for Escape key
|
||||||
@@ -1210,6 +1320,15 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
onPressed: _playSound,
|
onPressed: _playSound,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// Meilisearch Settings Button
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.settings),
|
||||||
|
tooltip: 'Meilisearch Settings',
|
||||||
|
onPressed: _showMeilisearchSettings,
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user