イベント
このプラグインのインストール手順とフルマークダウンガイドを含むセットアップコマンドをコピーしてください。
The Capacitor Updater plugin provides several events you can listen to for monitoring the update process and responding to different states.
The __CAPGO_KEEP_0__ Updater plugin provides several events you can listen to for monitoring the update process and responding to different states.
イベントリスナーセットアップイベントを聞くには、 addListener メソッドを使用します。 CapacitorUpdater オブジェクト:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Add a listenerconst listener = await CapacitorUpdater.addListener('eventName', (event) => { // Handle the event});
// Remove the listener when no longer neededlistener.remove();
// Remove all listenersawait CapacitorUpdater.removeAllListeners();利用可能なイベント
利用可能なイベントdownload
ダウンロードバンドルダウンロードプロセス中に発生します。ダウンロードの進行状況情報を提供します。
CapacitorUpdater.addListener('download', (event) => { console.log(`Download progress: ${event.percent}%`); console.log('Bundle info:', event.bundle);});イベントデータ:
percent:数値 - ダウンロードの進行状況パーセンテージ(0-100)bundle: BundleInfo -
noNeedUpdate
「noNeedUpdate」Fired when a check for updates determines that no update is needed.
CapacitorUpdater.addListener('noNeedUpdate', (event) => { console.log('App is up to date'); console.log('Current bundle:', event.bundle);});Event Data:
bundleクリップボードにコピー
updateAvailable
Event Data:: BundleInfo -
CapacitorUpdater.addListener('updateAvailable', (event) => { console.log('Update available'); console.log('New bundle:', event.bundle); // You can trigger a download here if needed});イベントデータ:
bundle: BundleInfo - ダウンロード可能なアップデートバンドルの情報
downloadComplete
セクション「ダウンロード完了」バンドルのダウンロードが正常に完了したときに発火します。
CapacitorUpdater.addListener('downloadComplete', (event) => { console.log('Download completed'); console.log('Downloaded bundle:', event.bundle); // You might want to set this bundle as next});イベントデータ:
bundle: BundleInfo - ダウンロードしたバンドルの情報
majorAvailable
セクション「メジャーアップデートあり」メジャーアップデートが利用可能ですが、自動アップデート設定によってブロックされています。
CapacitorUpdater.addListener('majorAvailable', (event) => { console.log('Major update available:', event.version); // Notify user about major update});イベントデータ:
version: string - メジャーアップデートのバージョン番号
updateFailed
updateFailedupdateFailed
CapacitorUpdater.addListener('updateFailed', (event) => { console.error('Update failed to install'); console.log('Failed bundle:', event.bundle); // Handle rollback or retry logic});イベントデータ:
bundleBundleInfo - インストールに失敗したバンドルの情報
downloadFailed
downloadFaileddownloadFailed
CapacitorUpdater.addListener('downloadFailed', (event) => { console.error('Download failed for version:', event.version); // Handle download retry logic});イベントデータ:
version: __CAPGO_KEEP_0__ - __CAPGO_KEEP_0__ がダウンロードに失敗したバージョン
appReloaded
「アプリ再読み込み」アプリが再読み込みされたときに発火します。
CapacitorUpdater.addListener('appReloaded', () => { console.log('App has been reloaded'); // Perform any necessary reinitialization});イベントデータ: なし
appReady
「アプリ利用可能」アプリが更新後に利用可能になったときに発火します。
CapacitorUpdater.addListener('appReady', (event) => { console.log('App is ready'); console.log('Current bundle:', event.bundle); console.log('Status:', event.status);});イベントデータ:
bundle: __CAPGO_KEEP_0__ - 現在のバンドルに関する情報status: __CAPGO_KEEP_0__ - アプリが利用可能な状態
BundleInfo オブジェクト
「BundleInfo オブジェクト」セクション多くのイベントには、 BundleInfo 以下のプロパティを持つオブジェクトが含まれています:
interface BundleInfo { id: string; // Unique bundle identifier version: string; // Bundle version downloaded: string; // Download timestamp checksum?: string; // Bundle checksum (if available) status: BundleStatus; // Bundle status}「」の場所 BundleStatus 「」の場所は次のとおりです:
'success'- Bundle のダウンロードが正常に完了しました'error'- ダウンロード/インストールが失敗しました'pending'- 次に設定するBundleが準備中です'downloading'- Bundleが現在ダウンロード中です
例:完全なアップデートフロー
セクションのタイトル:例:完全なアップデートフローイベントを使用して、完全なアップデートフローを処理する方法の例です。
import { CapacitorUpdater } from '@capgo/capacitor-updater';
export class UpdateManager { private listeners: any[] = [];
async setupListeners() { // Listen for available updates this.listeners.push( await CapacitorUpdater.addListener('updateAvailable', async (event) => { console.log('Update available:', event.bundle.version); // Auto-download the update await CapacitorUpdater.download({ url: event.bundle.url, version: event.bundle.version }); }) );
// Monitor download progress this.listeners.push( await CapacitorUpdater.addListener('download', (event) => { console.log(`Downloading: ${event.percent}%`); // Update UI progress bar this.updateProgressBar(event.percent); }) );
// Handle download completion this.listeners.push( await CapacitorUpdater.addListener('downloadComplete', async (event) => { console.log('Download complete:', event.bundle.version); // Set as next bundle await CapacitorUpdater.next({ id: event.bundle.id }); }) );
// Handle failures this.listeners.push( await CapacitorUpdater.addListener('downloadFailed', (event) => { console.error('Download failed:', event.version); this.showError('Update download failed. Please try again later.'); }) );
this.listeners.push( await CapacitorUpdater.addListener('updateFailed', (event) => { console.error('Update installation failed:', event.bundle.version); this.showError('Update installation failed. The app has been rolled back.'); }) );
// Handle app ready this.listeners.push( await CapacitorUpdater.addListener('appReady', async (event) => { console.log('App ready with bundle:', event.bundle.version); }) ); }
cleanup() { // Remove all listeners when no longer needed this.listeners.forEach(listener => listener.remove()); this.listeners = []; }
private updateProgressBar(percent: number) { // Update your UI progress bar }
private showError(message: string) { // Show error to user }}ベストプラクティス
「ベストプラクティス」セクション-
常に呼び出す
notifyAppReady()自動更新を使用する場合、常にアプリケーションが初期化された後、このメソッドを呼び出すことでロールバックを防止します。 -
失敗を柔軟に処理するダウンロードと更新の失敗のための適切なエラーハンドリングを実装します。
-
ユーザーにフィードバックを提供するダウンロードの進行状況イベントを使用して、ユーザーにアップデートの進行状況を表示します。
-
リスナーのクリーンアップイベントリスナを削除することでメモリリークを防止します。
-
テスト更新シナリオ: さまざまな更新シナリオをテストするには、失敗、ロールバック、およびメジャーアップデートを含む。
イベントから続ける
「イベントから続ける」というセクションCapacitor を使用している場合 イベント ネイティブ プラグインの作業を計画する場合、イベントを使用してネイティブ プラグインと接続する Capacitor の @capgo/capacitor-updater を使用 Capacitor の @capgo/capacitor-updater を使用 Capgo プラグイン ディレクトリ Capgo プラグイン ディレクトリ Capacitor プラグイン ( Capgo ) 実装詳細については Capacitor プラグインの Capgo を参照してください。 プラグインの追加または更新 実装詳細についてはプラグインの追加または更新、 Ionic Enterprise プラグインの代替 Ionic Enterprise プラグインの代替の製品ワークフローについてはこちらを参照してください。