Skip to content

Commit

Permalink
Merge pull request #357 from e-picsa/ft/show-prompt-of-update
Browse files Browse the repository at this point in the history
Feat: show play update prompt
  • Loading branch information
chrismclarke authored Mar 4, 2025
2 parents de4a878 + 5189d64 commit e0848ad
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
4 changes: 2 additions & 2 deletions apps/picsa-apps/extension-app-native/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "io.picsa.extension"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3052001
versionName "3.52.1"
versionCode 3053000
versionName "3.53.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
21 changes: 14 additions & 7 deletions apps/picsa-apps/extension-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AnalyticsService } from '@picsa/shared/services/core/analytics.service'
import { CrashlyticsService } from '@picsa/shared/services/core/crashlytics.service';
import { PerformanceService } from '@picsa/shared/services/core/performance.service';
import { PicsaPushNotificationService } from '@picsa/shared/services/core/push-notifications.service';
import { AppUpdateService } from '@picsa/shared/services/native/app-update';
import { _wait } from '@picsa/utils';

@Component({
Expand All @@ -30,6 +31,7 @@ export class AppComponent implements OnInit {
private resourcesService: ResourcesToolService,
private monitoringService: MonitoringToolService,
private migrationService: PicsaMigrationService,
private appUpdateService: AppUpdateService,
private pushNotificationService: PicsaPushNotificationService,
private injector: Injector
) {}
Expand All @@ -42,20 +44,25 @@ export class AppComponent implements OnInit {
// ensure service initialisation only occurs after migrations complete
// and UI has chance to update
await _wait(50);
this.performanceService.init();
this.crashlyticsService.ready();

// eagerly enable analytics collection
this.analyticsService.init(this.router);
// eagerly load resources service to populate hardcoded resources
this.resourcesService.ready();
// eagerly load monitoring service to sync form data
this.monitoringService.ready();
// delay push notification as will prompt for permissions
setTimeout(() => {
if (Capacitor.isNativePlatform()) {
this.ready.set(true);

if (Capacitor.isNativePlatform()) {
this.performanceService.init();
this.crashlyticsService.ready();
// check for available updates
this.appUpdateService.checkForUpdates();
// delay push notification as will prompt for permissions
setTimeout(() => {
this.pushNotificationService.initializePushNotifications();
}
}, 1000);
}, 1000);
}
}

private async runMigrations() {
Expand Down
2 changes: 1 addition & 1 deletion libs/environments/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import packageJson from '../../../package.json';
export const APP_VERSION = {
/** Semver code for current app version, e.g. 3.26.0 */
semver: packageJson.version,
date: '2025-02-28',
date: '2025-03-04',
};
36 changes: 36 additions & 0 deletions libs/shared/src/services/native/app-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { AppUpdate, AppUpdateAvailability, AppUpdateInfo } from '@capawesome/capacitor-app-update';

@Injectable({
providedIn: 'root',
})
export class AppUpdateService {
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor() {}

/** Checks for app updates and starts a flexible update if allowed */
async checkForUpdates() {
try {
const appUpdateInfo: AppUpdateInfo = await AppUpdate.getAppUpdateInfo();
if (
appUpdateInfo.updateAvailability === AppUpdateAvailability.UPDATE_AVAILABLE &&
appUpdateInfo.flexibleUpdateAllowed
) {
await this.startFlexibleUpdate();
}
} catch (error) {
console.error('Error checking for updates:', error);
}
}

/** Starts a flexible update process */
private async startFlexibleUpdate() {
try {
await AppUpdate.startFlexibleUpdate();
// Complete the update once it's downloaded
await AppUpdate.completeFlexibleUpdate();
} catch (error) {
console.error('Error during flexible update:', error);
}
}
}
1 change: 1 addition & 0 deletions libs/shared/src/services/native/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// NOTE - to use these service must import PicsaNativeModule in app root with forRoot call

export * from './app-update';
export * from './print';
export * from './storage-service';
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picsa-apps",
"version": "3.52.1",
"version": "3.53.0",
"license": "See LICENSE",
"scripts": {
"ng": "nx",
Expand Down Expand Up @@ -79,6 +79,7 @@
"@capacitor/push-notifications": "^6.0.4",
"@capacitor/screen-orientation": "^6.0.3",
"@capacitor/share": "^6.0.3",
"@capawesome/capacitor-app-update": "^6.1.0",
"@ngx-translate/core": "~16.0.4",
"@ngx-translate/http-loader": "~16.0.1",
"@nx/angular": "20.3.0",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,15 @@ __metadata:
languageName: node
linkType: hard

"@capawesome/capacitor-app-update@npm:^6.1.0":
version: 6.1.0
resolution: "@capawesome/capacitor-app-update@npm:6.1.0"
peerDependencies:
"@capacitor/core": ^6.0.0
checksum: 10c0/409f258d0fca4920cdb2ba6cb954fd36304f66eaf5c0afa3bc13115c1cec65c616e65ac332847fa5a9a23051f8bacd1343dac4c8bc24a256e2b7fce2fd63b95a
languageName: node
linkType: hard

"@colors/colors@npm:1.5.0":
version: 1.5.0
resolution: "@colors/colors@npm:1.5.0"
Expand Down Expand Up @@ -19841,6 +19850,7 @@ __metadata:
"@capacitor/push-notifications": "npm:^6.0.4"
"@capacitor/screen-orientation": "npm:^6.0.3"
"@capacitor/share": "npm:^6.0.3"
"@capawesome/capacitor-app-update": "npm:^6.1.0"
"@ngx-translate/core": "npm:~16.0.4"
"@ngx-translate/http-loader": "npm:~16.0.1"
"@nx/angular": "npm:20.3.0"
Expand Down

0 comments on commit e0848ad

Please sign in to comment.