본문 바로가기

이벤트

GitHub

Capacitor Updater 플러그인은 업데이트 프로세스를 모니터링하고 다양한 상태에 대응할 수 있도록 여러 이벤트를 제공합니다.

이벤트 리스너 설정

“Event Listener Setup” 섹션

이벤트를 수신하려면 다음 addListener 메서드를 CapacitorUpdater 객체에서 호출하세요:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Add a listener
const listener = await CapacitorUpdater.addListener('eventName', (event) => {
// Handle the event
});
// Remove the listener when no longer needed
listener.remove();
// Remove all listeners
await CapacitorUpdater.removeAllListeners();

사용 가능한 이벤트

“Available Events” 섹션

bundle 다운로드 중에 발생합니다. 다운로드 진행 상황 정보를 제공합니다.

CapacitorUpdater.addListener('download', (event) => {
console.log(`Download progress: ${event.percent}%`);
console.log('Bundle info:', event.bundle);
});

이벤트 데이터:

  • percent: number - 다운로드 진행률 백분율 (0-100)
  • bundle: BundleInfo - 다운로드 중인 번들에 대한 정보

업데이트 확인 결과 업데이트가 필요하지 않을 때 발생합니다.

CapacitorUpdater.addListener('noNeedUpdate', (event) => {
console.log('App is up to date');
console.log('Current bundle:', event.bundle);
});

이벤트 데이터:

  • bundle: 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 - 사용 가능한 업데이트 번들에 대한 정보

번들 다운로드가 성공적으로 완료되었을 때 발생합니다.

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 - 다운로드된 번들에 대한 정보

메이저 업데이트가 사용 가능하지만 자동 업데이트 설정으로 인해 차단되었을 때 발생합니다.

CapacitorUpdater.addListener('majorAvailable', (event) => {
console.log('Major update available:', event.version);
// Notify user about major update
});

이벤트 데이터:

  • version: string - 메이저 업데이트의 버전 번호

다음 앱 시작 시 업데이트 설치에 실패하면 발생합니다.

CapacitorUpdater.addListener('updateFailed', (event) => {
console.error('Update failed to install');
console.log('Failed bundle:', event.bundle);
// Handle rollback or retry logic
});

이벤트 데이터:

  • bundle: BundleInfo - 설치에 실패한 번들에 대한 정보

번들 다운로드가 실패하면 발생합니다.

CapacitorUpdater.addListener('downloadFailed', (event) => {
console.error('Download failed for version:', event.version);
// Handle download retry logic
});

이벤트 데이터:

  • version: string - 다운로드에 실패한 버전

앱이 다시 로드되었을 때 발생합니다.

CapacitorUpdater.addListener('appReloaded', () => {
console.log('App has been reloaded');
// Perform any necessary reinitialization
});

이벤트 데이터: 없음

업데이트 후 앱을 사용할 준비가 되면 발생합니다.

CapacitorUpdater.addListener('appReady', (event) => {
console.log('App is ready');
console.log('Current bundle:', event.bundle);
console.log('Status:', event.status);
});

이벤트 데이터:

  • bundle: BundleInfo - 현재 번들에 대한 정보
  • status: string - 준비 완료 상태

많은 이벤트에 다음 속성을 포함하는 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
}

Where BundleStatus 값:

  • 'success' - Bundle 다운로드 완료
  • 'error' - Bundle 다운로드/설치 실패
  • '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
}
}
  1. 항상 호출하세요 notifyAppReady(): auto-update 사용 시 롤백을 방지하려면 앱 초기화 후 반드시 이 메서드를 호출하세요.

  2. 실패를 우아하게 처리하기: download 및 update 실패 시 적절한 에러 핸들링을 구현하세요.

  3. 사용자 피드백 제공하기: download progress 이벤트를 사용하여 사용자에게 업데이트 진행 상황을 보여주세요.

  4. 리스너 정리하기: 메모리 누수를 방지하려면 더 이상 필요하지 않은 이벤트 리스너를 제거하세요.

  5. 업데이트 시나리오 테스트: 실패, 롤백, 메이저 업데이트를 포함한 다양한 업데이트 시나리오를 테스트하세요.

사용 중이라면 이벤트 네이티브 플러그인 작업을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-updater 사용하기 네이티브 기능의 경우 @capgo/capacitor-updater 사용하기에서, Capgo 플러그인 디렉토리 Capgo Plugin Directory의 제품 워크플로우에 맞춰, Capgo의 Capacitor 플러그인 Capgo의 Capacitor 플러그인 구현 상세 내용에 대해서는, 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트 구현 상세 내용에 대해서는, Ionic Enterprise 플러그인 대안 Ionic Enterprise 플러그인 대안의 제품 워크플로우에 대해서는.