Skip to content

Commit feaaf55

Browse files
committed
feat: experimental optimised sync flag
1 parent f3260f9 commit feaaf55

12 files changed

+130
-64
lines changed

lib/api/manager/storage.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum StorageKey<T> {
5050
setman_gitCommitSigningKey<String?>(name: "gitCommitSigningKey", defaultValue: null),
5151
setman_gitCommitSigningPassphrase<String?>(name: "gitCommitSigningPassphrase", defaultValue: null),
5252
setman_clientModeEnabled<bool?>(name: "clientModeEnabled", defaultValue: false, hasDefault: true),
53+
setman_optimisedSyncExperimental<bool>(name: "optimisedSyncExperimental", defaultValue: false),
5354

5455
// Git Manager
5556
setman_lfsFilePaths<List<String>>(name: "lfsFilePaths", defaultValue: []),

lib/gitsync_service.dart

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class GitsyncService {
192192
}
193193

194194
bool synced = false;
195+
bool? pullResult = null;
196+
bool? pushResult = null;
195197

196198
if (!await hasNetworkConnection()) {
197199
Workmanager().registerOneOffTask(
@@ -203,77 +205,86 @@ class GitsyncService {
203205
return;
204206
}
205207

206-
Logger.gmLog(type: LogType.Sync, "Start Pull Repo");
207-
final pullResult = await GitManager.downloadChanges(repomanRepoindex, settingsManager, () {
208-
synced = true;
209-
_displaySyncMessage(settingsManager, s.syncStartPull);
210-
});
211-
212-
switch (pullResult) {
213-
case null:
214-
{
215-
Logger.gmLog(type: LogType.Sync, "Pull Repo Failed");
216-
if (!await hasNetworkConnection()) {
217-
Workmanager().registerOneOffTask(
218-
"$networkScheduledSyncKey$repomanRepoindex",
219-
networkScheduledSyncKey,
220-
inputData: {repoIndex: repomanRepoindex},
221-
constraints: Constraints(networkType: NetworkType.connected),
222-
);
208+
final optimisedSyncFlag = await settingsManager.getBool(StorageKey.setman_optimisedSyncExperimental);
209+
final recommendedAction = await GitManager.getRecommendedAction();
210+
211+
if (optimisedSyncFlag && recommendedAction == null) return;
212+
213+
if (!optimisedSyncFlag || (recommendedAction == 0 || recommendedAction == 1)) {
214+
Logger.gmLog(type: LogType.Sync, "Start Pull Repo");
215+
pullResult = await GitManager.downloadChanges(repomanRepoindex, settingsManager, () {
216+
synced = true;
217+
_displaySyncMessage(settingsManager, s.syncStartPull);
218+
});
219+
220+
switch (pullResult) {
221+
case null:
222+
{
223+
Logger.gmLog(type: LogType.Sync, "Pull Repo Failed");
224+
if (!await hasNetworkConnection()) {
225+
Workmanager().registerOneOffTask(
226+
"$networkScheduledSyncKey$repomanRepoindex",
227+
networkScheduledSyncKey,
228+
inputData: {repoIndex: repomanRepoindex},
229+
constraints: Constraints(networkType: NetworkType.connected),
230+
);
231+
return;
232+
}
223233
return;
224234
}
225-
return;
226-
}
227-
case true:
228-
{
229-
Logger.gmLog(type: LogType.Sync, "Pull Complete");
230-
}
231-
case false:
232-
{
233-
Logger.gmLog(type: LogType.Sync, "Pull Not Required");
234-
}
235-
}
235+
case true:
236+
{
237+
Logger.gmLog(type: LogType.Sync, "Pull Complete");
238+
}
239+
case false:
240+
{
241+
Logger.gmLog(type: LogType.Sync, "Pull Not Required");
242+
}
243+
}
236244

237-
if (!await hasNetworkConnection()) {
238-
Workmanager().registerOneOffTask(
239-
"$networkScheduledSyncKey$repomanRepoindex",
240-
networkScheduledSyncKey,
241-
inputData: {repoIndex: repomanRepoindex},
242-
constraints: Constraints(networkType: NetworkType.connected),
243-
);
244-
return;
245+
if (!await hasNetworkConnection()) {
246+
Workmanager().registerOneOffTask(
247+
"$networkScheduledSyncKey$repomanRepoindex",
248+
networkScheduledSyncKey,
249+
inputData: {repoIndex: repomanRepoindex},
250+
constraints: Constraints(networkType: NetworkType.connected),
251+
);
252+
return;
253+
}
245254
}
246255

247-
Logger.gmLog(type: LogType.Sync, "Start Push Repo");
248-
final pushResult = await GitManager.uploadChanges(repomanRepoindex, settingsManager, () {
249-
if (!synced) {
250-
_displaySyncMessage(settingsManager, s.syncStartPush);
251-
}
252-
});
253-
254-
switch (pushResult) {
255-
case null:
256-
{
257-
Logger.gmLog(type: LogType.Sync, "Push Repo Failed");
258-
if (!await hasNetworkConnection()) {
259-
Workmanager().registerOneOffTask(
260-
"$networkScheduledSyncKey$repomanRepoindex",
261-
networkScheduledSyncKey,
262-
inputData: {repoIndex: repomanRepoindex},
263-
constraints: Constraints(networkType: NetworkType.connected),
264-
);
256+
if (!optimisedSyncFlag || recommendedAction == 2 || recommendedAction == 3) {
257+
Logger.gmLog(type: LogType.Sync, "Start Push Repo");
258+
pushResult = await GitManager.uploadChanges(repomanRepoindex, settingsManager, () {
259+
if (!synced) {
260+
_displaySyncMessage(settingsManager, s.syncStartPush);
261+
}
262+
});
263+
264+
switch (pushResult) {
265+
case null:
266+
{
267+
Logger.gmLog(type: LogType.Sync, "Push Repo Failed");
268+
if (!await hasNetworkConnection()) {
269+
Workmanager().registerOneOffTask(
270+
"$networkScheduledSyncKey$repomanRepoindex",
271+
networkScheduledSyncKey,
272+
inputData: {repoIndex: repomanRepoindex},
273+
constraints: Constraints(networkType: NetworkType.connected),
274+
);
275+
return;
276+
}
265277
return;
266278
}
267-
return;
268-
}
269-
case true:
270-
{
271-
Logger.gmLog(type: LogType.Sync, "Push Complete");
272-
}
273-
case false:
274-
{
275-
Logger.gmLog(type: LogType.Sync, "Push Not Required");
276-
}
279+
case true:
280+
{
281+
Logger.gmLog(type: LogType.Sync, "Push Complete");
282+
}
283+
case false:
284+
{
285+
Logger.gmLog(type: LogType.Sync, "Push Not Required");
286+
}
287+
}
277288
}
278289

279290
if (!(pushResult == true || pullResult == true)) {

lib/l10n/app_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
"disableSsl": "Disable SSL",
267267
"disableSslPromptTitle": "Disable SSL?",
268268
"disableSslPromptMsg": "The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.",
269+
"optimisedSync": "Optimised Sync",
269270
"proceedAnyway": "Proceed anyway?",
270271
"moreOptions": "More Options",
271272

lib/l10n/app_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ abstract class AppLocalizations {
15081508
/// **'The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.'**
15091509
String get disableSslPromptMsg;
15101510

1511+
/// No description provided for @optimisedSync.
1512+
///
1513+
/// In en, this message translates to:
1514+
/// **'Optimised Sync'**
1515+
String get optimisedSync;
1516+
15111517
/// No description provided for @proceedAnyway.
15121518
///
15131519
/// In en, this message translates to:

lib/l10n/app_localizations_de.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ class AppLocalizationsDe extends AppLocalizations {
731731
@override
732732
String get disableSslPromptMsg => 'The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.';
733733

734+
@override
735+
String get optimisedSync => 'Optimised Sync';
736+
734737
@override
735738
String get proceedAnyway => 'Proceed anyway?';
736739

lib/l10n/app_localizations_en.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ class AppLocalizationsEn extends AppLocalizations {
725725
@override
726726
String get disableSslPromptMsg => 'The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.';
727727

728+
@override
729+
String get optimisedSync => 'Optimised Sync';
730+
728731
@override
729732
String get proceedAnyway => 'Proceed anyway?';
730733

lib/l10n/app_localizations_es.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ class AppLocalizationsEs extends AppLocalizations {
730730
@override
731731
String get disableSslPromptMsg => 'The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.';
732732

733+
@override
734+
String get optimisedSync => 'Optimised Sync';
735+
733736
@override
734737
String get proceedAnyway => 'Proceed anyway?';
735738

lib/l10n/app_localizations_fr.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@ class AppLocalizationsFr extends AppLocalizations {
734734
String get disableSslPromptMsg =>
735735
'L\'adresse que vous avez clonée commence par \"http\" (non sécurisé). La désactivation du SSL correspondra à l\'URL mais réduira la sécurité.';
736736

737+
@override
738+
String get optimisedSync => 'Optimised Sync';
739+
737740
@override
738741
String get proceedAnyway => 'Continuer quand même ?';
739742

lib/l10n/app_localizations_ru.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ class AppLocalizationsRu extends AppLocalizations {
728728
@override
729729
String get disableSslPromptMsg => 'The address you cloned starts with \"http\" (not secure). Disabling SSL will match the URL but reduce security.';
730730

731+
@override
732+
String get optimisedSync => 'Optimised Sync';
733+
731734
@override
732735
String get proceedAnyway => 'Proceed anyway?';
733736

lib/l10n/app_localizations_zh.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,9 @@ class AppLocalizationsZh extends AppLocalizations {
714714
@override
715715
String get disableSslPromptMsg => '您克隆的地址以 \"http\" 开头 (不安全)。您可以选择禁用 SSL 验证,但这会降低安全性。';
716716

717+
@override
718+
String get optimisedSync => 'Optimised Sync';
719+
717720
@override
718721
String get proceedAnyway => '照常进行吗?';
719722

0 commit comments

Comments
 (0)