mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-25 16:19:58 +08:00
Split Settings into StorageConfig
This commit is contained in:
27
lib/app.dart
27
lib/app.dart
@ -8,7 +8,6 @@ import 'package:device_info_plus/device_info_plus.dart';
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
||||||
import 'package:flutter_runtime_env/flutter_runtime_env.dart';
|
import 'package:flutter_runtime_env/flutter_runtime_env.dart';
|
||||||
import 'package:gitjournal/settings/git_config.dart';
|
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -24,8 +23,10 @@ import 'package:gitjournal/iap/iap.dart';
|
|||||||
import 'package:gitjournal/repository.dart';
|
import 'package:gitjournal/repository.dart';
|
||||||
import 'package:gitjournal/repository_manager.dart';
|
import 'package:gitjournal/repository_manager.dart';
|
||||||
import 'package:gitjournal/settings/app_settings.dart';
|
import 'package:gitjournal/settings/app_settings.dart';
|
||||||
|
import 'package:gitjournal/settings/git_config.dart';
|
||||||
import 'package:gitjournal/settings/markdown_renderer_config.dart';
|
import 'package:gitjournal/settings/markdown_renderer_config.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/themes.dart';
|
import 'package:gitjournal/themes.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
@ -296,7 +297,12 @@ class _JournalAppState extends State<JournalApp> {
|
|||||||
var stateContainer = Provider.of<GitJournalRepo>(context);
|
var stateContainer = Provider.of<GitJournalRepo>(context);
|
||||||
var settings = Provider.of<Settings>(context);
|
var settings = Provider.of<Settings>(context);
|
||||||
var appSettings = Provider.of<AppSettings>(context);
|
var appSettings = Provider.of<AppSettings>(context);
|
||||||
var router = AppRouter(settings: settings, appSettings: appSettings);
|
var storageConfig = Provider.of<StorageConfig>(context);
|
||||||
|
var router = AppRouter(
|
||||||
|
settings: settings,
|
||||||
|
appSettings: appSettings,
|
||||||
|
storageConfig: storageConfig,
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const FlexSchemeData customFlexScheme = FlexSchemeData(
|
const FlexSchemeData customFlexScheme = FlexSchemeData(
|
||||||
@ -375,13 +381,16 @@ class GitJournalChangeNotifiers extends StatelessWidget {
|
|||||||
child: Consumer<GitJournalRepo>(
|
child: Consumer<GitJournalRepo>(
|
||||||
builder: (_, repo, __) => ChangeNotifierProvider<GitConfig>.value(
|
builder: (_, repo, __) => ChangeNotifierProvider<GitConfig>.value(
|
||||||
value: repo.gitConfig,
|
value: repo.gitConfig,
|
||||||
child: ChangeNotifierProvider<Settings>.value(
|
child: ChangeNotifierProvider<StorageConfig>.value(
|
||||||
value: repo.settings,
|
value: repo.storageConfig,
|
||||||
child: Consumer<GitJournalRepo>(
|
child: ChangeNotifierProvider<Settings>.value(
|
||||||
builder: (_, repo, __) =>
|
value: repo.settings,
|
||||||
ChangeNotifierProvider<NotesFolderFS>.value(
|
child: Consumer<GitJournalRepo>(
|
||||||
value: repo.notesFolder,
|
builder: (_, repo, __) =>
|
||||||
child: child,
|
ChangeNotifierProvider<NotesFolderFS>.value(
|
||||||
|
value: repo.notesFolder,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -16,6 +16,7 @@ import 'package:gitjournal/screens/tag_listing.dart';
|
|||||||
import 'package:gitjournal/settings/app_settings.dart';
|
import 'package:gitjournal/settings/app_settings.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
import 'package:gitjournal/settings/settings_screen.dart';
|
import 'package:gitjournal/settings/settings_screen.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/setup/screens.dart';
|
import 'package:gitjournal/setup/screens.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
import 'package:gitjournal/utils/utils.dart';
|
import 'package:gitjournal/utils/utils.dart';
|
||||||
@ -51,8 +52,13 @@ class AppRoute {
|
|||||||
class AppRouter {
|
class AppRouter {
|
||||||
final AppSettings appSettings;
|
final AppSettings appSettings;
|
||||||
final Settings settings;
|
final Settings settings;
|
||||||
|
final StorageConfig storageConfig;
|
||||||
|
|
||||||
AppRouter({required this.appSettings, required this.settings});
|
AppRouter({
|
||||||
|
required this.appSettings,
|
||||||
|
required this.settings,
|
||||||
|
required this.storageConfig,
|
||||||
|
});
|
||||||
|
|
||||||
String initialRoute() {
|
String initialRoute() {
|
||||||
var route = '/';
|
var route = '/';
|
||||||
@ -81,7 +87,7 @@ class AppRouter {
|
|||||||
pageBuilder: (_, __, ___) => screenForRoute(
|
pageBuilder: (_, __, ___) => screenForRoute(
|
||||||
route,
|
route,
|
||||||
repository,
|
repository,
|
||||||
settings,
|
storageConfig,
|
||||||
sharedText,
|
sharedText,
|
||||||
sharedImages,
|
sharedImages,
|
||||||
callbackIfUsedShared,
|
callbackIfUsedShared,
|
||||||
@ -97,7 +103,7 @@ class AppRouter {
|
|||||||
builder: (context) => screenForRoute(
|
builder: (context) => screenForRoute(
|
||||||
route,
|
route,
|
||||||
repository,
|
repository,
|
||||||
settings,
|
storageConfig,
|
||||||
sharedText,
|
sharedText,
|
||||||
sharedImages,
|
sharedImages,
|
||||||
callbackIfUsedShared,
|
callbackIfUsedShared,
|
||||||
@ -108,7 +114,7 @@ class AppRouter {
|
|||||||
Widget? screenForRoute(
|
Widget? screenForRoute(
|
||||||
String route,
|
String route,
|
||||||
GitJournalRepo repository,
|
GitJournalRepo repository,
|
||||||
Settings settings,
|
StorageConfig storageConfig,
|
||||||
String sharedText,
|
String sharedText,
|
||||||
List<String> sharedImages,
|
List<String> sharedImages,
|
||||||
Function callbackIfUsedShared,
|
Function callbackIfUsedShared,
|
||||||
@ -132,7 +138,7 @@ class AppRouter {
|
|||||||
return SignUpScreen();
|
return SignUpScreen();
|
||||||
case AppRoute.SetupRemoteGit:
|
case AppRoute.SetupRemoteGit:
|
||||||
return GitHostSetupScreen(
|
return GitHostSetupScreen(
|
||||||
repoFolderName: settings.folderName,
|
repoFolderName: storageConfig.folderName,
|
||||||
remoteName: "origin",
|
remoteName: "origin",
|
||||||
onCompletedFunction: repository.completeGitHostSetup,
|
onCompletedFunction: repository.completeGitHostSetup,
|
||||||
);
|
);
|
||||||
|
@ -38,13 +38,17 @@ void main() async {
|
|||||||
await repoManager.buildActiveRepository();
|
await repoManager.buildActiveRepository();
|
||||||
var repo = repoManager.currentRepo;
|
var repo = repoManager.currentRepo;
|
||||||
var settings = repo.settings;
|
var settings = repo.settings;
|
||||||
var appRouter = AppRouter(settings: settings, appSettings: appSettings);
|
var storageConfig = repo.storageConfig;
|
||||||
|
var appRouter = AppRouter(
|
||||||
|
settings: settings,
|
||||||
|
appSettings: appSettings,
|
||||||
|
storageConfig: storageConfig);
|
||||||
|
|
||||||
for (var routeName in AppRoute.all) {
|
for (var routeName in AppRoute.all) {
|
||||||
dashbook.storiesOf(routeName).decorator(CenterDecorator()).add('all',
|
dashbook.storiesOf(routeName).decorator(CenterDecorator()).add('all',
|
||||||
(context) {
|
(context) {
|
||||||
return appRouter.screenForRoute(
|
return appRouter.screenForRoute(
|
||||||
routeName, repo, settings, "", [], () {})!;
|
routeName, repo, storageConfig, "", [], () {})!;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import 'package:gitjournal/error_reporting.dart';
|
|||||||
import 'package:gitjournal/settings/git_config.dart';
|
import 'package:gitjournal/settings/git_config.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
import 'package:gitjournal/settings/settings_migrations.dart';
|
import 'package:gitjournal/settings/settings_migrations.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
enum SyncStatus {
|
enum SyncStatus {
|
||||||
@ -34,8 +35,9 @@ enum SyncStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class GitJournalRepo with ChangeNotifier {
|
class GitJournalRepo with ChangeNotifier {
|
||||||
final Settings settings;
|
final StorageConfig storageConfig;
|
||||||
final GitConfig gitConfig;
|
final GitConfig gitConfig;
|
||||||
|
final Settings settings;
|
||||||
|
|
||||||
final _opLock = Lock();
|
final _opLock = Lock();
|
||||||
final _loadLock = Lock();
|
final _loadLock = Lock();
|
||||||
@ -71,26 +73,31 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
}) async {
|
}) async {
|
||||||
await migrateSettings(id, pref, gitBaseDir);
|
await migrateSettings(id, pref, gitBaseDir);
|
||||||
|
|
||||||
|
var storageConfig = StorageConfig(id);
|
||||||
|
storageConfig.load(pref);
|
||||||
|
|
||||||
var settings = Settings(id);
|
var settings = Settings(id);
|
||||||
settings.load(pref);
|
settings.load(pref);
|
||||||
|
|
||||||
logEvent(Event.Settings, parameters: settings.toLoggableMap());
|
|
||||||
|
|
||||||
Log.i("Setting ${settings.toLoggableMap()}");
|
|
||||||
|
|
||||||
var gitConfig = GitConfig(id);
|
var gitConfig = GitConfig(id);
|
||||||
gitConfig.load(pref);
|
gitConfig.load(pref);
|
||||||
|
|
||||||
var repoPath = await settings.buildRepoPath(gitBaseDir);
|
// logEvent(Event.Settings, parameters: settings.toLoggableMap());
|
||||||
|
|
||||||
|
Log.i("StorageConfig ${storageConfig.toLoggableMap()}");
|
||||||
|
Log.i("GitConfig ${gitConfig.toLoggableMap()}");
|
||||||
|
Log.i("Settings ${settings.toLoggableMap()}");
|
||||||
|
|
||||||
|
var repoPath = await storageConfig.buildRepoPath(gitBaseDir);
|
||||||
Log.i("Loading Repo at path $repoPath");
|
Log.i("Loading Repo at path $repoPath");
|
||||||
|
|
||||||
var repoDir = Directory(repoPath);
|
var repoDir = Directory(repoPath);
|
||||||
|
|
||||||
if (!repoDir.existsSync()) {
|
if (!repoDir.existsSync()) {
|
||||||
Log.i("Calling GitInit for ${settings.folderName} at: $repoPath");
|
Log.i("Calling GitInit for ${storageConfig.folderName} at: $repoPath");
|
||||||
await GitRepository.init(repoPath);
|
await GitRepository.init(repoPath);
|
||||||
|
|
||||||
settings.save();
|
storageConfig.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
var valid = await GitRepository.isValidRepo(repoPath);
|
var valid = await GitRepository.isValidRepo(repoPath);
|
||||||
@ -111,6 +118,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
gitBaseDirectory: gitBaseDir,
|
gitBaseDirectory: gitBaseDir,
|
||||||
cacheDir: cacheDir,
|
cacheDir: cacheDir,
|
||||||
remoteGitRepoConfigured: remoteConfigured,
|
remoteGitRepoConfigured: remoteConfigured,
|
||||||
|
storageConfig: storageConfig,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
gitConfig: gitConfig,
|
gitConfig: gitConfig,
|
||||||
id: id,
|
id: id,
|
||||||
@ -123,6 +131,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
required this.repoPath,
|
required this.repoPath,
|
||||||
required this.gitBaseDirectory,
|
required this.gitBaseDirectory,
|
||||||
required this.cacheDir,
|
required this.cacheDir,
|
||||||
|
required this.storageConfig,
|
||||||
required this.settings,
|
required this.settings,
|
||||||
required this.gitConfig,
|
required this.gitConfig,
|
||||||
required this.remoteGitRepoConfigured,
|
required this.remoteGitRepoConfigured,
|
||||||
@ -423,8 +432,8 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
remoteGitRepoConfigured = true;
|
remoteGitRepoConfigured = true;
|
||||||
notesFolder.reset(repoPath);
|
notesFolder.reset(repoPath);
|
||||||
|
|
||||||
settings.folderName = repoFolderName;
|
storageConfig.folderName = repoFolderName;
|
||||||
settings.save();
|
storageConfig.save();
|
||||||
|
|
||||||
await _persistConfig();
|
await _persistConfig();
|
||||||
_loadNotes();
|
_loadNotes();
|
||||||
@ -435,10 +444,12 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
|
|
||||||
Future _persistConfig() async {
|
Future _persistConfig() async {
|
||||||
await settings.save();
|
await settings.save();
|
||||||
|
await storageConfig.save();
|
||||||
|
await gitConfig.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> moveRepoToPath() async {
|
Future<void> moveRepoToPath() async {
|
||||||
var newRepoPath = await settings.buildRepoPath(gitBaseDirectory);
|
var newRepoPath = await storageConfig.buildRepoPath(gitBaseDirectory);
|
||||||
|
|
||||||
if (newRepoPath != repoPath) {
|
if (newRepoPath != repoPath) {
|
||||||
Log.i("Old Path: $repoPath");
|
Log.i("Old Path: $repoPath");
|
||||||
|
@ -5,6 +5,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
|
|
||||||
import 'package:gitjournal/repository.dart';
|
import 'package:gitjournal/repository.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
class RepositoryManager with ChangeNotifier {
|
class RepositoryManager with ChangeNotifier {
|
||||||
|
@ -15,13 +15,9 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'dart:io' show Platform;
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:icloud_documents_path/icloud_documents_path.dart';
|
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
@ -31,7 +27,6 @@ import 'package:gitjournal/folder_views/common_types.dart';
|
|||||||
import 'settings_sharedpref.dart';
|
import 'settings_sharedpref.dart';
|
||||||
|
|
||||||
const DEFAULT_ID = "0";
|
const DEFAULT_ID = "0";
|
||||||
const FOLDER_NAME_KEY = "remoteGitRepoPath";
|
|
||||||
const SETTINGS_VERSION = 3;
|
const SETTINGS_VERSION = 3;
|
||||||
|
|
||||||
class Settings extends ChangeNotifier with SettingsSharedPref {
|
class Settings extends ChangeNotifier with SettingsSharedPref {
|
||||||
@ -40,8 +35,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
@override
|
@override
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
String folderName = "journal";
|
|
||||||
|
|
||||||
NoteFileNameFormat noteFileNameFormat = NoteFileNameFormat.Default;
|
NoteFileNameFormat noteFileNameFormat = NoteFileNameFormat.Default;
|
||||||
NoteFileNameFormat journalNoteFileNameFormat = NoteFileNameFormat.Default;
|
NoteFileNameFormat journalNoteFileNameFormat = NoteFileNameFormat.Default;
|
||||||
|
|
||||||
@ -86,9 +79,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
bool confirmDelete = true;
|
bool confirmDelete = true;
|
||||||
bool hardWrap = false;
|
bool hardWrap = false;
|
||||||
|
|
||||||
bool storeInternally = true;
|
|
||||||
String storageLocation = "";
|
|
||||||
|
|
||||||
void load(SharedPreferences pref) {
|
void load(SharedPreferences pref) {
|
||||||
noteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
noteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
||||||
getString(pref, "noteFileNameFormat"));
|
getString(pref, "noteFileNameFormat"));
|
||||||
@ -152,12 +142,8 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
getStringSet(pref, "inlineTagPrefixes") ?? inlineTagPrefixes;
|
getStringSet(pref, "inlineTagPrefixes") ?? inlineTagPrefixes;
|
||||||
|
|
||||||
// From AppState
|
// From AppState
|
||||||
folderName = getString(pref, FOLDER_NAME_KEY) ?? folderName;
|
|
||||||
|
|
||||||
bottomMenuBar = getBool(pref, "bottomMenuBar") ?? bottomMenuBar;
|
bottomMenuBar = getBool(pref, "bottomMenuBar") ?? bottomMenuBar;
|
||||||
confirmDelete = getBool(pref, "confirmDelete") ?? confirmDelete;
|
confirmDelete = getBool(pref, "confirmDelete") ?? confirmDelete;
|
||||||
storeInternally = getBool(pref, "storeInternally") ?? storeInternally;
|
|
||||||
storageLocation = getString(pref, "storageLocation") ?? "";
|
|
||||||
|
|
||||||
hardWrap = getBool(pref, "hardWrap") ?? hardWrap;
|
hardWrap = getBool(pref, "hardWrap") ?? hardWrap;
|
||||||
}
|
}
|
||||||
@ -240,15 +226,9 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
|
pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
|
||||||
await setBool(
|
await setBool(
|
||||||
pref, "confirmDelete", confirmDelete, defaultSet.confirmDelete);
|
pref, "confirmDelete", confirmDelete, defaultSet.confirmDelete);
|
||||||
await setBool(
|
|
||||||
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
|
|
||||||
await setString(
|
|
||||||
pref, "storageLocation", storageLocation, defaultSet.storageLocation);
|
|
||||||
|
|
||||||
await setInt(pref, "settingsVersion", version, defaultSet.version);
|
await setInt(pref, "settingsVersion", version, defaultSet.version);
|
||||||
|
|
||||||
await setString(pref, FOLDER_NAME_KEY, folderName, defaultSet.folderName);
|
|
||||||
|
|
||||||
await setBool(pref, "hardWrap", hardWrap, defaultSet.hardWrap);
|
await setBool(pref, "hardWrap", hardWrap, defaultSet.hardWrap);
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -286,36 +266,10 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
'swipeToDelete': swipeToDelete.toString(),
|
'swipeToDelete': swipeToDelete.toString(),
|
||||||
'inlineTagPrefixes': inlineTagPrefixes.join(' '),
|
'inlineTagPrefixes': inlineTagPrefixes.join(' '),
|
||||||
'emojiParser': emojiParser.toString(),
|
'emojiParser': emojiParser.toString(),
|
||||||
'folderName': folderName.toString(),
|
|
||||||
'bottomMenuBar': bottomMenuBar.toString(),
|
'bottomMenuBar': bottomMenuBar.toString(),
|
||||||
'confirmDelete': confirmDelete.toString(),
|
'confirmDelete': confirmDelete.toString(),
|
||||||
'storeInternally': storeInternally.toString(),
|
|
||||||
'storageLocation': storageLocation,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> buildRepoPath(String internalDir) async {
|
|
||||||
if (storeInternally) {
|
|
||||||
return p.join(internalDir, folderName);
|
|
||||||
}
|
|
||||||
if (Platform.isIOS) {
|
|
||||||
//
|
|
||||||
// iOS is strange as fuck and it seems if you don't call this function
|
|
||||||
// asking for the path, you won't be able to access the path
|
|
||||||
// So even though we have it stored in the settings, this method
|
|
||||||
// must be called
|
|
||||||
//
|
|
||||||
var basePath = await ICloudDocumentsPath.documentsPath;
|
|
||||||
if (basePath == null) {
|
|
||||||
// Go back to the normal path
|
|
||||||
return p.join(storageLocation, folderName);
|
|
||||||
}
|
|
||||||
assert(basePath == storageLocation);
|
|
||||||
return p.join(basePath, folderName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.join(storageLocation, folderName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoteFileNameFormat {
|
class NoteFileNameFormat {
|
||||||
|
@ -12,6 +12,7 @@ import 'package:gitjournal/repository.dart';
|
|||||||
import 'package:gitjournal/settings/git_config.dart';
|
import 'package:gitjournal/settings/git_config.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
import 'package:gitjournal/settings/settings_widgets.dart';
|
import 'package:gitjournal/settings/settings_widgets.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/setup/screens.dart';
|
import 'package:gitjournal/setup/screens.dart';
|
||||||
import 'package:gitjournal/setup/sshkey.dart';
|
import 'package:gitjournal/setup/sshkey.dart';
|
||||||
import 'package:gitjournal/ssh/keygen.dart';
|
import 'package:gitjournal/ssh/keygen.dart';
|
||||||
@ -227,10 +228,10 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
|||||||
}
|
}
|
||||||
repoFolderName = repoFolderName + num.toString();
|
repoFolderName = repoFolderName + num.toString();
|
||||||
|
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var storageConfig = Provider.of<StorageConfig>(context, listen: false);
|
||||||
settings.folderName = repoFolderName;
|
storageConfig.folderName = repoFolderName;
|
||||||
settings.storeInternally = true;
|
storageConfig.storeInternally = true;
|
||||||
await settings.save();
|
await storageConfig.save();
|
||||||
|
|
||||||
var route = MaterialPageRoute(
|
var route = MaterialPageRoute(
|
||||||
builder: (context) => GitHostSetupScreen(
|
builder: (context) => GitHostSetupScreen(
|
||||||
|
@ -50,6 +50,7 @@ import 'package:gitjournal/settings/settings_misc.dart';
|
|||||||
import 'package:gitjournal/settings/settings_note_metadata.dart';
|
import 'package:gitjournal/settings/settings_note_metadata.dart';
|
||||||
import 'package:gitjournal/settings/settings_tags.dart';
|
import 'package:gitjournal/settings/settings_tags.dart';
|
||||||
import 'package:gitjournal/settings/settings_widgets.dart';
|
import 'package:gitjournal/settings/settings_widgets.dart';
|
||||||
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
import 'package:gitjournal/utils/utils.dart';
|
import 'package:gitjournal/utils/utils.dart';
|
||||||
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
|
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
|
||||||
@ -89,6 +90,7 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var settings = Provider.of<Settings>(context);
|
var settings = Provider.of<Settings>(context);
|
||||||
var gitConfig = Provider.of<GitConfig>(context);
|
var gitConfig = Provider.of<GitConfig>(context);
|
||||||
|
var storageConfig = Provider.of<StorageConfig>(context);
|
||||||
var appSettings = Provider.of<AppSettings>(context);
|
var appSettings = Provider.of<AppSettings>(context);
|
||||||
final repo = Provider.of<GitJournalRepo>(context);
|
final repo = Provider.of<GitJournalRepo>(context);
|
||||||
var repoManager = Provider.of<RepositoryManager>(context);
|
var repoManager = Provider.of<RepositoryManager>(context);
|
||||||
@ -343,13 +345,13 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
if (Platform.isAndroid)
|
if (Platform.isAndroid)
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(tr('settings.storage.external')),
|
title: Text(tr('settings.storage.external')),
|
||||||
value: !settings.storeInternally,
|
value: !storageConfig.storeInternally,
|
||||||
onChanged: (bool newVal) async {
|
onChanged: (bool newVal) async {
|
||||||
Future<void> moveBackToInternal(bool showError) async {
|
Future<void> moveBackToInternal(bool showError) async {
|
||||||
settings.storeInternally = true;
|
storageConfig.storeInternally = true;
|
||||||
settings.storageLocation = "";
|
storageConfig.storageLocation = "";
|
||||||
|
|
||||||
settings.save();
|
storageConfig.save();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
await repo.moveRepoToPath();
|
await repo.moveRepoToPath();
|
||||||
|
|
||||||
@ -372,10 +374,9 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
|
|
||||||
Log.i("Moving repo to $path");
|
Log.i("Moving repo to $path");
|
||||||
|
|
||||||
settings.storeInternally = false;
|
storageConfig.storeInternally = false;
|
||||||
settings.storageLocation = p.join(path, "GitJournal");
|
storageConfig.storageLocation = p.join(path, "GitJournal");
|
||||||
|
storageConfig.save();
|
||||||
settings.save();
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -393,22 +394,23 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
if (Platform.isAndroid)
|
if (Platform.isAndroid)
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(tr('settings.storage.repoLocation')),
|
title: Text(tr('settings.storage.repoLocation')),
|
||||||
subtitle: Text(p.join(settings.storageLocation, settings.folderName)),
|
subtitle: Text(
|
||||||
enabled: !settings.storeInternally,
|
p.join(storageConfig.storageLocation, storageConfig.folderName)),
|
||||||
|
enabled: !storageConfig.storeInternally,
|
||||||
),
|
),
|
||||||
if (Platform.isIOS)
|
if (Platform.isIOS)
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(tr('settings.storage.icloud')),
|
title: Text(tr('settings.storage.icloud')),
|
||||||
value: !settings.storeInternally,
|
value: !storageConfig.storeInternally,
|
||||||
onChanged: (bool newVal) async {
|
onChanged: (bool newVal) async {
|
||||||
if (newVal == false) {
|
if (newVal == false) {
|
||||||
settings.storeInternally = true;
|
storageConfig.storeInternally = true;
|
||||||
settings.storageLocation = "";
|
storageConfig.storageLocation = "";
|
||||||
} else {
|
} else {
|
||||||
settings.storageLocation =
|
storageConfig.storageLocation =
|
||||||
(await ICloudDocumentsPath.documentsPath)!;
|
(await ICloudDocumentsPath.documentsPath)!;
|
||||||
if (settings.storageLocation.isNotEmpty) {
|
if (storageConfig.storageLocation.isNotEmpty) {
|
||||||
settings.storeInternally = false;
|
storageConfig.storeInternally = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.save();
|
settings.save();
|
||||||
|
70
lib/settings/storage_config.dart
Normal file
70
lib/settings/storage_config.dart
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import 'package:icloud_documents_path/icloud_documents_path.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||||
|
|
||||||
|
const FOLDER_NAME_KEY = "remoteGitRepoPath";
|
||||||
|
|
||||||
|
class StorageConfig extends ChangeNotifier with SettingsSharedPref {
|
||||||
|
StorageConfig(this.id);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
var folderName = "journal";
|
||||||
|
var storeInternally = true;
|
||||||
|
var storageLocation = "";
|
||||||
|
|
||||||
|
void load(SharedPreferences pref) {
|
||||||
|
folderName = getString(pref, FOLDER_NAME_KEY) ?? folderName;
|
||||||
|
storeInternally = getBool(pref, "storeInternally") ?? storeInternally;
|
||||||
|
storageLocation = getString(pref, "storageLocation") ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> save() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
var defaultSet = StorageConfig(id);
|
||||||
|
|
||||||
|
await setString(pref, FOLDER_NAME_KEY, folderName, defaultSet.folderName);
|
||||||
|
await setBool(
|
||||||
|
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
|
||||||
|
await setString(
|
||||||
|
pref, "storageLocation", storageLocation, defaultSet.storageLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> toLoggableMap() {
|
||||||
|
return <String, String>{
|
||||||
|
'folderName': folderName.toString(),
|
||||||
|
'storeInternally': storeInternally.toString(),
|
||||||
|
'storageLocation': storageLocation,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> buildRepoPath(String internalDir) async {
|
||||||
|
if (storeInternally) {
|
||||||
|
return p.join(internalDir, folderName);
|
||||||
|
}
|
||||||
|
if (Platform.isIOS) {
|
||||||
|
//
|
||||||
|
// iOS is strange as fuck and it seems if you don't call this function
|
||||||
|
// asking for the path, you won't be able to access the path
|
||||||
|
// So even though we have it stored in the settings, this method
|
||||||
|
// must be called
|
||||||
|
//
|
||||||
|
var basePath = await ICloudDocumentsPath.documentsPath;
|
||||||
|
if (basePath == null) {
|
||||||
|
// Go back to the normal path
|
||||||
|
return p.join(storageLocation, folderName);
|
||||||
|
}
|
||||||
|
assert(basePath == storageLocation);
|
||||||
|
return p.join(basePath, folderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.join(storageLocation, folderName);
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ import 'package:gitjournal/apis/githost_factory.dart';
|
|||||||
import 'package:gitjournal/error_reporting.dart';
|
import 'package:gitjournal/error_reporting.dart';
|
||||||
import 'package:gitjournal/repository.dart';
|
import 'package:gitjournal/repository.dart';
|
||||||
import 'package:gitjournal/settings/git_config.dart';
|
import 'package:gitjournal/settings/git_config.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/storage_config.dart';
|
||||||
import 'package:gitjournal/setup/autoconfigure.dart';
|
import 'package:gitjournal/setup/autoconfigure.dart';
|
||||||
import 'package:gitjournal/setup/button.dart';
|
import 'package:gitjournal/setup/button.dart';
|
||||||
import 'package:gitjournal/setup/clone.dart';
|
import 'package:gitjournal/setup/clone.dart';
|
||||||
@ -594,7 +594,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
parameters: _buildOnboardingAnalytics(),
|
parameters: _buildOnboardingAnalytics(),
|
||||||
);
|
);
|
||||||
|
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var storageConfig = Provider.of<StorageConfig>(context, listen: false);
|
||||||
var folderName = folderNameFromCloneUrl(_gitCloneUrl);
|
var folderName = folderNameFromCloneUrl(_gitCloneUrl);
|
||||||
if (folderName != widget.repoFolderName) {
|
if (folderName != widget.repoFolderName) {
|
||||||
var newRepoPath = p.join(basePath, folderName);
|
var newRepoPath = p.join(basePath, folderName);
|
||||||
@ -608,7 +608,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
var repoPath = p.join(basePath, widget.repoFolderName);
|
var repoPath = p.join(basePath, widget.repoFolderName);
|
||||||
Log.i("Renaming $repoPath --> $newRepoPath");
|
Log.i("Renaming $repoPath --> $newRepoPath");
|
||||||
await Directory(repoPath).rename(newRepoPath);
|
await Directory(repoPath).rename(newRepoPath);
|
||||||
settings.folderName = p.basename(newRepoPath);
|
storageConfig.folderName = p.basename(newRepoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("calling onComplete $folderName ${widget.remoteName}");
|
Log.i("calling onComplete $folderName ${widget.remoteName}");
|
||||||
|
@ -169,7 +169,8 @@ class __CurrentRepoState extends State<_CurrentRepo>
|
|||||||
}
|
}
|
||||||
|
|
||||||
var repo = context.watch<GitJournalRepo>();
|
var repo = context.watch<GitJournalRepo>();
|
||||||
var repoPath = await repo.settings.buildRepoPath(repo.gitBaseDirectory);
|
var repoPath =
|
||||||
|
await repo.storageConfig.buildRepoPath(repo.gitBaseDirectory);
|
||||||
_repoFolderName = p.basename(repoPath);
|
_repoFolderName = p.basename(repoPath);
|
||||||
|
|
||||||
var remoteConfigs = await repo.remoteConfigs();
|
var remoteConfigs = await repo.remoteConfigs();
|
||||||
|
Reference in New Issue
Block a user