Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
188619478e | |||
27f21a23fe | |||
d78db03d5d | |||
df93602db4 | |||
d6f9fa5032 | |||
64884cbb42 | |||
29f6f28f12 | |||
fadd9a7387 | |||
716a02a1dc | |||
6eb55c5d50 | |||
3c1f31d29b | |||
dfe1c2b34c | |||
89f8889f1e | |||
597ce8c9cf | |||
c2202bdfef | |||
8daf7ed6bf | |||
4339763261 | |||
621e85c747 | |||
d937ae212c | |||
b5dad28491 | |||
1e11cd53c9 | |||
b74dc5b3c6 | |||
474cb662e5 | |||
a84973def6 | |||
fcb8e41cde | |||
4f54b89689 | |||
eb2ec79150 | |||
e8b9f0ba49 | |||
6c8340d768 | |||
db565f4603 | |||
b2bff9e5c5 | |||
9d39cb09df | |||
5ea62a1216 | |||
c457b5cd5b | |||
722aa34fdf | |||
68c6dd1a95 | |||
5a27ac75c7 | |||
900bcd866c | |||
963f7271a2 | |||
442403b5b9 |
97
README.md
97
README.md
@@ -1,16 +1,93 @@
|
||||
# journaler
|
||||
# Journaler
|
||||
|
||||
A new Flutter project.
|
||||

|
||||
|
||||
## Getting Started
|
||||
Journaler is a "cross-platform" desktop application designed to encourage regular journaling by providing automated reminders and a clean writing environment.
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
## Overview
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
Journaler helps you build a consistent journaling habit by periodically reminding you to record your thoughts throughout the day. It runs silently in the system tray and pops up at customizable intervals, making it perfect for:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
- **Daily reflection and mindfulness practice**
|
||||
- **Tracking your thoughts and activities**
|
||||
- **Building a journaling habit**
|
||||
- **Capturing ideas before they fade**
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||

|
||||
|
||||
## Note
|
||||
|
||||
**Versions up to 3 use a local sqlite database while versions 4 and above use meillisearch!**
|
||||
|
||||
## Features
|
||||
|
||||
- **Automated Reminders**: Customizable popup intervals to remind you to journal
|
||||
- **System Tray Integration**: Runs silently in the background
|
||||
- **Scratch Pad**: Quick notes area for temporary thoughts
|
||||
- **Journal History**: Browse through past entries
|
||||
- **Full-Text Search**: Find entries containing specific words or phrases
|
||||
- **Dark/Light Theme**: Automatically follows your system theme
|
||||
- **Notification Sounds**: Audio cues when it's time to journal
|
||||
- **Single Instance**: Only one copy of the app runs at a time
|
||||
|
||||
## Usage
|
||||
|
||||
### Getting Started
|
||||
|
||||
1. **First Launch**: When you first launch Journaler, it will start in the system tray
|
||||
2. **Writing Entries**: The app will automatically pop up at set intervals (default: 20 minutes)
|
||||
3. **Manual Access**: Click the system tray icon to show the app manually
|
||||
4. **"Multiple" instances**: Running another instance will make the existing instance show itself
|
||||
5. **Saving entries**: Entries are saved automatically when the popup is closed either manually or by hitting the escape key
|
||||
|
||||
### Main Interface
|
||||
|
||||
1. **Current Entry**: Write your thoughts for the current moment
|
||||
2. **Previous Entry**: View what you wrote last time
|
||||
3. **Scratch Pad**: Space for quick notes that persist between sessions
|
||||
4. **Navigation**: Browse through your past entries
|
||||
5. **Search**: Find specific content in your journal history (May also be invoked by CTRL-F)
|
||||
|
||||

