mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Core: Finish null safety migration
This commit is contained in:
@ -1,10 +1,6 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io' show Platform;
|
import 'dart:io' show Platform;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
|
|
||||||
import 'package:dart_git/dart_git.dart' as git;
|
import 'package:dart_git/dart_git.dart' as git;
|
||||||
import 'package:git_bindings/git_bindings.dart';
|
import 'package:git_bindings/git_bindings.dart';
|
||||||
|
|
||||||
@ -19,10 +15,10 @@ bool useDartGit = false;
|
|||||||
|
|
||||||
class NoteRepoResult {
|
class NoteRepoResult {
|
||||||
bool error;
|
bool error;
|
||||||
String noteFilePath;
|
String? noteFilePath;
|
||||||
|
|
||||||
NoteRepoResult({
|
NoteRepoResult({
|
||||||
@required this.error,
|
required this.error,
|
||||||
this.noteFilePath,
|
this.noteFilePath,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -33,10 +29,10 @@ class GitNoteRepository {
|
|||||||
final Settings settings;
|
final Settings settings;
|
||||||
|
|
||||||
GitNoteRepository({
|
GitNoteRepository({
|
||||||
@required this.gitDirPath,
|
required this.gitDirPath,
|
||||||
@required this.settings,
|
required this.settings,
|
||||||
}) : _gitRepo = GitRepo(folderPath: gitDirPath) {
|
}) : _gitRepo = GitRepo(folderPath: gitDirPath) {
|
||||||
// git-bindings aren't properly implemented in these platformsk
|
// git-bindings aren't properly implemented in these platforms
|
||||||
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
|
if (Platform.isLinux || Platform.isMacOS || Platform.isWindows) {
|
||||||
useDartGit = true;
|
useDartGit = true;
|
||||||
}
|
}
|
||||||
@ -61,7 +57,9 @@ class GitNoteRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _commit(
|
Future<void> _commit(
|
||||||
{String message, String authorEmail, String authorName}) async {
|
{required String /*!*/ message,
|
||||||
|
required String authorEmail,
|
||||||
|
required String authorName}) async {
|
||||||
if (useDartGit) {
|
if (useDartGit) {
|
||||||
var repo = await git.GitRepository.load(gitDirPath);
|
var repo = await git.GitRepository.load(gitDirPath);
|
||||||
var author = git.GitAuthor(name: authorName, email: authorEmail);
|
var author = git.GitAuthor(name: authorName, email: authorEmail);
|
||||||
@ -225,6 +223,9 @@ class GitNoteRepository {
|
|||||||
Future<void> merge() async {
|
Future<void> merge() async {
|
||||||
var repo = await git.GitRepository.load(gitDirPath);
|
var repo = await git.GitRepository.load(gitDirPath);
|
||||||
var branch = await repo.currentBranch();
|
var branch = await repo.currentBranch();
|
||||||
|
if (branch == null) {
|
||||||
|
throw Exception('No current branch found');
|
||||||
|
}
|
||||||
var branchConfig = repo.config.branch(branch);
|
var branchConfig = repo.config.branch(branch);
|
||||||
if (branchConfig == null) {
|
if (branchConfig == null) {
|
||||||
logExceptionWarning(
|
logExceptionWarning(
|
||||||
@ -232,12 +233,9 @@ class GitNoteRepository {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(branchConfig.name != null);
|
|
||||||
assert(branchConfig.merge != null);
|
|
||||||
|
|
||||||
var remoteRef = await repo.remoteBranch(
|
var remoteRef = await repo.remoteBranch(
|
||||||
branchConfig.remote,
|
branchConfig.remote!,
|
||||||
branchConfig.trackingBranch(),
|
branchConfig.trackingBranch()!,
|
||||||
);
|
);
|
||||||
if (remoteRef == null) {
|
if (remoteRef == null) {
|
||||||
Log.i('Remote has no refs');
|
Log.i('Remote has no refs');
|
||||||
@ -282,13 +280,15 @@ class GitNoteRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> numChanges() async {
|
Future<int?> numChanges() async {
|
||||||
try {
|
try {
|
||||||
var repo = await git.GitRepository.load(gitDirPath);
|
var repo = await git.GitRepository.load(gitDirPath);
|
||||||
var n = await repo.numChangesToPush();
|
var n = await repo.numChangesToPush();
|
||||||
return n;
|
return n;
|
||||||
} catch (_) {}
|
} catch (ex, st) {
|
||||||
return 0;
|
Log.e("numChanges", ex: ex, stacktrace: st);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ bool shouldLogGitException(Exception ex) {
|
|||||||
if (ex is! GitException) {
|
if (ex is! GitException) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var msg = (ex as GitException).cause.toLowerCase();
|
var msg = ex.cause.toLowerCase();
|
||||||
for (var i = 0; i < ignoredMessages.length; i++) {
|
for (var i = 0; i < ignoredMessages.length; i++) {
|
||||||
if (msg.contains(ignoredMessages[i])) {
|
if (msg.contains(ignoredMessages[i])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
@ -19,11 +17,11 @@ class Node {
|
|||||||
double forceX = 0.0;
|
double forceX = 0.0;
|
||||||
double forceY = 0.0;
|
double forceY = 0.0;
|
||||||
|
|
||||||
String _label;
|
String? _label;
|
||||||
|
|
||||||
Node(this.note);
|
Node(this.note);
|
||||||
|
|
||||||
String get label {
|
String? get label {
|
||||||
_label ??= note.pathSpec();
|
_label ??= note.pathSpec();
|
||||||
return _label;
|
return _label;
|
||||||
}
|
}
|
||||||
@ -43,10 +41,10 @@ class Graph extends ChangeNotifier {
|
|||||||
List<Node> nodes = [];
|
List<Node> nodes = [];
|
||||||
List<Edge> edges = [];
|
List<Edge> edges = [];
|
||||||
|
|
||||||
Map<String, Set<int>> _neighbours = {};
|
Map<String?, Set<int?>> _neighbours = {};
|
||||||
Map<String, int> _nodeIndexes;
|
Map<String?, int>? _nodeIndexes;
|
||||||
|
|
||||||
GraphNodeLayout initLayouter;
|
late GraphNodeLayout initLayouter;
|
||||||
|
|
||||||
final double nodeSize = 50.0;
|
final double nodeSize = 50.0;
|
||||||
|
|
||||||
@ -78,6 +76,9 @@ class Graph extends ChangeNotifier {
|
|||||||
var node = _getNode(note);
|
var node = _getNode(note);
|
||||||
|
|
||||||
var links = await node.note.fetchLinks();
|
var links = await node.note.fetchLinks();
|
||||||
|
if (links == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var linkResolver = LinkResolver(note);
|
var linkResolver = LinkResolver(note);
|
||||||
for (var l in links) {
|
for (var l in links) {
|
||||||
var noteB = linkResolver.resolveLink(l);
|
var noteB = linkResolver.resolveLink(l);
|
||||||
@ -110,12 +111,12 @@ class Graph extends ChangeNotifier {
|
|||||||
startLayout();
|
startLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> computeNeighbours(Node n) {
|
List<int?> computeNeighbours(Node n) {
|
||||||
if (_nodeIndexes == null) {
|
if (_nodeIndexes == null) {
|
||||||
_nodeIndexes = <String, int>{};
|
_nodeIndexes = <String?, int>{};
|
||||||
for (var i = 0; i < this.nodes.length; i++) {
|
for (var i = 0; i < this.nodes.length; i++) {
|
||||||
var node = this.nodes[i];
|
var node = this.nodes[i];
|
||||||
_nodeIndexes[node.label] = i;
|
_nodeIndexes![node.label] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,15 +125,15 @@ class Graph extends ChangeNotifier {
|
|||||||
return _nodes.union(computeOverlappingNodes(n)).toList();
|
return _nodes.union(computeOverlappingNodes(n)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodes = <int>{};
|
var nodes = <int?>{};
|
||||||
for (var edge in edges) {
|
for (var edge in edges) {
|
||||||
if (edge.a.label == n.label) {
|
if (edge.a.label == n.label) {
|
||||||
nodes.add(_nodeIndexes[edge.b.label]);
|
nodes.add(_nodeIndexes![edge.b.label]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (edge.b.label == n.label) {
|
if (edge.b.label == n.label) {
|
||||||
nodes.add(_nodeIndexes[edge.a.label]);
|
nodes.add(_nodeIndexes![edge.a.label]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,7 +165,7 @@ class Graph extends ChangeNotifier {
|
|||||||
return _nodes;
|
return _nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer layoutTimer;
|
Timer? layoutTimer;
|
||||||
|
|
||||||
void startLayout() {
|
void startLayout() {
|
||||||
if (layoutTimer != null) {
|
if (layoutTimer != null) {
|
||||||
@ -191,7 +192,7 @@ class Graph extends ChangeNotifier {
|
|||||||
|
|
||||||
void stopLayout() {
|
void stopLayout() {
|
||||||
if (layoutTimer != null) {
|
if (layoutTimer != null) {
|
||||||
layoutTimer.cancel();
|
layoutTimer!.cancel();
|
||||||
layoutTimer = null;
|
layoutTimer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +211,7 @@ class GraphNodeLayout {
|
|||||||
double gap = 70;
|
double gap = 70;
|
||||||
double nodeSize = 50;
|
double nodeSize = 50;
|
||||||
|
|
||||||
GraphNodeLayout({@required this.maxWidth, @required this.maxHeight}) {
|
GraphNodeLayout({required this.maxWidth, required this.maxHeight}) {
|
||||||
x = startX;
|
x = startX;
|
||||||
y = startY;
|
y = startY;
|
||||||
}
|
}
|
||||||
@ -288,7 +289,7 @@ bool _updateGraphPositions(Graph g) {
|
|||||||
var node1Neighbours = g.computeNeighbours(node1);
|
var node1Neighbours = g.computeNeighbours(node1);
|
||||||
|
|
||||||
for (var j = 0; j < node1Neighbours.length; j++) {
|
for (var j = 0; j < node1Neighbours.length; j++) {
|
||||||
var i2 = node1Neighbours[j];
|
var i2 = node1Neighbours[j]!;
|
||||||
var node2 = g.nodes[i2];
|
var node2 = g.nodes[i2];
|
||||||
|
|
||||||
if (i1 < i2) {
|
if (i1 < i2) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
import 'package:gitjournal/core/notes_folder.dart';
|
import 'package:gitjournal/core/notes_folder.dart';
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:gitjournal/core/sorting_mode.dart';
|
import 'package:gitjournal/core/sorting_mode.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
import 'note.dart';
|
import 'note.dart';
|
||||||
@ -13,14 +9,14 @@ import 'notes_folder_notifier.dart';
|
|||||||
class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
|
class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
|
||||||
final NotesFolder folder;
|
final NotesFolder folder;
|
||||||
|
|
||||||
SortingMode _sortingMode;
|
late SortingMode _sortingMode;
|
||||||
NoteSortingFunction _sortFunc;
|
late NoteSortingFunction _sortFunc;
|
||||||
|
|
||||||
List<Note> _notes = [];
|
List<Note> _notes = [];
|
||||||
|
|
||||||
SortedNotesFolder({
|
SortedNotesFolder({
|
||||||
@required this.folder,
|
required this.folder,
|
||||||
@required SortingMode sortingMode,
|
required SortingMode sortingMode,
|
||||||
}) {
|
}) {
|
||||||
_sortingMode = sortingMode;
|
_sortingMode = sortingMode;
|
||||||
_sortFunc = _sortingMode.sortingFunction();
|
_sortFunc = _sortingMode.sortingFunction();
|
||||||
@ -155,7 +151,7 @@ class SortedNotesFolder with NotesFolderNotifier implements NotesFolder {
|
|||||||
SortingMode get sortingMode => _sortingMode;
|
SortingMode get sortingMode => _sortingMode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
NotesFolder get parent => folder.parent;
|
NotesFolder? get parent => folder.parent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String pathSpec() => folder.pathSpec();
|
String pathSpec() => folder.pathSpec();
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/core/processors/wiki_links_auto_add.dart';
|
import 'package:gitjournal/core/processors/wiki_links_auto_add.dart';
|
||||||
|
import 'package:gitjournal/settings.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Should process body', () {
|
test('Should process body', () {
|
||||||
var body =
|
var body =
|
||||||
"GitJournal is the best? And it works quite well with Foam, Foam and Obsidian.";
|
"GitJournal is the best? And it works quite well with Foam, Foam and Obsidian.";
|
||||||
|
|
||||||
var p = WikiLinksAutoAddProcessor(null);
|
var folder = NotesFolderFS(null, '/', Settings(''));
|
||||||
|
var p = WikiLinksAutoAddProcessor(folder);
|
||||||
var newBody = p.processBody(body, ['GitJournal', 'Foam', 'Obsidian']);
|
var newBody = p.processBody(body, ['GitJournal', 'Foam', 'Obsidian']);
|
||||||
var expectedBody =
|
var expectedBody =
|
||||||
"[[GitJournal]] is the best? And it works quite well with [[Foam]], [[Foam]] and [[Obsidian]].";
|
"[[GitJournal]] is the best? And it works quite well with [[Foam]], [[Foam]] and [[Obsidian]].";
|
||||||
|
Reference in New Issue
Block a user