Save Notes Cache in the cache directory

It shouldn't be saved in the Documents folder. Now that this folder is
exposed on ios, I should remove all non-user related files from here.
This commit is contained in:
Vishesh Handa
2020-10-16 01:10:18 +02:00
parent a1e7135236
commit 5c2e336343
3 changed files with 8 additions and 1 deletions

View File

@ -83,6 +83,7 @@ class JournalApp extends StatefulWidget {
settings.localGitRepoConfigured = true;
settings.save();
}
final cacheDir = await getApplicationSupportDirectory();
Widget app = ChangeNotifierProvider.value(
value: settings,
@ -92,6 +93,7 @@ class JournalApp extends StatefulWidget {
appState: appState,
settings: settings,
gitBaseDirectory: appState.gitBaseDirectory,
cacheDirectory: cacheDir.path,
);
},
child: ChangeNotifierProvider(

View File

@ -320,6 +320,9 @@ class Settings extends ChangeNotifier {
Future<void> migrate(SharedPreferences pref, String gitBaseDir) async {
if (version == 0) {
var cache = p.join(gitBaseDir, "cache.json");
await File(cache).delete(recursive: true);
if (localGitRepoConfigured && !remoteGitRepoConfigured) {
Log.i("Migrating from local and remote repos to a single one");
var oldName = p.join(gitBaseDir, "journal_local");

View File

@ -24,6 +24,7 @@ class StateContainer with ChangeNotifier {
final AppState appState;
final Settings settings;
final String gitBaseDirectory;
final String cacheDirectory;
final _opLock = Lock();
final _loadLock = Lock();
@ -38,6 +39,7 @@ class StateContainer with ChangeNotifier {
@required this.appState,
@required this.settings,
@required this.gitBaseDirectory,
@required this.cacheDirectory,
}) {
assert(settings.localGitRepoConfigured);
var repoPath = p.join(gitBaseDirectory, settings.internalRepoFolderName);
@ -51,7 +53,7 @@ class StateContainer with ChangeNotifier {
value: settings.remoteGitRepoConfigured.toString(),
);
var cachePath = p.join(gitBaseDirectory, "cache.json");
var cachePath = p.join(cacheDirectory, "cache.json");
_notesCache = NotesCache(
filePath: cachePath,
notesBasePath: _gitRepo.gitDirPath,