이벤트
설치 단계와 이 플러그인의 전체 마크다운 가이드를 포함한 설정 지시를 복사할 수 있습니다.
Capacitor 업데이터 플러그인은 업데이트 프로세스를 모니터링하고 다양한 상태에 대응하기 위해 이벤트를 듣는 데 사용할 수 있는 여러 이벤트를 제공합니다.
이벤트 리스너 설정
이벤트 리스너 설정이벤트를 듣기 위해 사용하는 방법은 객체의 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
제목 ‘업데이트가 필요하지 않습니다’업데이트 확인이 필요하지 않음을 결정할 때 발생합니다.
CapacitorUpdater.addListener('noNeedUpdate', (event) => { console.log('App is up to date'); console.log('Current bundle:', event.bundle);});이벤트 데이터:
bundle: BundleInfo - 현재 번들에 대한 정보
updateAvailable
업데이트가 다운로드 가능합니다.업데이트가 다운로드 가능합니다.
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
업데이트 실패앱이 다음 시작 시 설치에 실패한 업데이트에 대한 정보를 전달합니다.
CapacitorUpdater.addListener('updateFailed', (event) => { console.error('Update failed to install'); console.log('Failed bundle:', event.bundle); // Handle rollback or retry logic});이벤트 데이터:
bundle: BundleInfo - 설치에 실패한 부ंडल에 대한 정보
downloadFailed
다운로드 실패__CAPGO_KEEP_0__ 발생 시에 호출됩니다.
CapacitorUpdater.addListener('downloadFailed', (event) => { console.error('Download failed for version:', event.version); // Handle download retry logic});__CAPGO_KEEP_2__:
version: string - 다운로드에 실패한 __CAPGO_KEEP_0__ 버전
appReloaded
__CAPGO_KEEP_3__ 제목 ‘appReloaded’__CAPGO_KEEP_0__이 재로드되었습니다.
CapacitorUpdater.addListener('appReloaded', () => { console.log('App has been reloaded'); // Perform any necessary reinitialization});__CAPGO_KEEP_2__: : None
appReady
__CAPGO_KEEP_3__ 제목 ‘appReady’__CAPGO_KEEP_0__이 업데이트 후 사용할 준비가되었습니다.
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 객체
많은 이벤트는 다음 속성을 포함하는 객체를 포함합니다.클립보드에 복사 BundleInfo __CAPGO_KEEP_0__
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'- 다운로드가 성공적으로 완료되었습니다.'error'- 다운로드/설치가 실패했습니다.'pending'- 다음으로 설정될 예정인 패키지가 있습니다.'downloading'- 현재 다운로드 중인 패키지가 있습니다.
예시: 완전한 업데이트의 흐름
제목: 예시: 완전한 업데이트의 흐름이벤트를 처리하는 완전한 업데이트의 흐름 예시입니다.
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 }}Section titled “Best Practices”
Always call-
자동 업데이트 시 항상 앱 초기화 후 이 메서드를 호출하여 롤백을 방지하세요.
notifyAppReady()Handle failures gracefully -
다운로드 및 업데이트 실패 시 적절한 오류 처리를 구현하세요.Provide user feedback
-
사용자에게 피드백을 제공하세요.: 사용자에게 업데이트 진행률을 보여주기 위해 다운로드 진행 이벤트를 사용하세요.
-
리스너 정리: 사용자가 더 이상 필요하지 않은 이벤트 리스너를 제거하여 메모리 누수를 방지하세요.
-
업데이트 시나리오 테스트: 실패, 롤백 및 주요 업데이트와 같은 다양한 업데이트 시나리오를 테스트하세요.
이벤트에서 계속
이벤트에서 계속이러한 기능을 사용하고 있다면 이벤트 네이티브 플러그인 작업을 계획하고 있습니다. 이를 @capgo/capacitor-업데이트 사용하여 네이티브 기능과 연결하세요. @capgo/capacitor-업데이터를 사용하여 Capgo 플러그인 디렉토리 Capgo 플러그인 디렉토리에서 제품 워크플로우를 위해 Capacitor 플러그인들에 의해 Capgo Capacitor 플러그인들에 의해 Capgo에서 구현 세부 정보를 위해 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트 구현 세부 정보를 위해, 그리고 아이오닉 엔터프라이즈 플러그인 대체 아이오닉 엔터프라이즈 플러그인 대체 제품 워크플로우를 위해