Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = G7NB5YCKAP;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.15.5;
MARKETING_VERSION = 0.15.6;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = io.numbersprotocol.capturelite;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -381,12 +381,12 @@
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = G7NB5YCKAP;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 0.15.5;
MARKETING_VERSION = 0.15.6;
PRODUCT_BUNDLE_IDENTIFIER = io.numbersprotocol.capturelite;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
41 changes: 16 additions & 25 deletions src/app/shared/services/migration/migration.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Plugins } from '@capacitor/core';
import { defer } from 'rxjs';
import { concatMap, first } from 'rxjs/operators';
import { BehaviorSubject, defer } from 'rxjs';
import { concatMap, distinctUntilChanged, tap } from 'rxjs/operators';
import { VOID$ } from '../../../utils/rx-operators/rx-operators';
import { MigratingDialogComponent } from '../../core/migrating-dialog/migrating-dialog.component';
import {
DiaBackendAsset,
DiaBackendAssetRepository,
} from '../dia-backend/asset/dia-backend-asset-repository.service';
import { NetworkService } from '../network/network.service';
import { OnboardingService } from '../onboarding/onboarding.service';
import { PreferenceManager } from '../preference-manager/preference-manager.service';
import { getOldProof } from '../repositories/proof/old-proof-adapter';
Expand All @@ -21,50 +20,41 @@ const { Device } = Plugins;
providedIn: 'root',
})
export class MigrationService {
private readonly _hasMigrated$ = new BehaviorSubject(false);
readonly hasMigrated$ = this._hasMigrated$
.asObservable()
.pipe(distinctUntilChanged());
private readonly preferences = this.preferenceManager.getPreferences(
MigrationService.name
);

constructor(
private readonly dialog: MatDialog,
private readonly diaBackendAssetRepository: DiaBackendAssetRepository,
private readonly networkService: NetworkService,
private readonly proofRepository: ProofRepository,
private readonly preferenceManager: PreferenceManager,
private readonly onboardingService: OnboardingService
) {}

migrate$(skip?: boolean) {
const runMigrate$ = defer(() => this.preMigrate(skip)).pipe(
concatMap(() => this.runMigrateWithProgressDialog(skip)),
concatMap(() => this.postMigrate())
const runMigrate$ = defer(() =>
this.runMigrateWithProgressDialog(skip)
).pipe(
concatMap(() => this.preferences.setBoolean(PrefKeys.TO_0_15_0, true)),
concatMap(() => this.updatePreviousVersion())
);
return defer(() =>
this.preferences.getBoolean(PrefKeys.TO_0_15_0, false)
).pipe(concatMap(hasMigrated => (hasMigrated ? VOID$ : runMigrate$)));
}

private async preMigrate(skip?: boolean) {
if (
!skip &&
!(await this.onboardingService.hasPrefetchedDiaBackendAssets())
) {
await this.onboardingService.setHasPrefetchedDiaBackendAssets(true);
}
}

private async postMigrate() {
await this.preferences.setBoolean(PrefKeys.TO_0_15_0, true);
await this.updatePreviousVersion();
).pipe(
concatMap(hasMigrated => (hasMigrated ? VOID$ : runMigrate$)),
tap(() => this._hasMigrated$.next(true))
);
}

private async runMigrateWithProgressDialog(skip?: boolean) {
if (skip) {
return;
}
if (!(await this.networkService.connected$.pipe(first()).toPromise())) {
throw new Error('No network connection, aborting migration.');
}
const dialogRef = this.dialog.open(MigratingDialogComponent, {
disableClose: true,
data: { progress: 0 },
Expand Down Expand Up @@ -132,6 +122,7 @@ export class MigrationService {
} = await this.diaBackendAssetRepository
.fetchAllOriginallyOwned$(currentOffset, limit)
.toPromise();

if (diaBackendAssets.length === 0) {
break;
}
Expand Down