diff --git a/lib/app.dart b/lib/app.dart index 2b337fe5..691b5d26 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -29,34 +29,28 @@ class JournalApp extends StatefulWidget { static Future main(SharedPreferences pref) async { await Log.init(); - var settings = Settings(); - settings.load(pref); - var appSettings = AppSettings.instance; Log.i("AppSetting ${appSettings.toMap()}"); - Log.i("Setting ${settings.toLoggableMap()}"); if (appSettings.collectUsageStatistics) { - _enableAnalyticsIfPossible(appSettings, settings); + _enableAnalyticsIfPossible(appSettings); } _sendAppUpdateEvent(appSettings); final gitBaseDirectory = (await getApplicationDocumentsDirectory()).path; final cacheDir = (await getApplicationSupportDirectory()).path; - await settings.migrate(pref, gitBaseDirectory); - var repo = await Repository.load( gitBaseDir: gitBaseDirectory, cacheDir: cacheDir, - settings: settings, + pref: pref, name: "journal", ); Widget app = ChangeNotifierProvider.value( - value: settings, + value: repo, child: ChangeNotifierProvider.value( - value: repo, + value: repo.settings, child: ChangeNotifierProvider.value( child: JournalApp(), value: repo.notesFolder, @@ -82,8 +76,7 @@ class JournalApp extends StatefulWidget { )); } - static void _enableAnalyticsIfPossible( - AppSettings appSettings, Settings settings) async { + static void _enableAnalyticsIfPossible(AppSettings appSettings) async { JournalApp.isInDebugMode = foundation.kDebugMode; var isPhysicalDevice = true; @@ -120,8 +113,6 @@ class JournalApp extends StatefulWidget { name: 'proExpirationDate', value: appSettings.proExpirationDate.toString(), ); - - logEvent(Event.Settings, parameters: settings.toLoggableMap()); } } diff --git a/lib/repository.dart b/lib/repository.dart index ddc43a9d..df6c4c4e 100644 --- a/lib/repository.dart +++ b/lib/repository.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:dart_git/dart_git.dart'; import 'package:path/path.dart' as p; +import 'package:shared_preferences/shared_preferences.dart'; import 'package:synchronized/synchronized.dart'; import 'package:gitjournal/analytics.dart'; @@ -59,9 +60,18 @@ class Repository with ChangeNotifier { static Future load({ @required String gitBaseDir, @required String cacheDir, - @required Settings settings, + @required SharedPreferences pref, @required String name, }) async { + var settings = Settings(name); + settings.load(pref); + + await settings.migrate(pref, gitBaseDir); + + logEvent(Event.Settings, parameters: settings.toLoggableMap()); + + Log.i("Setting ${settings.toLoggableMap()}"); + var repoPath = settings.buildRepoPath(gitBaseDir); var repoDirStat = File(repoPath).statSync(); diff --git a/lib/settings.dart b/lib/settings.dart index 555fe3cd..a44979f3 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -13,7 +13,9 @@ import 'package:gitjournal/screens/note_editor.dart'; import 'package:gitjournal/utils/logger.dart'; class Settings extends ChangeNotifier { - Settings(); + Settings(this.folderName); + + String folderName; // Properties String gitAuthor = "GitJournal"; @@ -59,8 +61,6 @@ class Settings extends ChangeNotifier { bool bottomMenuBar = true; - String folderName = "journal"; - bool storeInternally = true; String storageLocation = ""; @@ -145,7 +145,7 @@ class Settings extends ChangeNotifier { Future save() async { var pref = await SharedPreferences.getInstance(); - var defaultSet = Settings(); + var defaultSet = Settings(folderName); _setString(pref, "gitAuthor", gitAuthor, defaultSet.gitAuthor); _setString( diff --git a/test/checklist_test.dart b/test/checklist_test.dart index 66688190..6d78823e 100644 --- a/test/checklist_test.dart +++ b/test/checklist_test.dart @@ -41,7 +41,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note.md"); File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -105,7 +105,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note2.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -120,7 +120,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note3.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -141,7 +141,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note13.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -161,7 +161,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note4.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -181,7 +181,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note4.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -197,7 +197,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note449.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -215,7 +215,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note448.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -231,7 +231,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note448.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -247,7 +247,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note449.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -264,7 +264,7 @@ Booga Wooga var notePath = p.join(tempDir.path, "note429.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); diff --git a/test/flattened_notes_folder_large_test.dart b/test/flattened_notes_folder_large_test.dart index dc828495..e244fbce 100644 --- a/test/flattened_notes_folder_large_test.dart +++ b/test/flattened_notes_folder_large_test.dart @@ -24,7 +24,7 @@ void main() { await _writeRandomNote(random, tempDir.path); } - rootFolder = NotesFolderFS(null, tempDir.path, Settings()); + rootFolder = NotesFolderFS(null, tempDir.path, Settings('')); await rootFolder.loadRecursively(); }); @@ -56,7 +56,7 @@ Future _writeRandomNote(Random random, String dirPath) async { } } - var note = Note(NotesFolderFS(null, dirPath, Settings()), path); + var note = Note(NotesFolderFS(null, dirPath, Settings('')), path); note.modified = DateTime(2014, 1, 1 + (random.nextInt(2000))); note.body = "p1"; await note.save(); diff --git a/test/flattened_notes_folder_test.dart b/test/flattened_notes_folder_test.dart index aa262e1b..4c8fc710 100644 --- a/test/flattened_notes_folder_test.dart +++ b/test/flattened_notes_folder_test.dart @@ -31,7 +31,7 @@ void main() { setUp(() async { tempDir = await Directory.systemTemp.createTemp('__sorted_folder_test__'); - rootFolder = NotesFolderFS(null, tempDir.path, Settings()); + rootFolder = NotesFolderFS(null, tempDir.path, Settings('')); for (var i = 0; i < 3; i++) { var note = Note(rootFolder, _getRandomFilePath(rootFolder.folderPath)); @@ -45,7 +45,7 @@ void main() { Directory(p.join(tempDir.path, "sub2")).createSync(); var sub1Folder = - NotesFolderFS(rootFolder, p.join(tempDir.path, "sub1"), Settings()); + NotesFolderFS(rootFolder, p.join(tempDir.path, "sub1"), Settings('')); for (var i = 0; i < 2; i++) { var note = Note( sub1Folder, @@ -57,7 +57,7 @@ void main() { } var sub2Folder = - NotesFolderFS(rootFolder, p.join(tempDir.path, "sub2"), Settings()); + NotesFolderFS(rootFolder, p.join(tempDir.path, "sub2"), Settings('')); for (var i = 0; i < 2; i++) { var note = Note( sub2Folder, @@ -69,7 +69,7 @@ void main() { } var p1Folder = NotesFolderFS( - sub1Folder, p.join(tempDir.path, "sub1", "p1"), Settings()); + sub1Folder, p.join(tempDir.path, "sub1", "p1"), Settings('')); for (var i = 0; i < 2; i++) { var note = Note( p1Folder, diff --git a/test/link_resolver_test.dart b/test/link_resolver_test.dart index f3a89ea3..77148175 100644 --- a/test/link_resolver_test.dart +++ b/test/link_resolver_test.dart @@ -15,7 +15,7 @@ void main() { setUpAll(() async { tempDir = await Directory.systemTemp.createTemp('__link_resolver__'); - rootFolder = NotesFolderFS(null, tempDir.path, Settings()); + rootFolder = NotesFolderFS(null, tempDir.path, Settings('')); await generateNote(tempDir.path, "Hello.md"); await generateNote(tempDir.path, "Fire.md"); diff --git a/test/note_serializer_test.dart b/test/note_serializer_test.dart index c704dcb4..284ee1df 100644 --- a/test/note_serializer_test.dart +++ b/test/note_serializer_test.dart @@ -10,7 +10,7 @@ import 'package:gitjournal/settings.dart'; void main() { group('Note Serializer Test', () { - var parent = NotesFolderFS(null, '/tmp', Settings()); + var parent = NotesFolderFS(null, '/tmp', Settings('')); test('Test emojis', () { var props = LinkedHashMap.from( diff --git a/test/note_storage_test.dart b/test/note_storage_test.dart index 048cc164..d97bd77b 100644 --- a/test/note_storage_test.dart +++ b/test/note_storage_test.dart @@ -28,7 +28,7 @@ void main() { n1Path = p.join(tempDir.path, "1.md"); n2Path = p.join(tempDir.path, "2.md"); - var parent = NotesFolderFS(null, tempDir.path, Settings()); + var parent = NotesFolderFS(null, tempDir.path, Settings('')); var n1 = Note(parent, n1Path); n1.body = "test"; n1.created = dt; @@ -52,7 +52,7 @@ void main() { expect(File(n2Path).existsSync(), isTrue); var loadedNotes = []; - var parent = NotesFolderFS(null, tempDir.path, Settings()); + var parent = NotesFolderFS(null, tempDir.path, Settings('')); await Future.forEach(notes, (origNote) async { var note = Note(parent, origNote.filePath); diff --git a/test/note_test.dart b/test/note_test.dart index 9ba6a1ad..6c3a2f73 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -30,7 +30,7 @@ Hello"""; var notePath = p.join(tempDir.path, "note.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -60,7 +60,7 @@ Hello"""; var notePath = p.join(tempDir.path, "note.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -90,7 +90,7 @@ Hello"""; var notePath = p.join(tempDir.path, "note5.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -128,7 +128,7 @@ bar: Foo var notePath = p.join(tempDir.path, "note6.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -148,7 +148,7 @@ bar: Foo var notePath = p.join(tempDir.path, "note63.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -173,7 +173,7 @@ Gee var notePath = p.join(tempDir.path, "note16.md"); await File(notePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note(parentFolder, notePath); await note.load(); @@ -195,7 +195,7 @@ Gee }); test('New Notes have a file extension', () async { - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var note = Note.newNote(parentFolder); var path = note.filePath; expect(path.endsWith('.md'), true); @@ -209,7 +209,7 @@ Gee var txtNotePath = p.join(tempDir.path, "note163.txt"); await File(txtNotePath).writeAsString(content); - var parentFolder = NotesFolderFS(null, tempDir.path, Settings()); + var parentFolder = NotesFolderFS(null, tempDir.path, Settings('')); var txtNote = Note(parentFolder, txtNotePath); await txtNote.load(); diff --git a/test/notes_cache_test.dart b/test/notes_cache_test.dart index 1474094b..d83e1176 100644 --- a/test/notes_cache_test.dart +++ b/test/notes_cache_test.dart @@ -25,7 +25,7 @@ void main() { cache = NotesCache( filePath: cacheFilePath, notesBasePath: '/base', - settings: Settings(), + settings: Settings(''), ); }); @@ -45,7 +45,7 @@ void main() { test('Should create directory structure accurately', () async { await cache.saveToDisk(fileList); - var rootFolder = NotesFolderFS(null, '/base', Settings()); + var rootFolder = NotesFolderFS(null, '/base', Settings('')); await cache.load(rootFolder); expect(rootFolder.subFolders.length, 2); diff --git a/test/notes_folder_config_test.dart b/test/notes_folder_config_test.dart index 4be4f0f8..c8028613 100644 --- a/test/notes_folder_config_test.dart +++ b/test/notes_folder_config_test.dart @@ -24,7 +24,7 @@ void main() { }); test('Should load from FS correctly', () async { - var folder = NotesFolderFS(null, tempDir.path, Settings()); + var folder = NotesFolderFS(null, tempDir.path, Settings('')); var config = NotesFolderConfig( defaultEditor: EditorType.Checklist, defaultView: FolderViewType.Standard, diff --git a/test/sorted_notes_folder_test.dart b/test/sorted_notes_folder_test.dart index 82cf45bc..fac13bb0 100644 --- a/test/sorted_notes_folder_test.dart +++ b/test/sorted_notes_folder_test.dart @@ -18,7 +18,7 @@ void main() { setUp(() async { tempDir = await Directory.systemTemp.createTemp('__sorted_folder_test__'); - folder = NotesFolderFS(null, tempDir.path, Settings()); + folder = NotesFolderFS(null, tempDir.path, Settings('')); var random = Random(); for (var i = 0; i < 5; i++) { @@ -122,7 +122,7 @@ void main() { }); test('If still sorted while loading the notes', () async { - var folder = NotesFolderFS(null, tempDir.path, Settings()); + var folder = NotesFolderFS(null, tempDir.path, Settings('')); var sf = SortedNotesFolder( folder: folder, sortingMode: diff --git a/test/sorting_mode_test.dart b/test/sorting_mode_test.dart index fdb4d0dd..0f7f868f 100644 --- a/test/sorting_mode_test.dart +++ b/test/sorting_mode_test.dart @@ -8,7 +8,7 @@ import 'package:gitjournal/settings.dart'; void main() { group('Sorting Mode', () { test('Created', () async { - var folder = NotesFolderFS(null, '/tmp/', Settings()); + var folder = NotesFolderFS(null, '/tmp/', Settings('')); var n1 = Note(folder, '/tmp/1.md'); n1.created = DateTime(2020, 10, 01); @@ -33,7 +33,7 @@ void main() { }); test('Modified', () async { - var folder = NotesFolderFS(null, '/tmp/', Settings()); + var folder = NotesFolderFS(null, '/tmp/', Settings('')); var n1 = Note(folder, '/tmp/1.md'); n1.modified = DateTime(2020, 10, 01);