|
||||
|
||||
### Settings
|
||||
|
||||
You can adjust:
|
||||
|
||||
- **Popup Interval**: Change how frequently Journaler reminds you
|
||||
- **Notification Sound**: Select your preferred audio reminder
|
||||
- **Volume**: Adjust the sound level of reminders
|
||||
|
||||
## Data privacy
|
||||
|
||||
All your journal entries are stored securely on your local machine:
|
||||
|
||||
- **Windows**: `C:\Users\YourUsername\.journaler\`
|
||||
|
||||
No network requests are made, no data sent or received, your data is yours alone.
|
||||
|
||||
Data is stored in an SQLite database with a very simple schema that can be fucked with easily.
|
||||
|
||||
## Development
|
||||
|
||||
This application is built with Flutter. If you want to build from source:
|
||||
|
||||
1. Install Flutter (version 3.7.2 or higher)
|
||||
2. Clone the repository
|
||||
3. Run `flutter pub get` to install dependencies
|
||||
4. Use `flutter run` to run the application in debug mode
|
||||
|
||||
## Known issues
|
||||
|
||||
I don't know whether or not the sound customization works.<br>
|
||||
In theory only 2 sound files are bundled with the app so, in theory, you may only choose between those two.<br>
|
||||
But I don't know how flutter handles assets, currently I am not very motivated to figure this out.
|
||||
|
||||
Scrolling through long notes is difficult since we're intercepting the scroll event and using it to scroll through notes themselves.<br>
|
||||
This, again, is not really an issue for me so I'm not very motivated to fix it.
|
||||
|
||||
Showing and focusing the window is really annoying for "gamers" and generally whoever is doing anything at the time.<br>
|
||||
But I have no better ideas.<br>
|
||||
If we show the window without focusing it, it will still be on top and, if not focused, will be even more annoying because to close it you have to click on it (to focus it) and THEN close it.<br>
|
||||
If we only play the sound as a reminder we could miss it or simply get used to the sound and learn to ignore it.<br>
|
||||
I have no ideas for a better solution.
|
||||
|
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
(Stored with Git LFS)
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
(Stored with Git LFS)
Binary file not shown.
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
(Stored with Git LFS)
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
(Stored with Git LFS)
Binary file not shown.
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
(Stored with Git LFS)
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
(Stored with Git LFS)
Binary file not shown.
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
(Stored with Git LFS)
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
(Stored with Git LFS)
Binary file not shown.
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
(Stored with Git LFS)
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
(Stored with Git LFS)
Binary file not shown.
BIN
assets/windows/sqlite3_icu.dll
Normal file
BIN
assets/windows/sqlite3_icu.dll
Normal file
Binary file not shown.
BIN
docs/screenshots/journaler_annotated.png
(Stored with Git LFS)
Normal file
BIN
docs/screenshots/journaler_annotated.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
docs/screenshots/journaler_main.png
(Stored with Git LFS)
Normal file
BIN
docs/screenshots/journaler_main.png
(Stored with Git LFS)
Normal file
Binary file not shown.
@@ -427,7 +427,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
@@ -484,7 +484,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
|
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
(Stored with Git LFS)
Normal file
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
(Stored with Git LFS)
Binary file not shown.
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
(Stored with Git LFS)
BIN
ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
(Stored with Git LFS)
Binary file not shown.
373
lib/db.dart
373
lib/db.dart
@@ -6,10 +6,23 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
const settingsDir = '.journaler';
|
||||
const dbFileName = 'journaler.db';
|
||||
|
||||
// Add this at the top level
|
||||
typedef ShowMessageCallback = void Function(String message);
|
||||
|
||||
class DB {
|
||||
static late Database db;
|
||||
static bool _hasIcuSupport = false;
|
||||
static ShowMessageCallback? _showMessage;
|
||||
|
||||
static const String _schema = '''
|
||||
// Add this to register the callback
|
||||
static void registerMessageCallback(ShowMessageCallback callback) {
|
||||
_showMessage = callback;
|
||||
}
|
||||
|
||||
// Add this method to check ICU status
|
||||
static bool get hasIcuSupport => _hasIcuSupport;
|
||||
|
||||
static const String _baseSchema = '''
|
||||
CREATE TABLE IF NOT EXISTS notes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -17,19 +30,178 @@ CREATE TABLE IF NOT EXISTS notes (
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_notes_date ON notes (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_notes_date_unique ON notes (date);
|
||||
-- Todos are "static", we are only interested in the latest entry
|
||||
-- ie. they're not really a list but instead a string
|
||||
-- But we will also keep a history of all todos
|
||||
-- Because we might as well
|
||||
CREATE TABLE IF NOT EXISTS todos (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS scratches (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
content TEXT NOT NULL
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_todos_date ON todos (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
||||
CREATE INDEX IF NOT EXISTS idx_scratches_date ON scratches (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY NOT NULL,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
''';
|
||||
|
||||
static const String _ftsSchemaWithIcu = '''
|
||||
-- Create virtual FTS5 table with Unicode tokenizer
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(
|
||||
content,
|
||||
date,
|
||||
content='notes',
|
||||
content_rowid='id',
|
||||
tokenize='unicode61 remove_diacritics 2 tokenchars "\u0401\u0451\u0410-\u044f"'
|
||||
);
|
||||
''';
|
||||
|
||||
static const String _ftsSchemaBasic = '''
|
||||
-- Create virtual FTS5 table with basic tokenizer
|
||||
CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(
|
||||
content,
|
||||
date,
|
||||
content='notes',
|
||||
content_rowid='id',
|
||||
tokenize='unicode61'
|
||||
);
|
||||
''';
|
||||
|
||||
static const String _ftsTriggers = '''
|
||||
-- Trigger to keep FTS table in sync with notes table when inserting
|
||||
CREATE TRIGGER IF NOT EXISTS notes_ai AFTER INSERT ON notes BEGIN
|
||||
INSERT INTO notes_fts(rowid, content, date) VALUES (new.id, new.content, new.date);
|
||||
END;
|
||||
|
||||
-- Trigger to keep FTS table in sync when deleting notes
|
||||
CREATE TRIGGER IF NOT EXISTS notes_ad AFTER DELETE ON notes BEGIN
|
||||
DELETE FROM notes_fts WHERE rowid = old.id;
|
||||
END;
|
||||
|
||||
-- Trigger to keep FTS table in sync when updating notes
|
||||
CREATE TRIGGER IF NOT EXISTS notes_au AFTER UPDATE ON notes BEGIN
|
||||
UPDATE notes_fts SET content = new.content, date = new.date WHERE rowid = old.id;
|
||||
END;
|
||||
''';
|
||||
|
||||
// Add this method to check ICU status with visible feedback
|
||||
static Future<bool> checkAndShowIcuStatus() async {
|
||||
final status = _hasIcuSupport;
|
||||
final message =
|
||||
status
|
||||
? 'ICU support is enabled - Full Unicode search available'
|
||||
: 'ICU support is not available - Unicode search will be limited\n'
|
||||
'Looking for sqlite3_icu.dll in the application directory';
|
||||
debugPrint(message);
|
||||
_showMessage?.call(message);
|
||||
return status;
|
||||
}
|
||||
|
||||
static Future<bool> _checkIcuSupport(Database db) async {
|
||||
try {
|
||||
debugPrint(
|
||||
'\n================== CHECKING UNICODE SUPPORT ==================',
|
||||
);
|
||||
|
||||
// Test Unicode support with a simple query
|
||||
try {
|
||||
debugPrint('Testing Unicode support...');
|
||||
// Test with some Cyrillic characters
|
||||
await db.rawQuery("SELECT 'тест' LIKE '%ест%'");
|
||||
await db.rawQuery("SELECT 'ТЕСТ' LIKE '%ЕСТ%'");
|
||||
|
||||
final message = 'Unicode support is available';
|
||||
debugPrint(message);
|
||||
_showMessage?.call(message);
|
||||
return true;
|
||||
} catch (e, stackTrace) {
|
||||
final message = 'Unicode support test failed';
|
||||
debugPrint('$message:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
|
||||
// Try to get SQLite version and compile options for debugging
|
||||
try {
|
||||
final version = await db.rawQuery('SELECT sqlite_version()');
|
||||
final compileOpts = await db.rawQuery('PRAGMA compile_options');
|
||||
debugPrint('SQLite version: $version');
|
||||
debugPrint('SQLite compile options: $compileOpts');
|
||||
} catch (e) {
|
||||
debugPrint('Could not get SQLite info: $e');
|
||||
}
|
||||
|
||||
_showMessage?.call(message);
|
||||
return false;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
final message = 'Failed to test Unicode support';
|
||||
debugPrint('$message:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
_showMessage?.call(message);
|
||||
return false;
|
||||
} finally {
|
||||
debugPrint('=====================================================\n');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _recreateFtsTable(Database db, bool useIcu) async {
|
||||
debugPrint('Updating FTS table configuration...');
|
||||
|
||||
try {
|
||||
// Start a transaction to ensure data safety
|
||||
await db.transaction((txn) async {
|
||||
// First, create a temporary table with the new configuration
|
||||
final tempTableName = 'notes_fts_temp';
|
||||
final schema = useIcu ? _ftsSchemaWithIcu : _ftsSchemaBasic;
|
||||
|
||||
// Create temp table with new configuration
|
||||
await txn.execute(schema.replaceAll('notes_fts', tempTableName));
|
||||
|
||||
// Copy data from old FTS table if it exists
|
||||
try {
|
||||
debugPrint('Copying existing FTS data to temporary table...');
|
||||
await txn.execute('''
|
||||
INSERT INTO $tempTableName(rowid, content, date)
|
||||
SELECT rowid, content, date FROM notes_fts
|
||||
''');
|
||||
debugPrint('Data copied successfully');
|
||||
} catch (e) {
|
||||
debugPrint('No existing FTS data to copy: $e');
|
||||
}
|
||||
|
||||
// Drop old triggers
|
||||
debugPrint('Updating triggers...');
|
||||
await txn.execute('DROP TRIGGER IF EXISTS notes_ai');
|
||||
await txn.execute('DROP TRIGGER IF EXISTS notes_ad');
|
||||
await txn.execute('DROP TRIGGER IF EXISTS notes_au');
|
||||
|
||||
// Drop old FTS table
|
||||
await txn.execute('DROP TABLE IF EXISTS notes_fts');
|
||||
|
||||
// Rename temp table to final name
|
||||
await txn.execute('ALTER TABLE $tempTableName RENAME TO notes_fts');
|
||||
|
||||
// Create new triggers
|
||||
await txn.execute(_ftsTriggers);
|
||||
|
||||
// Rebuild FTS index from notes table to ensure consistency
|
||||
debugPrint('Rebuilding FTS index from notes table...');
|
||||
await txn.execute('''
|
||||
INSERT OR REPLACE INTO notes_fts(rowid, content, date)
|
||||
SELECT id, content, date FROM notes
|
||||
''');
|
||||
|
||||
debugPrint('FTS table update completed successfully');
|
||||
});
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Error updating FTS table:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<String> _getDatabasePath() async {
|
||||
debugPrint('Attempting to get database path...');
|
||||
if (Platform.isWindows || Platform.isLinux) {
|
||||
@@ -39,7 +211,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
||||
if (home == null) {
|
||||
throw Exception('Could not find home directory');
|
||||
}
|
||||
debugPrint('Home directory found: home');
|
||||
debugPrint('Home directory found: $home');
|
||||
|
||||
final dbDir = Directory(path.join(home, settingsDir));
|
||||
if (!await dbDir.exists()) {
|
||||
@@ -53,34 +225,193 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
||||
} else {
|
||||
// Default path for other platforms
|
||||
final databasesPath = await databaseFactoryFfi.getDatabasesPath();
|
||||
debugPrint('Using default databases path: databasesPath');
|
||||
debugPrint('Using default databases path: $databasesPath');
|
||||
return path.join(databasesPath, dbFileName);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> init() async {
|
||||
debugPrint('Starting database initialization...');
|
||||
|
||||
// Initialize SQLite FFI
|
||||
sqfliteFfiInit();
|
||||
final databaseFactory = databaseFactoryFfi;
|
||||
|
||||
final dbPath = await _getDatabasePath();
|
||||
debugPrint('Database path: dbPath');
|
||||
|
||||
// Create a temporary database to check version
|
||||
try {
|
||||
db = await databaseFactoryFfi.openDatabase(
|
||||
dbPath,
|
||||
debugPrint(
|
||||
'\n================== SQLITE VERSION CHECK ==================',
|
||||
);
|
||||
final tempDb = await databaseFactory.openDatabase(
|
||||
':memory:',
|
||||
options: OpenDatabaseOptions(
|
||||
version: 1,
|
||||
onCreate: (db, version) async {
|
||||
debugPrint('Creating database schema...');
|
||||
await db.execute(_schema);
|
||||
debugPrint('Database schema created successfully');
|
||||
final results = await db.rawQuery('SELECT sqlite_version()');
|
||||
debugPrint('SQLite version: ${results.first.values.first}');
|
||||
|
||||
final compileOpts = await db.rawQuery('PRAGMA compile_options');
|
||||
debugPrint('SQLite compile options:');
|
||||
for (var opt in compileOpts) {
|
||||
debugPrint(' ${opt.values.first}');
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
debugPrint('Database opened and initialized');
|
||||
} catch (e) {
|
||||
debugPrint('Failed to initialize database: e');
|
||||
await tempDb.close();
|
||||
debugPrint('=====================================================\n');
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Error checking SQLite version:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
}
|
||||
|
||||
await databaseFactory.setDatabasesPath(
|
||||
await databaseFactory.getDatabasesPath(),
|
||||
);
|
||||
|
||||
final dbPath = await _getDatabasePath();
|
||||
debugPrint('Database path: $dbPath');
|
||||
|
||||
try {
|
||||
db = await databaseFactory.openDatabase(
|
||||
dbPath,
|
||||
options: OpenDatabaseOptions(
|
||||
version: 2,
|
||||
onConfigure: (db) async {
|
||||
debugPrint('Configuring database...');
|
||||
await db.execute('PRAGMA foreign_keys = ON');
|
||||
debugPrint('Database configured');
|
||||
},
|
||||
onCreate: (db, version) async {
|
||||
debugPrint('Creating database schema...');
|
||||
await db.execute(_baseSchema);
|
||||
|
||||
// Check for Unicode support on first creation
|
||||
_hasIcuSupport = await _checkIcuSupport(db);
|
||||
await _recreateFtsTable(db, _hasIcuSupport);
|
||||
|
||||
debugPrint('Database schema created successfully');
|
||||
},
|
||||
onOpen: (db) async {
|
||||
debugPrint('Database opened, checking Unicode support...');
|
||||
try {
|
||||
_hasIcuSupport = await _checkIcuSupport(db);
|
||||
debugPrint('Unicode support check completed: $_hasIcuSupport');
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Error during Unicode support check:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
},
|
||||
onUpgrade: (db, oldVersion, newVersion) async {
|
||||
debugPrint('Upgrading database from $oldVersion to $newVersion');
|
||||
|
||||
if (oldVersion < 2) {
|
||||
// Check for Unicode support during upgrade
|
||||
_hasIcuSupport = await _checkIcuSupport(db);
|
||||
await _recreateFtsTable(db, _hasIcuSupport);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Store Unicode support status in settings for future reference
|
||||
await setSetting('has_icu_support', _hasIcuSupport.toString());
|
||||
debugPrint(
|
||||
'Database opened and initialized (Unicode support: $_hasIcuSupport)',
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Failed to initialize database:');
|
||||
debugPrint('Error: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Settings Management
|
||||
static Future<String?> getSetting(String key) async {
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'settings',
|
||||
columns: ['value'],
|
||||
where: 'key = ?',
|
||||
whereArgs: [key],
|
||||
);
|
||||
if (maps.isNotEmpty) {
|
||||
return maps.first['value'] as String?;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<void> setSetting(String key, String value) async {
|
||||
await db.insert('settings', {
|
||||
'key': key,
|
||||
'value': value,
|
||||
}, conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
debugPrint("Setting updated: $key = $value");
|
||||
}
|
||||
|
||||
// Search notes using FTS
|
||||
static Future<List<Map<String, dynamic>>> searchNotes(String query) async {
|
||||
try {
|
||||
if (query.trim().isEmpty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Split into individual terms, filter empty ones
|
||||
List<String> terms =
|
||||
query
|
||||
.trim()
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((term) => term.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
if (terms.isEmpty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Process terms for FTS5 query using proper tokenization
|
||||
String ftsQuery = terms
|
||||
.map((term) {
|
||||
// Remove dangerous characters but preserve Unicode
|
||||
String sanitizedTerm = term.replaceAll(RegExp(r'''['"]'''), '');
|
||||
if (sanitizedTerm.isEmpty) return '';
|
||||
|
||||
// Use proper FTS5 syntax: each word becomes a separate token with prefix matching
|
||||
List<String> words = sanitizedTerm.split(RegExp(r'\s+'));
|
||||
return words.map((word) => '$word*').join(' OR ');
|
||||
})
|
||||
.where((term) => term.isNotEmpty)
|
||||
.join(' AND ');
|
||||
|
||||
if (ftsQuery.isEmpty) {
|
||||
debugPrint('Query was sanitized to empty string');
|
||||
return [];
|
||||
}
|
||||
|
||||
ftsQuery = ftsQuery.replaceAll('-', ' ');
|
||||
debugPrint('FTS query: "$ftsQuery"');
|
||||
|
||||
// Execute the FTS query
|
||||
final List<Map<String, dynamic>> results = await db.rawQuery(
|
||||
'''
|
||||
SELECT n.id, n.date, n.content,
|
||||
snippet(notes_fts, -1, '<b>', '</b>', '...', 64) as snippet
|
||||
FROM notes_fts
|
||||
JOIN notes n ON notes_fts.rowid = n.id
|
||||
WHERE notes_fts MATCH ?
|
||||
ORDER BY rank
|
||||
''',
|
||||
[ftsQuery],
|
||||
);
|
||||
|
||||
debugPrint('Search returned ${results.length} results');
|
||||
return results;
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('Search failed: $e');
|
||||
debugPrint('Stack trace: $stackTrace');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1305
lib/main.dart
1305
lib/main.dart
File diff suppressed because it is too large
Load Diff
220
lib/meilifix.dart
Normal file
220
lib/meilifix.dart
Normal file
@@ -0,0 +1,220 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:journaler/meilisearch_config.dart';
|
||||
|
||||
const noteIndex = 'notes';
|
||||
const scratchIndex = 'scratch';
|
||||
final alphanum = RegExp(r'[a-zA-Z0-9]', caseSensitive: false);
|
||||
|
||||
class MeilisearchQuery {
|
||||
String q;
|
||||
String? filter;
|
||||
int? limit;
|
||||
int? offset;
|
||||
bool? showRankingScore;
|
||||
double? rankingScoreThreshold;
|
||||
String? highlightPreTag;
|
||||
String? highlightPostTag;
|
||||
List<String>? attributesToHighlight;
|
||||
List<String>? sort;
|
||||
|
||||
MeilisearchQuery({
|
||||
required this.q,
|
||||
this.filter,
|
||||
this.sort,
|
||||
this.limit,
|
||||
this.offset,
|
||||
this.showRankingScore,
|
||||
this.rankingScoreThreshold,
|
||||
this.highlightPreTag,
|
||||
this.highlightPostTag,
|
||||
this.attributesToHighlight,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> json = {'q': q};
|
||||
if (filter != null) json['filter'] = filter;
|
||||
if (sort != null) json['sort'] = sort;
|
||||
if (limit != null) json['limit'] = limit;
|
||||
if (offset != null) json['offset'] = offset;
|
||||
if (showRankingScore != null) json['showRankingScore'] = showRankingScore;
|
||||
if (rankingScoreThreshold != null) {
|
||||
json['rankingScoreThreshold'] = rankingScoreThreshold;
|
||||
}
|
||||
if (highlightPreTag != null) json['highlightPreTag'] = highlightPreTag;
|
||||
if (highlightPostTag != null) json['highlightPostTag'] = highlightPostTag;
|
||||
if (attributesToHighlight != null) {
|
||||
json['attributesToHighlight'] = attributesToHighlight;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
class MeilisearchResponse {
|
||||
final List<dynamic> hits;
|
||||
final String query;
|
||||
final int processingTimeMs;
|
||||
final int limit;
|
||||
final int offset;
|
||||
final int estimatedTotalHits;
|
||||
|
||||
MeilisearchResponse({
|
||||
required this.hits,
|
||||
required this.query,
|
||||
required this.processingTimeMs,
|
||||
required this.limit,
|
||||
required this.offset,
|
||||
required this.estimatedTotalHits,
|
||||
});
|
||||
|
||||
static MeilisearchResponse fromJson(Map<String, dynamic> json) {
|
||||
return MeilisearchResponse(
|
||||
hits: json['hits'],
|
||||
query: json['query'],
|
||||
processingTimeMs: json['processingTimeMs'],
|
||||
limit: json['limit'],
|
||||
offset: json['offset'],
|
||||
estimatedTotalHits: json['estimatedTotalHits'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, String>> _getHeaders() async {
|
||||
final apiKey = await getMeilisearchApiKey();
|
||||
return {
|
||||
'Authorization': 'Bearer $apiKey',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
|
||||
Future<String> _getEndpoint() async {
|
||||
return await getMeilisearchEndpoint();
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getAllDocuments(String index) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final allDocuments = <Map<String, dynamic>>[];
|
||||
var offset = 0;
|
||||
const limit = 100;
|
||||
|
||||
while (true) {
|
||||
final response = await http.get(
|
||||
Uri.parse('$endpoint/indexes/$index/documents?limit=$limit&offset=$offset'),
|
||||
headers: headers,
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to get documents: ${response.statusCode}');
|
||||
}
|
||||
final responseJson = jsonDecode(response.body);
|
||||
final documents = List<Map<String, dynamic>>.from(responseJson['results']);
|
||||
|
||||
if (documents.isEmpty) {
|
||||
break;
|
||||
}
|
||||
|
||||
allDocuments.addAll(documents);
|
||||
print('Found ${allDocuments.length} documents so far in $index');
|
||||
|
||||
if (documents.length < limit) {
|
||||
break;
|
||||
}
|
||||
|
||||
offset += limit;
|
||||
}
|
||||
|
||||
print('Total documents found in $index: ${allDocuments.length}');
|
||||
return allDocuments;
|
||||
}
|
||||
|
||||
Map<String, dynamic> fixDocument(Map<String, dynamic> doc) {
|
||||
final content = doc['content'] as String;
|
||||
final date = doc['date'] as int;
|
||||
|
||||
// Calculate letter frequency
|
||||
final letterFrequency = <String, int>{};
|
||||
for (final char in content.split('')) {
|
||||
if (alphanum.hasMatch(char)) {
|
||||
letterFrequency[char] = (letterFrequency[char] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
final mostFrequentLetter =
|
||||
letterFrequency.entries.isEmpty
|
||||
? 'a'
|
||||
: letterFrequency.entries
|
||||
.reduce((a, b) => a.value > b.value ? a : b)
|
||||
.key;
|
||||
|
||||
final mostFrequentLetterCount =
|
||||
letterFrequency.isEmpty
|
||||
? 0.0
|
||||
: letterFrequency[mostFrequentLetter]! / content.length;
|
||||
|
||||
return {
|
||||
...doc,
|
||||
'dateISO':
|
||||
DateTime.fromMillisecondsSinceEpoch(date).toUtc().toIso8601String(),
|
||||
'topLetter': mostFrequentLetter,
|
||||
'topLetterFrequency': mostFrequentLetterCount,
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> updateDocument(String index, Map<String, dynamic> doc) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$index/documents'),
|
||||
headers: headers,
|
||||
body: jsonEncode(doc),
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception('Failed to update document: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fixAllDocuments() async {
|
||||
print('Fixing notes...');
|
||||
final notes = await getAllDocuments(noteIndex);
|
||||
final noteBatches = <List<Map<String, dynamic>>>[];
|
||||
for (var i = 0; i < notes.length; i += 10) {
|
||||
noteBatches.add(notes.skip(i).take(10).toList());
|
||||
}
|
||||
|
||||
for (final batch in noteBatches) {
|
||||
await Future.wait(
|
||||
batch.map((note) async {
|
||||
final fixed = fixDocument(note);
|
||||
await updateDocument(noteIndex, fixed);
|
||||
print('Fixed note: ${note['id']}');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
print('Fixing scratches...');
|
||||
final scratches = await getAllDocuments(scratchIndex);
|
||||
final scratchBatches = <List<Map<String, dynamic>>>[];
|
||||
for (var i = 0; i < scratches.length; i += 10) {
|
||||
scratchBatches.add(scratches.skip(i).take(10).toList());
|
||||
}
|
||||
|
||||
for (final batch in scratchBatches) {
|
||||
await Future.wait(
|
||||
batch.map((scratch) async {
|
||||
final fixed = fixDocument(scratch);
|
||||
await updateDocument(scratchIndex, fixed);
|
||||
print('Fixed scratch: ${scratch['id']}');
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
await fixAllDocuments();
|
||||
print('All documents fixed successfully!');
|
||||
} catch (e) {
|
||||
print('Error fixing documents: $e');
|
||||
}
|
||||
}
|
529
lib/meilisearch.dart
Normal file
529
lib/meilisearch.dart
Normal file
@@ -0,0 +1,529 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
import 'dart:math';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:journaler/notes.dart';
|
||||
import 'package:journaler/meilisearch_config.dart';
|
||||
|
||||
const noteIndex = 'notes';
|
||||
const scratchIndex = 'scratch';
|
||||
const settingsIndex = 'settings';
|
||||
final alphanum = RegExp(r'[a-zA-Z0-9]', caseSensitive: false);
|
||||
|
||||
Future<Map<String, String>> _getHeaders() async {
|
||||
final apiKey = await getMeilisearchApiKey();
|
||||
return {
|
||||
'Authorization': 'Bearer $apiKey',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
|
||||
Future<String> _getEndpoint() async {
|
||||
return await getMeilisearchEndpoint();
|
||||
}
|
||||
|
||||
class MeilisearchQuery {
|
||||
String q;
|
||||
String? filter;
|
||||
int? limit;
|
||||
int? offset;
|
||||
bool? showRankingScore;
|
||||
double? rankingScoreThreshold;
|
||||
String? highlightPreTag;
|
||||
String? highlightPostTag;
|
||||
List<String>? attributesToHighlight;
|
||||
List<String>? sort;
|
||||
|
||||
MeilisearchQuery({
|
||||
required this.q,
|
||||
this.filter,
|
||||
this.sort,
|
||||
this.limit,
|
||||
this.offset,
|
||||
this.showRankingScore,
|
||||
this.rankingScoreThreshold,
|
||||
this.highlightPreTag,
|
||||
this.highlightPostTag,
|
||||
this.attributesToHighlight,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> json = {'q': q};
|
||||
if (filter != null) json['filter'] = filter;
|
||||
if (sort != null) json['sort'] = sort;
|
||||
if (limit != null) json['limit'] = limit;
|
||||
if (offset != null) json['offset'] = offset;
|
||||
if (showRankingScore != null) json['showRankingScore'] = showRankingScore;
|
||||
if (rankingScoreThreshold != null) {
|
||||
json['rankingScoreThreshold'] = rankingScoreThreshold;
|
||||
}
|
||||
if (highlightPreTag != null) json['highlightPreTag'] = highlightPreTag;
|
||||
if (highlightPostTag != null) json['highlightPostTag'] = highlightPostTag;
|
||||
if (attributesToHighlight != null) {
|
||||
json['attributesToHighlight'] = attributesToHighlight;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
class MeilisearchResponse {
|
||||
final List<dynamic> hits;
|
||||
final String query;
|
||||
final int processingTimeMs;
|
||||
final int limit;
|
||||
final int offset;
|
||||
final int estimatedTotalHits;
|
||||
|
||||
MeilisearchResponse({
|
||||
required this.hits,
|
||||
required this.query,
|
||||
required this.processingTimeMs,
|
||||
required this.limit,
|
||||
required this.offset,
|
||||
required this.estimatedTotalHits,
|
||||
});
|
||||
|
||||
static MeilisearchResponse fromJson(Map<String, dynamic> json) {
|
||||
return MeilisearchResponse(
|
||||
hits: json['hits'],
|
||||
query: json['query'],
|
||||
processingTimeMs: json['processingTimeMs'],
|
||||
limit: json['limit'],
|
||||
offset: json['offset'],
|
||||
estimatedTotalHits: json['estimatedTotalHits'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> init() async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
|
||||
if (!await indexExists(noteIndex)) {
|
||||
await http.post(
|
||||
Uri.parse('$endpoint/indexes'),
|
||||
headers: headers,
|
||||
body: jsonEncode({'uid': noteIndex, 'primaryKey': 'id'}),
|
||||
);
|
||||
}
|
||||
await http.put(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/settings/sortable-attributes'),
|
||||
headers: headers,
|
||||
body: jsonEncode(['date']),
|
||||
);
|
||||
await http.put(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/settings/filterable-attributes'),
|
||||
headers: headers,
|
||||
body: jsonEncode(['date', 'topLetter', 'topLetterFrequency']),
|
||||
);
|
||||
|
||||
if (!await indexExists(scratchIndex)) {
|
||||
await http.post(
|
||||
Uri.parse('$endpoint/indexes'),
|
||||
headers: headers,
|
||||
body: jsonEncode({'uid': scratchIndex, 'primaryKey': 'id'}),
|
||||
);
|
||||
}
|
||||
await http.put(
|
||||
Uri.parse('$endpoint/indexes/$scratchIndex/settings/sortable-attributes'),
|
||||
headers: headers,
|
||||
body: jsonEncode(['date']),
|
||||
);
|
||||
await http.put(
|
||||
Uri.parse('$endpoint/indexes/$scratchIndex/settings/filterable-attributes'),
|
||||
headers: headers,
|
||||
body: jsonEncode(['date']),
|
||||
);
|
||||
|
||||
if (!await indexExists(settingsIndex)) {
|
||||
await http.post(
|
||||
Uri.parse('$endpoint/indexes'),
|
||||
headers: headers,
|
||||
body: jsonEncode({'uid': settingsIndex, 'primaryKey': 'key'}),
|
||||
);
|
||||
}
|
||||
await http.put(
|
||||
Uri.parse('$endpoint/indexes/$settingsIndex/settings/filterable-attributes'),
|
||||
headers: headers,
|
||||
body: jsonEncode(['key', 'value']),
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> indexExists(String index) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final response = await http.get(
|
||||
Uri.parse('$endpoint/indexes/$index'),
|
||||
headers: headers,
|
||||
);
|
||||
return response.statusCode == 200;
|
||||
}
|
||||
|
||||
// Settings Management
|
||||
Future<String?> getSetting(String key) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(q: '', filter: 'key = $key');
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$settingsIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to get settings');
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
if (responseJson.hits.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return responseJson.hits.first['value'] as String?;
|
||||
}
|
||||
|
||||
Future<void> setSetting(String key, String value) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final document = {'key': key, 'value': value};
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$settingsIndex/documents'),
|
||||
headers: headers,
|
||||
body: jsonEncode(document),
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception('Failed to set settings');
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe we could factor a lot of this out into a separate function
|
||||
// But we don't care for now...
|
||||
Future<List<Note>> searchNotes(String query) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: query,
|
||||
limit: 10,
|
||||
attributesToHighlight: ['content'],
|
||||
showRankingScore: true,
|
||||
highlightPreTag: '<highlight>',
|
||||
highlightPostTag: '</highlight>',
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to search notes');
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
return responseJson.hits
|
||||
.map(
|
||||
(hit) => Note(
|
||||
id: hit['id'] as String,
|
||||
epochTime: hit['date'] as int,
|
||||
content: hit['content'] as String,
|
||||
snippet: hit['_formatted']['content'] as String,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<Note?> getPreviousTo(int epochTime) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
filter: 'date < $epochTime',
|
||||
sort: ['date:desc'],
|
||||
limit: 1,
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Failed to get previous note, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
if (responseJson.hits.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Note(
|
||||
id: responseJson.hits.first['id'] as String,
|
||||
epochTime: responseJson.hits.first['date'] as int,
|
||||
content: responseJson.hits.first['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Note?> getNextTo(int epochTime) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
filter: 'date > $epochTime',
|
||||
sort: ['date:asc'],
|
||||
limit: 1,
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Failed to get next note, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
if (responseJson.hits.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Note(
|
||||
id: responseJson.hits.first['id'] as String,
|
||||
epochTime: responseJson.hits.first['date'] as int,
|
||||
content: responseJson.hits.first['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Note?> getLatest() async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
sort: ['date:desc'],
|
||||
limit: 1,
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Failed to get latest note, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
if (responseJson.hits.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Note(
|
||||
id: responseJson.hits.first['id'] as String,
|
||||
epochTime: responseJson.hits.first['date'] as int,
|
||||
content: responseJson.hits.first['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
String generateRandomString(int length) {
|
||||
const characters =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
var result = '';
|
||||
for (var i = 0; i < length; i++) {
|
||||
final randomIndex = Random().nextInt(characters.length);
|
||||
result += characters[randomIndex];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Note> createNote(String content) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final lines = content.split('\n');
|
||||
final trimmedLines = <String>[];
|
||||
for (final line in lines) {
|
||||
final trimmedContent = line.trim().replaceAll(RegExp(r'\s{2,}'), ' ');
|
||||
if (trimmedContent.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
trimmedLines.add(trimmedContent);
|
||||
}
|
||||
final trimmedContent = trimmedLines.join('\n');
|
||||
|
||||
final letterFrequency = <String, int>{};
|
||||
for (final char in trimmedContent.split('')) {
|
||||
if (alphanum.hasMatch(char)) {
|
||||
letterFrequency[char] = (letterFrequency[char] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
final mostFrequentLetter =
|
||||
letterFrequency.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||
final mostFrequentLetterCount =
|
||||
letterFrequency[mostFrequentLetter]! / trimmedContent.length;
|
||||
|
||||
final document = {
|
||||
'id': generateRandomString(32),
|
||||
'date': DateTime.now().toUtc().millisecondsSinceEpoch,
|
||||
'dateISO': DateTime.now().toUtc().toIso8601String(),
|
||||
'content': content,
|
||||
'topLetter': mostFrequentLetter,
|
||||
'topLetterFrequency': mostFrequentLetterCount,
|
||||
};
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/documents'),
|
||||
headers: headers,
|
||||
body: jsonEncode(document),
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception('Failed to create note');
|
||||
}
|
||||
return Note(
|
||||
id: document['id'] as String,
|
||||
epochTime: document['date'] as int,
|
||||
content: document['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<Note>> getProblematic({double threshold = 0.7}) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
filter: 'topLetterFrequency > $threshold',
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Failed to get problematic notes, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
return responseJson.hits
|
||||
.map(
|
||||
(hit) => Note(
|
||||
id: hit['id'] as String,
|
||||
epochTime: hit['date'] as int,
|
||||
content: hit['content'] as String,
|
||||
isProblematic: true,
|
||||
problemReason:
|
||||
'Character "${hit['topLetter']}" makes up ${(hit['topLetterFrequency'] * 100).toStringAsFixed(1)}% of the content',
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// TODO: only update if changed
|
||||
// How? idk
|
||||
Future<void> updateNote(Note note) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final lines = note.content.split('\n');
|
||||
final trimmedLines = <String>[];
|
||||
for (final line in lines) {
|
||||
final trimmedContent = line.trim().replaceAll(RegExp(r'\s{2,}'), ' ');
|
||||
if (trimmedContent.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
trimmedLines.add(trimmedContent);
|
||||
}
|
||||
final trimmedContent = trimmedLines.join('\n');
|
||||
|
||||
final letterFrequency = <String, int>{};
|
||||
for (final char in trimmedContent.split('')) {
|
||||
if (alphanum.hasMatch(char)) {
|
||||
letterFrequency[char] = (letterFrequency[char] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
final mostFrequentLetter =
|
||||
letterFrequency.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||
final mostFrequentLetterRatio =
|
||||
letterFrequency[mostFrequentLetter]! / trimmedContent.length;
|
||||
|
||||
final document = {
|
||||
'id': note.id,
|
||||
'content': trimmedContent,
|
||||
'date': note.epochTime,
|
||||
'dateISO':
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
note.epochTime,
|
||||
).toUtc().toIso8601String(),
|
||||
'topLetter': mostFrequentLetter,
|
||||
'topLetterFrequency': mostFrequentLetterRatio,
|
||||
};
|
||||
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/documents'),
|
||||
headers: headers,
|
||||
body: jsonEncode(document),
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception(
|
||||
'Failed to update note, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteNote(String id) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final response = await http.delete(
|
||||
Uri.parse('$endpoint/indexes/$noteIndex/documents/$id'),
|
||||
headers: headers,
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception(
|
||||
'Failed to delete note, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Scratch?> getLatestScratch() async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final searchCondition = MeilisearchQuery(
|
||||
q: '',
|
||||
sort: ['date:desc'],
|
||||
limit: 1,
|
||||
);
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$scratchIndex/search'),
|
||||
headers: headers,
|
||||
body: jsonEncode(searchCondition.toJson()),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception(
|
||||
'Failed to get latest scratch, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
final responseJson = MeilisearchResponse.fromJson(jsonDecode(response.body));
|
||||
if (responseJson.hits.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Scratch(
|
||||
id: responseJson.hits.first['id'] as String,
|
||||
epochTime: responseJson.hits.first['date'] as int,
|
||||
content: responseJson.hits.first['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<Scratch> createScratch(String content) async {
|
||||
final endpoint = await _getEndpoint();
|
||||
final headers = await _getHeaders();
|
||||
final document = {
|
||||
'id': generateRandomString(32),
|
||||
'date': DateTime.now().toUtc().millisecondsSinceEpoch,
|
||||
'content': content,
|
||||
};
|
||||
final response = await http.post(
|
||||
Uri.parse('$endpoint/indexes/$scratchIndex/documents'),
|
||||
headers: headers,
|
||||
body: jsonEncode(document),
|
||||
);
|
||||
if (response.statusCode != 202) {
|
||||
throw Exception(
|
||||
'Failed to create scratch, backend responded with ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
return Scratch(
|
||||
id: document['id'] as String,
|
||||
epochTime: document['date'] as int,
|
||||
content: document['content'] as String,
|
||||
);
|
||||
}
|
133
lib/meilisearch_config.dart
Normal file
133
lib/meilisearch_config.dart
Normal file
@@ -0,0 +1,133 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
const defaultEndpoint = 'http://localhost:7700';
|
||||
const defaultApiKey = 'masterKey';
|
||||
|
||||
// Cache for configuration
|
||||
String? _cachedEndpoint;
|
||||
String? _cachedApiKey;
|
||||
bool _isInitialized = false;
|
||||
|
||||
// Get the config file path in the user's home directory
|
||||
Future<String> _getConfigPath() async {
|
||||
final home =
|
||||
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];
|
||||
if (home == null) {
|
||||
throw Exception('Could not find home directory');
|
||||
}
|
||||
final configDir = Directory(path.join(home, '.journaler'));
|
||||
if (!await configDir.exists()) {
|
||||
await configDir.create(recursive: true);
|
||||
}
|
||||
return path.join(configDir.path, 'meilisearch_config.enc');
|
||||
}
|
||||
|
||||
// Simple encryption key derived from machine-specific data
|
||||
String _getEncryptionKey() {
|
||||
final machineId =
|
||||
Platform.operatingSystem +
|
||||
Platform.operatingSystemVersion +
|
||||
Platform.localHostname;
|
||||
return sha256.convert(utf8.encode(machineId)).toString();
|
||||
}
|
||||
|
||||
// Encrypt data
|
||||
String _encrypt(String data) {
|
||||
final key = _getEncryptionKey();
|
||||
final bytes = utf8.encode(data);
|
||||
final encrypted = <int>[];
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
encrypted.add(bytes[i] ^ key.codeUnitAt(i % key.length));
|
||||
}
|
||||
return base64.encode(encrypted);
|
||||
}
|
||||
|
||||
// Decrypt data
|
||||
String _decrypt(String encrypted) {
|
||||
final key = _getEncryptionKey();
|
||||
final bytes = base64.decode(encrypted);
|
||||
final decrypted = <int>[];
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
decrypted.add(bytes[i] ^ key.codeUnitAt(i % key.length));
|
||||
}
|
||||
return utf8.decode(decrypted);
|
||||
}
|
||||
|
||||
// Initialize cache from file
|
||||
Future<void> _initializeCache() async {
|
||||
if (_isInitialized) return;
|
||||
|
||||
try {
|
||||
final configPath = await _getConfigPath();
|
||||
final file = File(configPath);
|
||||
if (!await file.exists()) {
|
||||
_cachedEndpoint = defaultEndpoint;
|
||||
_cachedApiKey = defaultApiKey;
|
||||
_isInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
final encrypted = await file.readAsString();
|
||||
final decrypted = _decrypt(encrypted);
|
||||
final config = jsonDecode(decrypted);
|
||||
|
||||
_cachedEndpoint = config['endpoint'] ?? defaultEndpoint;
|
||||
_cachedApiKey = config['apiKey'] ?? defaultApiKey;
|
||||
} catch (e) {
|
||||
_cachedEndpoint = defaultEndpoint;
|
||||
_cachedApiKey = defaultApiKey;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
Future<String> getMeilisearchEndpoint() async {
|
||||
await _initializeCache();
|
||||
return _cachedEndpoint!;
|
||||
}
|
||||
|
||||
Future<String> getMeilisearchApiKey() async {
|
||||
await _initializeCache();
|
||||
return _cachedApiKey!;
|
||||
}
|
||||
|
||||
Future<void> setMeilisearchEndpoint(String endpoint) async {
|
||||
final configPath = await _getConfigPath();
|
||||
final file = File(configPath);
|
||||
|
||||
Map<String, dynamic> config = {};
|
||||
if (await file.exists()) {
|
||||
final encrypted = await file.readAsString();
|
||||
final decrypted = _decrypt(encrypted);
|
||||
config = jsonDecode(decrypted);
|
||||
}
|
||||
|
||||
config['endpoint'] = endpoint;
|
||||
final encrypted = _encrypt(jsonEncode(config));
|
||||
await file.writeAsString(encrypted);
|
||||
|
||||
// Update cache
|
||||
_cachedEndpoint = endpoint;
|
||||
}
|
||||
|
||||
Future<void> setMeilisearchApiKey(String apiKey) async {
|
||||
final configPath = await _getConfigPath();
|
||||
final file = File(configPath);
|
||||
|
||||
Map<String, dynamic> config = {};
|
||||
if (await file.exists()) {
|
||||
final encrypted = await file.readAsString();
|
||||
final decrypted = _decrypt(encrypted);
|
||||
config = jsonDecode(decrypted);
|
||||
}
|
||||
|
||||
config['apiKey'] = apiKey;
|
||||
final encrypted = _encrypt(jsonEncode(config));
|
||||
await file.writeAsString(encrypted);
|
||||
|
||||
// Update cache
|
||||
_cachedApiKey = apiKey;
|
||||
}
|
@@ -1,64 +1,32 @@
|
||||
import 'package:journaler/db.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class Note {
|
||||
final String date;
|
||||
final String id;
|
||||
final int epochTime;
|
||||
late final String displayDate;
|
||||
String content;
|
||||
String? snippet;
|
||||
bool isProblematic;
|
||||
String problemReason;
|
||||
|
||||
Note({
|
||||
required this.id,
|
||||
required this.epochTime,
|
||||
required this.content,
|
||||
this.snippet,
|
||||
this.isProblematic = false,
|
||||
this.problemReason = '',
|
||||
}) {
|
||||
final dtUtc = DateTime.fromMillisecondsSinceEpoch(epochTime, isUtc: true);
|
||||
final dtLocal = dtUtc.toLocal();
|
||||
displayDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(dtLocal);
|
||||
}
|
||||
}
|
||||
|
||||
class Scratch {
|
||||
final int epochTime;
|
||||
final String id;
|
||||
String content;
|
||||
|
||||
Note({required this.date, required this.content});
|
||||
}
|
||||
|
||||
class Todo {
|
||||
final String date;
|
||||
final String content;
|
||||
|
||||
Todo({required this.date, required this.content});
|
||||
}
|
||||
|
||||
Future<Note?> getLatestNote() async {
|
||||
final note = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM notes ORDER BY date DESC LIMIT 1',
|
||||
);
|
||||
if (note.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Note(
|
||||
date: note[0]['date'] as String,
|
||||
content: note[0]['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createNote(String content) async {
|
||||
if (content.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await DB.db.insert('notes', {'content': content});
|
||||
}
|
||||
|
||||
Future<void> updateNote(Note note) async {
|
||||
await DB.db.update(
|
||||
'notes',
|
||||
{'content': note.content},
|
||||
where: 'date = ?',
|
||||
whereArgs: [note.date],
|
||||
);
|
||||
}
|
||||
|
||||
Future<Todo?> getLatestTodo() async {
|
||||
final todo = await DB.db.rawQuery(
|
||||
'SELECT content, date FROM todos ORDER BY date DESC LIMIT 1',
|
||||
);
|
||||
if (todo.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return Todo(
|
||||
date: todo[0]['date'] as String,
|
||||
content: todo[0]['content'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createTodo(String content) async {
|
||||
if (content.isEmpty) {
|
||||
return;
|
||||
}
|
||||
await DB.db.insert('todos', {'content': content});
|
||||
Scratch({required this.id, required this.epochTime, required this.content});
|
||||
}
|
||||
|
39
lib/utils.dart
Normal file
39
lib/utils.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:journaler/meilisearch.dart';
|
||||
|
||||
Future<double> getVolume() async {
|
||||
try {
|
||||
final volumeStr = await getSetting('notificationVolume');
|
||||
return double.tryParse(volumeStr ?? '0.7') ?? 0.7;
|
||||
} catch (e) {
|
||||
return 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setVolume(double volume) async {
|
||||
await setSetting('notificationVolume', volume.toString());
|
||||
}
|
||||
|
||||
Future<Duration> getPopupInterval() async {
|
||||
try {
|
||||
final intervalStr = await getSetting('popupIntervalMinutes');
|
||||
return Duration(minutes: int.tryParse(intervalStr ?? '10') ?? 10);
|
||||
} catch (e) {
|
||||
return Duration(minutes: 10);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setPopupInterval(Duration interval) async {
|
||||
await setSetting('popupIntervalMinutes', interval.inMinutes.toString());
|
||||
}
|
||||
|
||||
Future<String> getNotificationSound() async {
|
||||
try {
|
||||
return await getSetting('notificationSound') ?? 'MeetTheSniper.mp3';
|
||||
} catch (e) {
|
||||
return 'MeetTheSniper.mp3';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setNotificationSound(String sound) async {
|
||||
await setSetting('notificationSound', sound);
|
||||
}
|
106
pubspec.lock
106
pubspec.lock
@@ -1,6 +1,22 @@
|
||||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
archive:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: archive
|
||||
sha256: a7f37ff061d7abc2fcf213554b9dcaca713c5853afa5c065c44888bc9ccaf813
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.6"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.7.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -81,6 +97,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
checked_yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: checked_yaml
|
||||
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.3"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: cli_util
|
||||
sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -98,7 +130,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypto
|
||||
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
|
||||
@@ -142,6 +174,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_launcher_icons
|
||||
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.13.1"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -161,13 +201,13 @@ packages:
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
http:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
|
||||
sha256: "2c11f3f94c687ee9bad77c171151672986360b2b001d109814ee7140b2cf261b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.4.0"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -176,6 +216,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.1.2"
|
||||
image:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: image
|
||||
sha256: "4e973fcf4caae1a4be2fa0a13157aa38a8f9cb049db6529aa00b4d71abc4d928"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.5.4"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: intl
|
||||
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.20.2"
|
||||
json_annotation:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -241,7 +297,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path
|
||||
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
|
||||
@@ -296,6 +352,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: petitparser
|
||||
sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.0"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -312,6 +376,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.8"
|
||||
posix:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: posix
|
||||
sha256: f0d7856b6ca1887cfa6d1d394056a296ae33489db914e365e2044fdada449e62
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.0.2"
|
||||
ps_list:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: ps_list
|
||||
sha256: "19d32f6c643313cf4f5101bb144b8978b9ba3dc42c9a01b247e8ed90581bc0ab"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.0.5"
|
||||
screen_retriever:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -501,6 +581,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xml
|
||||
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.5.0"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.3"
|
||||
sdks:
|
||||
dart: ">=3.7.2 <4.0.0"
|
||||
flutter: ">=3.27.0"
|
||||
|
16
pubspec.yaml
16
pubspec.yaml
@@ -38,10 +38,16 @@ dependencies:
|
||||
window_manager: ^0.4.3
|
||||
audioplayers: ^6.4.0
|
||||
sqflite_common_ffi: ^2.3.5
|
||||
path: ^1.8.0
|
||||
ps_list: ^0.0.5
|
||||
intl: ^0.20.2
|
||||
http: ^1.4.0
|
||||
crypto: ^3.0.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_launcher_icons: ^0.13.1
|
||||
|
||||
# The "flutter_lints" package below contains a set of recommended lints to
|
||||
# encourage good coding practices. The lint set provided by the package is
|
||||
@@ -65,6 +71,7 @@ flutter:
|
||||
assets:
|
||||
- assets/ # Include the main assets directory for the icon
|
||||
- assets/sounds/
|
||||
- assets/windows/sqlite3_icu.dll
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
@@ -93,3 +100,12 @@ flutter:
|
||||
#
|
||||
# For details regarding fonts from package dependencies,
|
||||
# see https://flutter.dev/to/font-from-package
|
||||
|
||||
flutter_launcher_icons:
|
||||
android: true
|
||||
ios: true
|
||||
image_path: "assets/app_icon.ico"
|
||||
windows:
|
||||
generate: true
|
||||
image_path: "assets/app_icon.ico"
|
||||
icon_size: 256 # min: 48, max: 256, default: 48
|
||||
|
BIN
windows/runner/resources/app_icon.ico
(Stored with Git LFS)
BIN
windows/runner/resources/app_icon.ico
(Stored with Git LFS)
Binary file not shown.
Reference in New Issue
Block a user