mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-25 08:12:19 +08:00
Add GitConfig
This makes the Settings class smaller.
This commit is contained in:
18
lib/app.dart
18
lib/app.dart
@ -8,6 +8,7 @@ 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';
|
||||||
@ -372,13 +373,16 @@ class GitJournalChangeNotifiers extends StatelessWidget {
|
|||||||
child: ChangeNotifierProvider.value(
|
child: ChangeNotifierProvider.value(
|
||||||
value: repoManager.currentRepo,
|
value: repoManager.currentRepo,
|
||||||
child: Consumer<GitJournalRepo>(
|
child: Consumer<GitJournalRepo>(
|
||||||
builder: (_, repo, __) => ChangeNotifierProvider<Settings>.value(
|
builder: (_, repo, __) => ChangeNotifierProvider<GitConfig>.value(
|
||||||
value: repo.settings,
|
value: repo.gitConfig,
|
||||||
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,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -11,7 +11,7 @@ import 'package:gitjournal/core/notes_folder.dart';
|
|||||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/error_reporting.dart';
|
import 'package:gitjournal/error_reporting.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/git_config.dart';
|
||||||
import 'package:gitjournal/utils/git_desktop.dart';
|
import 'package:gitjournal/utils/git_desktop.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
|
|
||||||
@ -20,11 +20,11 @@ bool useDartGit = false;
|
|||||||
class GitNoteRepository {
|
class GitNoteRepository {
|
||||||
final String gitDirPath;
|
final String gitDirPath;
|
||||||
final gb.GitRepo _gitRepo;
|
final gb.GitRepo _gitRepo;
|
||||||
final Settings settings;
|
final GitConfig config;
|
||||||
|
|
||||||
GitNoteRepository({
|
GitNoteRepository({
|
||||||
required this.gitDirPath,
|
required this.gitDirPath,
|
||||||
required this.settings,
|
required this.config,
|
||||||
}) : _gitRepo = gb.GitRepo(folderPath: gitDirPath) {
|
}) : _gitRepo = gb.GitRepo(folderPath: gitDirPath) {
|
||||||
// git-bindings aren't properly implemented in these platforms
|
// git-bindings aren't properly implemented in these platforms
|
||||||
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
|
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
|
||||||
@ -79,8 +79,8 @@ class GitNoteRepository {
|
|||||||
try {
|
try {
|
||||||
await _gitRepo.commit(
|
await _gitRepo.commit(
|
||||||
message: message,
|
message: message,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
);
|
);
|
||||||
} on Exception catch (ex, st) {
|
} on Exception catch (ex, st) {
|
||||||
return Result.fail(ex, st);
|
return Result.fail(ex, st);
|
||||||
@ -103,8 +103,8 @@ class GitNoteRepository {
|
|||||||
|
|
||||||
var res = await _commit(
|
var res = await _commit(
|
||||||
message: commitMessage,
|
message: commitMessage,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
);
|
);
|
||||||
if (res.isFailure) {
|
if (res.isFailure) {
|
||||||
return fail(r);
|
return fail(r);
|
||||||
@ -160,8 +160,8 @@ class GitNoteRepository {
|
|||||||
await _rm(spec).throwOnError();
|
await _rm(spec).throwOnError();
|
||||||
await _commit(
|
await _commit(
|
||||||
message: "Removed Note " + spec,
|
message: "Removed Note " + spec,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
).throwOnError();
|
).throwOnError();
|
||||||
|
|
||||||
return Result(null);
|
return Result(null);
|
||||||
@ -174,8 +174,8 @@ class GitNoteRepository {
|
|||||||
await _rm(spec).throwOnError();
|
await _rm(spec).throwOnError();
|
||||||
await _commit(
|
await _commit(
|
||||||
message: "Removed Folder " + spec,
|
message: "Removed Folder " + spec,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
).throwOnError();
|
).throwOnError();
|
||||||
|
|
||||||
return Result(null);
|
return Result(null);
|
||||||
@ -216,9 +216,9 @@ class GitNoteRepository {
|
|||||||
try {
|
try {
|
||||||
await _gitRepo.fetch(
|
await _gitRepo.fetch(
|
||||||
remote: remoteName,
|
remote: remoteName,
|
||||||
publicKey: settings.sshPublicKey,
|
publicKey: config.sshPublicKey,
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: config.sshPrivateKey,
|
||||||
password: settings.sshPassword,
|
password: config.sshPassword,
|
||||||
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
||||||
);
|
);
|
||||||
} on gb.GitException catch (ex, stackTrace) {
|
} on gb.GitException catch (ex, stackTrace) {
|
||||||
@ -229,8 +229,8 @@ class GitNoteRepository {
|
|||||||
}
|
}
|
||||||
} else if (Platform.isMacOS) {
|
} else if (Platform.isMacOS) {
|
||||||
await gitPushViaExecutable(
|
await gitPushViaExecutable(
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: config.sshPrivateKey,
|
||||||
privateKeyPassword: settings.sshPassword,
|
privateKeyPassword: config.sshPassword,
|
||||||
remoteName: remoteName,
|
remoteName: remoteName,
|
||||||
repoPath: gitDirPath,
|
repoPath: gitDirPath,
|
||||||
).throwOnError();
|
).throwOnError();
|
||||||
@ -263,8 +263,8 @@ class GitNoteRepository {
|
|||||||
|
|
||||||
if (useDartGit || AppSettings.instance.experimentalGitMerge) {
|
if (useDartGit || AppSettings.instance.experimentalGitMerge) {
|
||||||
var author = GitAuthor(
|
var author = GitAuthor(
|
||||||
email: settings.gitAuthorEmail,
|
email: config.gitAuthorEmail,
|
||||||
name: settings.gitAuthor,
|
name: config.gitAuthor,
|
||||||
);
|
);
|
||||||
return repo.mergeCurrentTrackingBranch(author: author);
|
return repo.mergeCurrentTrackingBranch(author: author);
|
||||||
}
|
}
|
||||||
@ -272,8 +272,8 @@ class GitNoteRepository {
|
|||||||
try {
|
try {
|
||||||
await _gitRepo.merge(
|
await _gitRepo.merge(
|
||||||
branch: branchConfig.remoteTrackingBranch(),
|
branch: branchConfig.remoteTrackingBranch(),
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
);
|
);
|
||||||
} on gb.GitException catch (ex, stackTrace) {
|
} on gb.GitException catch (ex, stackTrace) {
|
||||||
Log.e("Git Merge Failed", ex: ex, stacktrace: stackTrace);
|
Log.e("Git Merge Failed", ex: ex, stacktrace: stackTrace);
|
||||||
@ -300,9 +300,9 @@ class GitNoteRepository {
|
|||||||
try {
|
try {
|
||||||
await _gitRepo.push(
|
await _gitRepo.push(
|
||||||
remote: remoteName,
|
remote: remoteName,
|
||||||
publicKey: settings.sshPublicKey,
|
publicKey: config.sshPublicKey,
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: config.sshPrivateKey,
|
||||||
password: settings.sshPassword,
|
password: config.sshPassword,
|
||||||
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
||||||
);
|
);
|
||||||
} on gb.GitException catch (ex, stackTrace) {
|
} on gb.GitException catch (ex, stackTrace) {
|
||||||
@ -316,8 +316,8 @@ class GitNoteRepository {
|
|||||||
}
|
}
|
||||||
} else if (Platform.isMacOS) {
|
} else if (Platform.isMacOS) {
|
||||||
await gitPushViaExecutable(
|
await gitPushViaExecutable(
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: config.sshPrivateKey,
|
||||||
privateKeyPassword: settings.sshPassword,
|
privateKeyPassword: config.sshPassword,
|
||||||
remoteName: remoteName,
|
remoteName: remoteName,
|
||||||
repoPath: gitDirPath,
|
repoPath: gitDirPath,
|
||||||
).throwOnError();
|
).throwOnError();
|
||||||
|
@ -20,6 +20,7 @@ import 'package:gitjournal/core/note.dart';
|
|||||||
import 'package:gitjournal/core/notes_cache.dart';
|
import 'package:gitjournal/core/notes_cache.dart';
|
||||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/error_reporting.dart';
|
import 'package:gitjournal/error_reporting.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/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
@ -34,6 +35,7 @@ enum SyncStatus {
|
|||||||
|
|
||||||
class GitJournalRepo with ChangeNotifier {
|
class GitJournalRepo with ChangeNotifier {
|
||||||
final Settings settings;
|
final Settings settings;
|
||||||
|
final GitConfig gitConfig;
|
||||||
|
|
||||||
final _opLock = Lock();
|
final _opLock = Lock();
|
||||||
final _loadLock = Lock();
|
final _loadLock = Lock();
|
||||||
@ -76,6 +78,9 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
|
|
||||||
Log.i("Setting ${settings.toLoggableMap()}");
|
Log.i("Setting ${settings.toLoggableMap()}");
|
||||||
|
|
||||||
|
var gitConfig = GitConfig(id);
|
||||||
|
gitConfig.load(pref);
|
||||||
|
|
||||||
var repoPath = await settings.buildRepoPath(gitBaseDir);
|
var repoPath = await settings.buildRepoPath(gitBaseDir);
|
||||||
Log.i("Loading Repo at path $repoPath");
|
Log.i("Loading Repo at path $repoPath");
|
||||||
|
|
||||||
@ -107,6 +112,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
cacheDir: cacheDir,
|
cacheDir: cacheDir,
|
||||||
remoteGitRepoConfigured: remoteConfigured,
|
remoteGitRepoConfigured: remoteConfigured,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
|
gitConfig: gitConfig,
|
||||||
id: id,
|
id: id,
|
||||||
currentBranch: await repo.currentBranch().getOrThrow(),
|
currentBranch: await repo.currentBranch().getOrThrow(),
|
||||||
);
|
);
|
||||||
@ -118,10 +124,11 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
required this.gitBaseDirectory,
|
required this.gitBaseDirectory,
|
||||||
required this.cacheDir,
|
required this.cacheDir,
|
||||||
required this.settings,
|
required this.settings,
|
||||||
|
required this.gitConfig,
|
||||||
required this.remoteGitRepoConfigured,
|
required this.remoteGitRepoConfigured,
|
||||||
required String? currentBranch,
|
required String? currentBranch,
|
||||||
}) {
|
}) {
|
||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, config: gitConfig);
|
||||||
notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath, settings);
|
notesFolder = NotesFolderFS(null, _gitRepo.gitDirPath, settings);
|
||||||
_currentBranch = currentBranch;
|
_currentBranch = currentBranch;
|
||||||
|
|
||||||
@ -408,9 +415,9 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
repoPath = p.join(gitBaseDirectory, repoFolderName);
|
repoPath = p.join(gitBaseDirectory, repoFolderName);
|
||||||
Log.i("repoPath: $repoPath");
|
Log.i("repoPath: $repoPath");
|
||||||
|
|
||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, config: gitConfig);
|
||||||
|
|
||||||
await _addFileInRepo(repo: this, settings: settings);
|
await _addFileInRepo(repo: this, config: gitConfig);
|
||||||
|
|
||||||
_notesCache.clear();
|
_notesCache.clear();
|
||||||
remoteGitRepoConfigured = true;
|
remoteGitRepoConfigured = true;
|
||||||
@ -442,7 +449,7 @@ class GitJournalRepo with ChangeNotifier {
|
|||||||
await Directory(repoPath).delete(recursive: true);
|
await Directory(repoPath).delete(recursive: true);
|
||||||
|
|
||||||
repoPath = newRepoPath;
|
repoPath = newRepoPath;
|
||||||
_gitRepo = GitNoteRepository(gitDirPath: repoPath, settings: settings);
|
_gitRepo = GitNoteRepository(gitDirPath: repoPath, config: gitConfig);
|
||||||
|
|
||||||
_notesCache.clear();
|
_notesCache.clear();
|
||||||
notesFolder.reset(repoPath);
|
notesFolder.reset(repoPath);
|
||||||
@ -560,7 +567,7 @@ Future<void> _copyDirectory(String source, String destination) async {
|
|||||||
/// one commit. It makes doing a git pull and push easier
|
/// one commit. It makes doing a git pull and push easier
|
||||||
Future<void> _addFileInRepo({
|
Future<void> _addFileInRepo({
|
||||||
required GitJournalRepo repo,
|
required GitJournalRepo repo,
|
||||||
required Settings settings,
|
required GitConfig config,
|
||||||
}) async {
|
}) async {
|
||||||
var repoPath = repo.repoPath;
|
var repoPath = repo.repoPath;
|
||||||
var dirList = await Directory(repoPath).list().toList();
|
var dirList = await Directory(repoPath).list().toList();
|
||||||
@ -577,8 +584,8 @@ Future<void> _addFileInRepo({
|
|||||||
|
|
||||||
await repo.commit(
|
await repo.commit(
|
||||||
message: "Add gitignore file",
|
message: "Add gitignore file",
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: config.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: config.gitAuthor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
lib/settings/git_config.dart
Normal file
50
lib/settings/git_config.dart
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/settings/settings_sharedpref.dart';
|
||||||
|
|
||||||
|
class GitConfig extends ChangeNotifier with SettingsSharedPref {
|
||||||
|
GitConfig(this.id);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
var gitAuthor = "GitJournal";
|
||||||
|
var gitAuthorEmail = "app@gitjournal.io";
|
||||||
|
var sshPublicKey = "";
|
||||||
|
var sshPrivateKey = "";
|
||||||
|
var sshPassword = "";
|
||||||
|
|
||||||
|
void load(SharedPreferences pref) {
|
||||||
|
gitAuthor = getString(pref, "gitAuthor") ?? gitAuthor;
|
||||||
|
gitAuthorEmail = getString(pref, "gitAuthorEmail") ?? gitAuthorEmail;
|
||||||
|
sshPublicKey = getString(pref, "sshPublicKey") ?? sshPublicKey;
|
||||||
|
sshPrivateKey = getString(pref, "sshPrivateKey") ?? sshPrivateKey;
|
||||||
|
sshPassword = getString(pref, "sshPassword") ?? sshPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> save() async {
|
||||||
|
var pref = await SharedPreferences.getInstance();
|
||||||
|
var defaultSet = GitConfig(id);
|
||||||
|
|
||||||
|
await setString(pref, "gitAuthor", gitAuthor, defaultSet.gitAuthor);
|
||||||
|
await setString(
|
||||||
|
pref, "gitAuthorEmail", gitAuthorEmail, defaultSet.gitAuthorEmail);
|
||||||
|
await setString(
|
||||||
|
pref, "sshPublicKey", sshPublicKey, defaultSet.sshPublicKey);
|
||||||
|
await setString(
|
||||||
|
pref, "sshPrivateKey", sshPrivateKey, defaultSet.sshPrivateKey);
|
||||||
|
await setString(pref, "sshPassword", sshPassword, defaultSet.sshPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> toLoggableMap() {
|
||||||
|
return <String, String>{
|
||||||
|
"gitAuthor": gitAuthor.isNotEmpty.toString(),
|
||||||
|
"gitAuthorEmail": gitAuthorEmail.isNotEmpty.toString(),
|
||||||
|
'sshPublicKey': sshPublicKey.isNotEmpty.toString(),
|
||||||
|
'sshPrivateKey': sshPrivateKey.isNotEmpty.toString(),
|
||||||
|
'sshPassword': sshPassword.isNotEmpty.toString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -42,13 +42,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
|
|
||||||
String folderName = "journal";
|
String folderName = "journal";
|
||||||
|
|
||||||
// Git Settings
|
|
||||||
String gitAuthor = "GitJournal";
|
|
||||||
String gitAuthorEmail = "app@gitjournal.io";
|
|
||||||
String sshPublicKey = "";
|
|
||||||
String sshPrivateKey = "";
|
|
||||||
String sshPassword = "";
|
|
||||||
|
|
||||||
NoteFileNameFormat noteFileNameFormat = NoteFileNameFormat.Default;
|
NoteFileNameFormat noteFileNameFormat = NoteFileNameFormat.Default;
|
||||||
NoteFileNameFormat journalNoteFileNameFormat = NoteFileNameFormat.Default;
|
NoteFileNameFormat journalNoteFileNameFormat = NoteFileNameFormat.Default;
|
||||||
|
|
||||||
@ -97,12 +90,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
String storageLocation = "";
|
String storageLocation = "";
|
||||||
|
|
||||||
void load(SharedPreferences pref) {
|
void load(SharedPreferences pref) {
|
||||||
gitAuthor = getString(pref, "gitAuthor") ?? gitAuthor;
|
|
||||||
gitAuthorEmail = getString(pref, "gitAuthorEmail") ?? gitAuthorEmail;
|
|
||||||
sshPublicKey = getString(pref, "sshPublicKey") ?? sshPublicKey;
|
|
||||||
sshPrivateKey = getString(pref, "sshPrivateKey") ?? sshPrivateKey;
|
|
||||||
sshPassword = getString(pref, "sshPassword") ?? sshPassword;
|
|
||||||
|
|
||||||
noteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
noteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
||||||
getString(pref, "noteFileNameFormat"));
|
getString(pref, "noteFileNameFormat"));
|
||||||
journalNoteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
journalNoteFileNameFormat = NoteFileNameFormat.fromInternalString(
|
||||||
@ -179,15 +166,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
var pref = await SharedPreferences.getInstance();
|
var pref = await SharedPreferences.getInstance();
|
||||||
var defaultSet = Settings(id);
|
var defaultSet = Settings(id);
|
||||||
|
|
||||||
await setString(pref, "gitAuthor", gitAuthor, defaultSet.gitAuthor);
|
|
||||||
await setString(
|
|
||||||
pref, "gitAuthorEmail", gitAuthorEmail, defaultSet.gitAuthorEmail);
|
|
||||||
await setString(
|
|
||||||
pref, "sshPublicKey", sshPublicKey, defaultSet.sshPublicKey);
|
|
||||||
await setString(
|
|
||||||
pref, "sshPrivateKey", sshPrivateKey, defaultSet.sshPrivateKey);
|
|
||||||
await setString(pref, "sshPassword", sshPassword, defaultSet.sshPassword);
|
|
||||||
|
|
||||||
await setString(
|
await setString(
|
||||||
pref,
|
pref,
|
||||||
"noteFileNameFormat",
|
"noteFileNameFormat",
|
||||||
@ -278,10 +256,6 @@ class Settings extends ChangeNotifier with SettingsSharedPref {
|
|||||||
|
|
||||||
Map<String, String> toLoggableMap() {
|
Map<String, String> toLoggableMap() {
|
||||||
return <String, String>{
|
return <String, String>{
|
||||||
"gitAuthor": gitAuthor.isNotEmpty.toString(),
|
|
||||||
"gitAuthorEmail": gitAuthorEmail.isNotEmpty.toString(),
|
|
||||||
'sshPublicKey': sshPublicKey.isNotEmpty.toString(),
|
|
||||||
'sshPrivateKey': sshPrivateKey.isNotEmpty.toString(),
|
|
||||||
"noteFileNameFormat": noteFileNameFormat.toInternalString(),
|
"noteFileNameFormat": noteFileNameFormat.toInternalString(),
|
||||||
"journalNoteFileNameFormat": journalNoteFileNameFormat.toInternalString(),
|
"journalNoteFileNameFormat": journalNoteFileNameFormat.toInternalString(),
|
||||||
"yamlModifiedKey": yamlModifiedKey,
|
"yamlModifiedKey": yamlModifiedKey,
|
||||||
|
@ -9,6 +9,7 @@ import 'package:path/path.dart' as p;
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/repository.dart';
|
import 'package:gitjournal/repository.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/setup/screens.dart';
|
import 'package:gitjournal/setup/screens.dart';
|
||||||
@ -163,15 +164,15 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _updateKeys(String publicKey, String privateKey, String password) {
|
void _updateKeys(String publicKey, String privateKey, String password) {
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var config = Provider.of<GitConfig>(context, listen: false);
|
||||||
|
|
||||||
if (publicKey.isEmpty || privateKey.isEmpty) {
|
if (publicKey.isEmpty || privateKey.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settings.sshPublicKey = publicKey;
|
config.sshPublicKey = publicKey;
|
||||||
settings.sshPrivateKey = privateKey;
|
config.sshPrivateKey = privateKey;
|
||||||
settings.sshPassword = password;
|
config.sshPassword = password;
|
||||||
settings.save();
|
config.save();
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
@ -188,11 +189,11 @@ class _GitRemoteSettingsScreenState extends State<GitRemoteSettingsScreen> {
|
|||||||
DateTime.now().toIso8601String().substring(0, 10); // only the date
|
DateTime.now().toIso8601String().substring(0, 10); // only the date
|
||||||
|
|
||||||
generateSSHKeys(comment: comment).then((SshKey? sshKey) {
|
generateSSHKeys(comment: comment).then((SshKey? sshKey) {
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var config = Provider.of<GitConfig>(context, listen: false);
|
||||||
settings.sshPublicKey = sshKey!.publicKey;
|
config.sshPublicKey = sshKey!.publicKey;
|
||||||
settings.sshPrivateKey = sshKey.publicKey;
|
config.sshPrivateKey = sshKey.publicKey;
|
||||||
settings.sshPassword = sshKey.password;
|
config.sshPassword = sshKey.password;
|
||||||
settings.save();
|
config.save();
|
||||||
|
|
||||||
Log.d("PublicKey: " + sshKey.publicKey);
|
Log.d("PublicKey: " + sshKey.publicKey);
|
||||||
_copyKeyToClipboard(context);
|
_copyKeyToClipboard(context);
|
||||||
|
@ -38,6 +38,7 @@ import 'package:gitjournal/repository_manager.dart';
|
|||||||
import 'package:gitjournal/screens/debug_screen.dart';
|
import 'package:gitjournal/screens/debug_screen.dart';
|
||||||
import 'package:gitjournal/screens/feature_timeline_screen.dart';
|
import 'package:gitjournal/screens/feature_timeline_screen.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/settings.dart';
|
import 'package:gitjournal/settings/settings.dart';
|
||||||
import 'package:gitjournal/settings/settings_bottom_menu_bar.dart';
|
import 'package:gitjournal/settings/settings_bottom_menu_bar.dart';
|
||||||
import 'package:gitjournal/settings/settings_display_images.dart';
|
import 'package:gitjournal/settings/settings_display_images.dart';
|
||||||
@ -87,14 +88,15 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
@override
|
@override
|
||||||
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 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);
|
||||||
|
|
||||||
var saveGitAuthor = (String? gitAuthor) {
|
var saveGitAuthor = (String? gitAuthor) {
|
||||||
if (gitAuthor == null) return;
|
if (gitAuthor == null) return;
|
||||||
settings.gitAuthor = gitAuthor;
|
gitConfig.gitAuthor = gitAuthor;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
var gitAuthorForm = Form(
|
var gitAuthorForm = Form(
|
||||||
@ -116,7 +118,7 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
onFieldSubmitted: saveGitAuthor,
|
onFieldSubmitted: saveGitAuthor,
|
||||||
onSaved: saveGitAuthor,
|
onSaved: saveGitAuthor,
|
||||||
initialValue: settings.gitAuthor,
|
initialValue: gitConfig.gitAuthor,
|
||||||
),
|
),
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
if (!gitAuthorKey.currentState!.validate()) return;
|
if (!gitAuthorKey.currentState!.validate()) return;
|
||||||
@ -128,8 +130,8 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
var saveGitAuthorEmail = (String? gitAuthorEmail) {
|
var saveGitAuthorEmail = (String? gitAuthorEmail) {
|
||||||
if (gitAuthorEmail == null) return;
|
if (gitAuthorEmail == null) return;
|
||||||
|
|
||||||
settings.gitAuthorEmail = gitAuthorEmail;
|
gitConfig.gitAuthorEmail = gitAuthorEmail;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
};
|
};
|
||||||
var gitAuthorEmailForm = Form(
|
var gitAuthorEmailForm = Form(
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
@ -155,7 +157,7 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
textInputAction: TextInputAction.done,
|
textInputAction: TextInputAction.done,
|
||||||
onFieldSubmitted: saveGitAuthorEmail,
|
onFieldSubmitted: saveGitAuthorEmail,
|
||||||
onSaved: saveGitAuthorEmail,
|
onSaved: saveGitAuthorEmail,
|
||||||
initialValue: settings.gitAuthorEmail,
|
initialValue: gitConfig.gitAuthorEmail,
|
||||||
),
|
),
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
if (!gitAuthorEmailKey.currentState!.validate()) return;
|
if (!gitAuthorEmailKey.currentState!.validate()) return;
|
||||||
@ -270,7 +272,7 @@ class SettingsListState extends State<SettingsList> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
var route = MaterialPageRoute(
|
var route = MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
GitRemoteSettingsScreen(settings.sshPublicKey),
|
GitRemoteSettingsScreen(gitConfig.sshPublicKey),
|
||||||
settings: const RouteSettings(name: '/settings/gitRemote'),
|
settings: const RouteSettings(name: '/settings/gitRemote'),
|
||||||
);
|
);
|
||||||
Navigator.of(context).push(route);
|
Navigator.of(context).push(route);
|
||||||
|
@ -8,7 +8,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:gitjournal/analytics/analytics.dart';
|
import 'package:gitjournal/analytics/analytics.dart';
|
||||||
import 'package:gitjournal/apis/githost_factory.dart';
|
import 'package:gitjournal/apis/githost_factory.dart';
|
||||||
import 'package:gitjournal/error_reporting.dart';
|
import 'package:gitjournal/error_reporting.dart';
|
||||||
import 'package:gitjournal/settings/settings.dart';
|
import 'package:gitjournal/settings/git_config.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
import 'button.dart';
|
import 'button.dart';
|
||||||
import 'error.dart';
|
import 'error.dart';
|
||||||
@ -65,14 +65,14 @@ class GitHostSetupAutoConfigurePageState
|
|||||||
});
|
});
|
||||||
|
|
||||||
userInfo = await gitHost!.getUserInfo().getOrThrow();
|
userInfo = await gitHost!.getUserInfo().getOrThrow();
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
if (userInfo.name.isNotEmpty) {
|
if (userInfo.name.isNotEmpty) {
|
||||||
settings.gitAuthor = userInfo.name;
|
gitConfig.gitAuthor = userInfo.name;
|
||||||
}
|
}
|
||||||
if (userInfo.email.isNotEmpty) {
|
if (userInfo.email.isNotEmpty) {
|
||||||
settings.gitAuthorEmail = userInfo.email;
|
gitConfig.gitAuthorEmail = userInfo.email;
|
||||||
}
|
}
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
} on Exception catch (e, stacktrace) {
|
} on Exception catch (e, stacktrace) {
|
||||||
_handleGitHostException(e, stacktrace);
|
_handleGitHostException(e, stacktrace);
|
||||||
return;
|
return;
|
||||||
|
@ -16,6 +16,7 @@ import 'package:gitjournal/analytics/analytics.dart';
|
|||||||
import 'package:gitjournal/apis/githost_factory.dart';
|
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/settings.dart';
|
import 'package:gitjournal/settings/settings.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';
|
||||||
@ -225,11 +226,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
return GitHostUserProvidedKeysPage(
|
return GitHostUserProvidedKeysPage(
|
||||||
doneFunction:
|
doneFunction:
|
||||||
(String publicKey, String privateKey, String password) async {
|
(String publicKey, String privateKey, String password) async {
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
settings.sshPublicKey = publicKey;
|
gitConfig.sshPublicKey = publicKey;
|
||||||
settings.sshPrivateKey = privateKey;
|
gitConfig.sshPrivateKey = privateKey;
|
||||||
settings.sshPassword = password;
|
gitConfig.sshPassword = password;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
@ -323,11 +324,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
} else if (_keyGenerationChoice == KeyGenerationChoice.UserProvided) {
|
} else if (_keyGenerationChoice == KeyGenerationChoice.UserProvided) {
|
||||||
return GitHostUserProvidedKeysPage(
|
return GitHostUserProvidedKeysPage(
|
||||||
doneFunction: (publicKey, privateKey, password) async {
|
doneFunction: (publicKey, privateKey, password) async {
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
settings.sshPublicKey = publicKey;
|
gitConfig.sshPublicKey = publicKey;
|
||||||
settings.sshPrivateKey = privateKey;
|
gitConfig.sshPrivateKey = privateKey;
|
||||||
settings.sshPassword = password;
|
gitConfig.sshPassword = password;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
@ -478,11 +479,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
DateTime.now().toIso8601String().substring(0, 10); // only the date
|
DateTime.now().toIso8601String().substring(0, 10); // only the date
|
||||||
|
|
||||||
generateSSHKeys(comment: comment).then((SshKey? sshKey) {
|
generateSSHKeys(comment: comment).then((SshKey? sshKey) {
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
settings.sshPublicKey = sshKey!.publicKey;
|
gitConfig.sshPublicKey = sshKey!.publicKey;
|
||||||
settings.sshPrivateKey = sshKey.privateKey;
|
gitConfig.sshPrivateKey = sshKey.privateKey;
|
||||||
settings.sshPassword = sshKey.password;
|
gitConfig.sshPassword = sshKey.password;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
publicKey = sshKey.publicKey;
|
publicKey = sshKey.publicKey;
|
||||||
@ -555,7 +556,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
var repo = context.read<GitJournalRepo>();
|
var repo = context.read<GitJournalRepo>();
|
||||||
var basePath = repo.gitBaseDirectory;
|
var basePath = repo.gitBaseDirectory;
|
||||||
|
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
var repoPath = p.join(basePath, widget.repoFolderName);
|
var repoPath = p.join(basePath, widget.repoFolderName);
|
||||||
Log.i("RepoPath: $repoPath");
|
Log.i("RepoPath: $repoPath");
|
||||||
|
|
||||||
@ -563,11 +564,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
cloneUrl: _gitCloneUrl,
|
cloneUrl: _gitCloneUrl,
|
||||||
remoteName: widget.remoteName,
|
remoteName: widget.remoteName,
|
||||||
repoPath: repoPath,
|
repoPath: repoPath,
|
||||||
sshPassword: settings.sshPassword,
|
sshPassword: gitConfig.sshPassword,
|
||||||
sshPrivateKey: settings.sshPrivateKey,
|
sshPrivateKey: gitConfig.sshPrivateKey,
|
||||||
sshPublicKey: settings.sshPublicKey,
|
sshPublicKey: gitConfig.sshPublicKey,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: gitConfig.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: gitConfig.gitAuthor,
|
||||||
progressUpdate: (GitTransferProgress p) {
|
progressUpdate: (GitTransferProgress p) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_cloneProgress = p;
|
_cloneProgress = p;
|
||||||
@ -593,6 +594,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
parameters: _buildOnboardingAnalytics(),
|
parameters: _buildOnboardingAnalytics(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var settings = Provider.of<Settings>(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);
|
||||||
@ -627,11 +629,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
// FIXME: Handle case when sshKey generation failed
|
// FIXME: Handle case when sshKey generation failed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var settings = Provider.of<Settings>(context, listen: false);
|
var gitConfig = Provider.of<GitConfig>(context, listen: false);
|
||||||
settings.sshPublicKey = sshKey.publicKey;
|
gitConfig.sshPublicKey = sshKey.publicKey;
|
||||||
settings.sshPrivateKey = sshKey.privateKey;
|
gitConfig.sshPrivateKey = sshKey.privateKey;
|
||||||
settings.sshPassword = sshKey.password;
|
gitConfig.sshPassword = sshKey.password;
|
||||||
settings.save();
|
gitConfig.save();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
publicKey = sshKey.publicKey;
|
publicKey = sshKey.publicKey;
|
||||||
|
Reference in New Issue
Block a user