From eb4d99338b78c5e2c4b70cf3addf13e7fdf3f282 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Fri, 25 Sep 2020 00:40:23 +0200 Subject: [PATCH] Remove some uses of the Settings singleton It needs to be removed from everywhere. --- lib/apis/git_migration.dart | 7 ++++--- lib/core/git_repo.dart | 42 +++++++++++++++++++------------------ lib/state_container.dart | 6 ++++-- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/lib/apis/git_migration.dart b/lib/apis/git_migration.dart index d1208bf2..b5e9de92 100644 --- a/lib/apis/git_migration.dart +++ b/lib/apis/git_migration.dart @@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; import 'package:git_bindings/git_bindings.dart'; import 'package:path/path.dart' as p; -import 'package:gitjournal/settings.dart'; import 'package:gitjournal/utils/logger.dart'; // @@ -16,6 +15,8 @@ Future migrateGitRepo({ @required String gitBasePath, @required String fromGitBasePath, @required String toGitBaseFolder, + @required String gitAuthor, + @required String gitAuthorEmail, }) async { Log.d("migrateGitRepo $fromGitBasePath $toGitBaseFolder"); var fromBasePath = p.join(gitBasePath, fromGitBasePath); @@ -40,8 +41,8 @@ Future migrateGitRepo({ await gitRepo.add(fileName); await gitRepo.commit( message: "Added Note", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: gitAuthorEmail, + authorName: gitAuthor, ); } Log.d("migrateGitRepo: Done"); diff --git a/lib/core/git_repo.dart b/lib/core/git_repo.dart index 8f2e95ab..5e6a83a0 100644 --- a/lib/core/git_repo.dart +++ b/lib/core/git_repo.dart @@ -25,9 +25,11 @@ class NoteRepoResult { class GitNoteRepository { final String gitDirPath; final GitRepo _gitRepo; + final Settings settings; GitNoteRepository({ @required this.gitDirPath, + @required this.settings, }) : _gitRepo = GitRepo(folderPath: gitDirPath); Future addNote(Note note) async { @@ -38,8 +40,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: commitMessage, - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: note.filePath, error: false); @@ -49,8 +51,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Created New Folder", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: folder.folderPath, error: false); @@ -63,8 +65,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Update folder config for $pathSpec", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: config.folder.folderPath, error: false); @@ -78,8 +80,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Renamed Folder", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: newFullPath, error: false); @@ -93,8 +95,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Renamed Note", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: newFullPath, error: false); @@ -108,8 +110,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Renamed File", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: newFullPath, error: false); @@ -123,8 +125,8 @@ class GitNoteRepository { await _gitRepo.add("."); await _gitRepo.commit( message: "Note Moved", - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: newFullPath, error: false); @@ -136,8 +138,8 @@ class GitNoteRepository { await _gitRepo.rm(spec); await _gitRepo.commit( message: "Removed Note " + spec, - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); return NoteRepoResult(noteFilePath: note.filePath, error: false); @@ -148,8 +150,8 @@ class GitNoteRepository { await _gitRepo.rm(spec); await _gitRepo.commit( message: "Removed Folder " + spec, - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); await Directory(folder.folderPath).delete(recursive: true); @@ -169,8 +171,8 @@ class GitNoteRepository { Future pull() async { try { await _gitRepo.pull( - authorEmail: Settings.instance.gitAuthorEmail, - authorName: Settings.instance.gitAuthor, + authorEmail: settings.gitAuthorEmail, + authorName: settings.gitAuthor, ); } on GitException catch (ex, stackTrace) { Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace); diff --git a/lib/state_container.dart b/lib/state_container.dart index bf33b5a7..58b3b4ac 100644 --- a/lib/state_container.dart +++ b/lib/state_container.dart @@ -48,7 +48,7 @@ class StateContainer with ChangeNotifier { repoPath = p.join(gitBaseDirectory, settings.localGitRepoFolderName); } - _gitRepo = GitNoteRepository(gitDirPath: repoPath); + _gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings); appState.notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath); // Just a fail safe @@ -361,11 +361,13 @@ class StateContainer with ChangeNotifier { fromGitBasePath: settings.localGitRepoFolderName, toGitBaseFolder: settings.remoteGitRepoFolderName, gitBasePath: gitBaseDirectory, + gitAuthor: settings.gitAuthor, + gitAuthorEmail: settings.gitAuthorEmail, ); } var repoPath = p.join(gitBaseDirectory, settings.remoteGitRepoFolderName); - _gitRepo = GitNoteRepository(gitDirPath: repoPath); + _gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings); appState.notesFolder.reset(_gitRepo.gitDirPath); await _persistConfig();