mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 16:46:51 +08:00
Add support for getting clone progress from git_bindings
This is hacky, and we're getting it through a file. Right now we aren't doing anything with the progress, we're just fetching it.
This commit is contained in:
@ -217,6 +217,7 @@ bool handleError(FlutterResult result, int err) {
|
|||||||
NSString *publicKey = arguments[@"publicKey"];
|
NSString *publicKey = arguments[@"publicKey"];
|
||||||
NSString *privateKey = arguments[@"privateKey"];
|
NSString *privateKey = arguments[@"privateKey"];
|
||||||
NSString *password = arguments[@"password"];
|
NSString *password = arguments[@"password"];
|
||||||
|
NSString *statusFile = arguments[@"statusFile"];
|
||||||
|
|
||||||
if (publicKey == nil || [publicKey length] == 0) {
|
if (publicKey == nil || [publicKey length] == 0) {
|
||||||
result([FlutterError errorWithCode:@"InvalidParams"
|
result([FlutterError errorWithCode:@"InvalidParams"
|
||||||
@ -244,8 +245,13 @@ bool handleError(FlutterResult result, int err) {
|
|||||||
message:@"Invalid remote" details:nil]);
|
message:@"Invalid remote" details:nil]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (statusFile == nil) {
|
||||||
|
result([FlutterError errorWithCode:@"InvalidParams"
|
||||||
|
message:@"Invalid statusFile" details:nil]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int err = gj_git_fetch([folderPath UTF8String], [remote UTF8String], [publicKey UTF8String], [privateKey UTF8String], [password UTF8String], true);
|
int err = gj_git_fetch([folderPath UTF8String], [remote UTF8String], [publicKey UTF8String], [privateKey UTF8String], [password UTF8String], true, [statusFile UTF8String]);
|
||||||
if (!handleError(result, err)) {
|
if (!handleError(result, err)) {
|
||||||
result(@YES);
|
result(@YES);
|
||||||
return;
|
return;
|
||||||
@ -290,6 +296,7 @@ bool handleError(FlutterResult result, int err) {
|
|||||||
NSString *publicKey = arguments[@"publicKey"];
|
NSString *publicKey = arguments[@"publicKey"];
|
||||||
NSString *privateKey = arguments[@"privateKey"];
|
NSString *privateKey = arguments[@"privateKey"];
|
||||||
NSString *password = arguments[@"password"];
|
NSString *password = arguments[@"password"];
|
||||||
|
NSString *statusFile = arguments[@"statusFile"];
|
||||||
|
|
||||||
if (publicKey == nil || [publicKey length] == 0) {
|
if (publicKey == nil || [publicKey length] == 0) {
|
||||||
result([FlutterError errorWithCode:@"InvalidParams"
|
result([FlutterError errorWithCode:@"InvalidParams"
|
||||||
@ -317,8 +324,13 @@ bool handleError(FlutterResult result, int err) {
|
|||||||
message:@"Invalid remote" details:nil]);
|
message:@"Invalid remote" details:nil]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (statusFile == nil) {
|
||||||
|
result([FlutterError errorWithCode:@"InvalidParams"
|
||||||
|
message:@"Invalid statusFile" details:nil]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int err = gj_git_push([folderPath UTF8String], [remote UTF8String], [publicKey UTF8String], [privateKey UTF8String], [password UTF8String], true);
|
int err = gj_git_push([folderPath UTF8String], [remote UTF8String], [publicKey UTF8String], [privateKey UTF8String], [password UTF8String], true, [statusFile UTF8String]);
|
||||||
if (!handleError(result, err)) {
|
if (!handleError(result, err)) {
|
||||||
result(@YES);
|
result(@YES);
|
||||||
return;
|
return;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io' show Platform;
|
import 'dart:io' show Platform, Directory;
|
||||||
|
|
||||||
import 'package:dart_git/dart_git.dart';
|
import 'package:dart_git/dart_git.dart';
|
||||||
import 'package:dart_git/utils/result.dart';
|
import 'package:dart_git/utils/result.dart';
|
||||||
import 'package:git_bindings/git_bindings.dart' as gb;
|
import 'package:git_bindings/git_bindings.dart' as gb;
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
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';
|
||||||
@ -218,6 +219,7 @@ class GitNoteRepository {
|
|||||||
publicKey: settings.sshPublicKey,
|
publicKey: settings.sshPublicKey,
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: settings.sshPrivateKey,
|
||||||
password: settings.sshPassword,
|
password: settings.sshPassword,
|
||||||
|
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
||||||
);
|
);
|
||||||
} on gb.GitException catch (ex, stackTrace) {
|
} on gb.GitException catch (ex, stackTrace) {
|
||||||
Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace);
|
Log.e("GitPull Failed", ex: ex, stacktrace: stackTrace);
|
||||||
@ -301,6 +303,7 @@ class GitNoteRepository {
|
|||||||
publicKey: settings.sshPublicKey,
|
publicKey: settings.sshPublicKey,
|
||||||
privateKey: settings.sshPrivateKey,
|
privateKey: settings.sshPrivateKey,
|
||||||
password: settings.sshPassword,
|
password: settings.sshPassword,
|
||||||
|
statusFile: p.join(Directory.systemTemp.path, 'gj'),
|
||||||
);
|
);
|
||||||
} on gb.GitException catch (ex, stackTrace) {
|
} on gb.GitException catch (ex, stackTrace) {
|
||||||
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
if (ex.cause == 'cannot push non-fastforwardable reference') {
|
||||||
|
@ -1,13 +1,45 @@
|
|||||||
import 'dart:io' show Platform;
|
import 'dart:async';
|
||||||
|
import 'dart:io' show Platform, Directory, File;
|
||||||
|
|
||||||
import 'package:dart_git/dart_git.dart';
|
import 'package:dart_git/dart_git.dart';
|
||||||
import 'package:dart_git/exceptions.dart';
|
import 'package:dart_git/exceptions.dart';
|
||||||
|
import 'package:function_types/function_types.dart';
|
||||||
import 'package:git_bindings/git_bindings.dart' as git_bindings;
|
import 'package:git_bindings/git_bindings.dart' as git_bindings;
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
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';
|
||||||
|
|
||||||
|
class GitTransferProgress {
|
||||||
|
int totalObjects = 0;
|
||||||
|
int indexedObjects = 0;
|
||||||
|
int receivedObjects = 0;
|
||||||
|
int localObjects = 0;
|
||||||
|
int totalDeltas = 0;
|
||||||
|
int indexedDeltas = 0;
|
||||||
|
int receivedBytes = 0;
|
||||||
|
|
||||||
|
static Future<GitTransferProgress?> load(String statusFile) async {
|
||||||
|
if (!File(statusFile).existsSync()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var str = await File(statusFile).readAsString();
|
||||||
|
var parts = str.split(' ');
|
||||||
|
print('Str #$str#');
|
||||||
|
print('Parts $parts');
|
||||||
|
|
||||||
|
var tp = GitTransferProgress();
|
||||||
|
tp.totalObjects = int.parse(parts[0]);
|
||||||
|
tp.indexedObjects = int.parse(parts[1]);
|
||||||
|
tp.receivedObjects = int.parse(parts[2]);
|
||||||
|
tp.localObjects = int.parse(parts[3]);
|
||||||
|
tp.totalDeltas = int.parse(parts[4]);
|
||||||
|
tp.indexedDeltas = int.parse(parts[5]);
|
||||||
|
tp.receivedBytes = int.parse(parts[6]);
|
||||||
|
return tp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<Result<void>> cloneRemote({
|
Future<Result<void>> cloneRemote({
|
||||||
required String repoPath,
|
required String repoPath,
|
||||||
required String cloneUrl,
|
required String cloneUrl,
|
||||||
@ -17,6 +49,7 @@ Future<Result<void>> cloneRemote({
|
|||||||
required String sshPassword,
|
required String sshPassword,
|
||||||
required String authorName,
|
required String authorName,
|
||||||
required String authorEmail,
|
required String authorEmail,
|
||||||
|
required Func1<GitTransferProgress, void> progressUpdate,
|
||||||
}) async {
|
}) async {
|
||||||
var repo = await GitRepository.load(repoPath).getOrThrow();
|
var repo = await GitRepository.load(repoPath).getOrThrow();
|
||||||
var remote = await repo.addOrUpdateRemote(remoteName, cloneUrl).getOrThrow();
|
var remote = await repo.addOrUpdateRemote(remoteName, cloneUrl).getOrThrow();
|
||||||
@ -25,12 +58,22 @@ Future<Result<void>> cloneRemote({
|
|||||||
var _gitRepo = git_bindings.GitRepo(folderPath: repoPath);
|
var _gitRepo = git_bindings.GitRepo(folderPath: repoPath);
|
||||||
|
|
||||||
if (Platform.isAndroid || Platform.isIOS) {
|
if (Platform.isAndroid || Platform.isIOS) {
|
||||||
|
var statusFile = p.join(Directory.systemTemp.path, 'gj');
|
||||||
|
var duration = const Duration(milliseconds: 10);
|
||||||
|
var timer = Timer.periodic(duration, (_) async {
|
||||||
|
var progress = await GitTransferProgress.load(statusFile);
|
||||||
|
if (progress != null) {
|
||||||
|
progressUpdate(progress);
|
||||||
|
}
|
||||||
|
});
|
||||||
await _gitRepo.fetch(
|
await _gitRepo.fetch(
|
||||||
remote: remoteName,
|
remote: remoteName,
|
||||||
publicKey: sshPublicKey,
|
publicKey: sshPublicKey,
|
||||||
privateKey: sshPrivateKey,
|
privateKey: sshPrivateKey,
|
||||||
password: sshPassword,
|
password: sshPassword,
|
||||||
|
statusFile: statusFile,
|
||||||
);
|
);
|
||||||
|
timer.cancel();
|
||||||
|
|
||||||
remoteBranchName = await _remoteDefaultBranch(
|
remoteBranchName = await _remoteDefaultBranch(
|
||||||
repo: repo,
|
repo: repo,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'clone.dart';
|
||||||
import 'error.dart';
|
import 'error.dart';
|
||||||
import 'loading.dart';
|
import 'loading.dart';
|
||||||
|
|
||||||
@ -21,3 +22,24 @@ class GitHostSetupLoadingErrorPage extends StatelessWidget {
|
|||||||
return GitHostSetupErrorPage(errorMessage!);
|
return GitHostSetupErrorPage(errorMessage!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GitHostCloningPage extends StatelessWidget {
|
||||||
|
final String? errorMessage;
|
||||||
|
final String loadingMessage;
|
||||||
|
final GitTransferProgress cloneProgress;
|
||||||
|
|
||||||
|
GitHostCloningPage({
|
||||||
|
required this.errorMessage,
|
||||||
|
required this.loadingMessage,
|
||||||
|
required this.cloneProgress,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (errorMessage == null || errorMessage!.isEmpty) {
|
||||||
|
return GitHostSetupLoadingPage(loadingMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GitHostSetupErrorPage(errorMessage!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -65,6 +65,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
String _autoConfigureErrorMessage = "";
|
String _autoConfigureErrorMessage = "";
|
||||||
|
|
||||||
var _gitCloneUrl = "";
|
var _gitCloneUrl = "";
|
||||||
|
var _cloneProgress = GitTransferProgress();
|
||||||
String? gitCloneErrorMessage = "";
|
String? gitCloneErrorMessage = "";
|
||||||
var publicKey = "";
|
var publicKey = "";
|
||||||
|
|
||||||
@ -287,9 +288,10 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
|
|
||||||
if (pos == 4) {
|
if (pos == 4) {
|
||||||
if (_pageChoice[0] == PageChoice0.CustomProvider) {
|
if (_pageChoice[0] == PageChoice0.CustomProvider) {
|
||||||
return GitHostSetupLoadingErrorPage(
|
return GitHostCloningPage(
|
||||||
loadingMessage: tr('setup.cloning'),
|
loadingMessage: tr('setup.cloning'),
|
||||||
errorMessage: gitCloneErrorMessage,
|
errorMessage: gitCloneErrorMessage,
|
||||||
|
cloneProgress: _cloneProgress,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,6 +561,11 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
sshPublicKey: settings.sshPublicKey,
|
sshPublicKey: settings.sshPublicKey,
|
||||||
authorEmail: settings.gitAuthorEmail,
|
authorEmail: settings.gitAuthorEmail,
|
||||||
authorName: settings.gitAuthor,
|
authorName: settings.gitAuthor,
|
||||||
|
progressUpdate: (GitTransferProgress p) {
|
||||||
|
setState(() {
|
||||||
|
_cloneProgress = p;
|
||||||
|
});
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} on Exception catch (e, stacktrace) {
|
} on Exception catch (e, stacktrace) {
|
||||||
Log.e("Failed to clone", ex: e, stacktrace: stacktrace);
|
Log.e("Failed to clone", ex: e, stacktrace: stacktrace);
|
||||||
|
@ -559,7 +559,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: HEAD
|
ref: HEAD
|
||||||
resolved-ref: "693a9266b845bed900f2c076ce2a4096d47d0039"
|
resolved-ref: "24612004500f388dc94b4670ae6fd39c14311f04"
|
||||||
url: "https://github.com/GitJournal/git_bindings.git"
|
url: "https://github.com/GitJournal/git_bindings.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.0.18"
|
version: "0.0.18"
|
||||||
|
Reference in New Issue
Block a user