From 5441700f2845da1e474c29fece3fe6366422f9d3 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 17 Oct 2020 12:33:19 +0200 Subject: [PATCH] Move building the repo's path logic to one place Instead of having it duplicated --- lib/app.dart | 2 +- lib/settings.dart | 6 ++++++ lib/state_container.dart | 10 ++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 0faafab8..9a21253e 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -69,7 +69,7 @@ class JournalApp extends StatefulWidget { await settings.migrate(pref, appState.gitBaseDirectory); - var gitRepoDir = p.join(appState.gitBaseDirectory, settings.folderName); + var gitRepoDir = settings.buildRepoPath(appState.gitBaseDirectory); var repoDirStat = File(gitRepoDir).statSync(); if (repoDirStat.type != FileSystemEntityType.directory) { diff --git a/lib/settings.dart b/lib/settings.dart index 71373c0b..44dc22ea 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -333,6 +333,12 @@ class Settings extends ChangeNotifier { } } } + + String buildRepoPath(String internalDir) { + return storeInternally + ? p.join(internalDir, folderName) + : p.join(storageLocation, folderName); + } } class NoteFileNameFormat { diff --git a/lib/state_container.dart b/lib/state_container.dart index 76667c4b..3fe027d5 100644 --- a/lib/state_container.dart +++ b/lib/state_container.dart @@ -43,10 +43,7 @@ class StateContainer with ChangeNotifier { @required this.gitBaseDirectory, @required this.cacheDirectory, }) { - var folderName = settings.folderName; - repoPath = settings.storeInternally - ? p.join(gitBaseDirectory, folderName) - : p.join(settings.storageLocation, folderName); + repoPath = settings.buildRepoPath(appState.gitBaseDirectory); _gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings); appState.notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath, settings); @@ -358,10 +355,7 @@ class StateContainer with ChangeNotifier { } Future moveRepoToPath() async { - var folderName = settings.folderName; - var newRepoPath = settings.storeInternally - ? p.join(gitBaseDirectory, folderName) - : p.join(settings.storageLocation, folderName); + var newRepoPath = settings.buildRepoPath(appState.gitBaseDirectory); if (newRepoPath != repoPath) { Log.i("Old Path: $repoPath");