Skip to content

Commit

Permalink
only show install alert on first install
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Hill authored and elvece committed Jun 16, 2022
1 parent 016110b commit d878b71
Showing 1 changed file with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class MarketplaceShowControlsComponent {

readonly PackageState = PackageState

loader: HTMLIonLoadingElement | undefined

constructor(
private readonly alertCtrl: AlertController,
public readonly localStorageService: LocalStorageService,
Expand All @@ -62,22 +60,26 @@ export class MarketplaceShowControlsComponent {
}

async tryInstall() {
if (
this.localPkg &&
this.emver.compare(this.localVersion, this.pkg.manifest.version) !== 0 &&
hasCurrentDeps(this.localPkg)
) {
this.dryInstall()
} else {
if (!this.localPkg) {
this.alertInstall()
} else {
if (
this.emver.compare(this.localVersion, this.pkg.manifest.version) !==
0 &&
hasCurrentDeps(this.localPkg)
) {
this.dryInstall()
} else {
this.install()
}
}
}

private async dryInstall() {
this.loader = await this.loadingCtrl.create({
const loader = await this.loadingCtrl.create({
message: 'Checking dependent services...',
})
await this.loader.present()
await loader.present()

const { id, version } = this.pkg.manifest

Expand All @@ -88,11 +90,12 @@ export class MarketplaceShowControlsComponent {
})

if (isEmptyObject(breakages)) {
this.alertInstall()
this.install(loader)
} else {
await loader.dismiss()
const proceed = await this.presentAlertBreakages(breakages)
if (proceed) {
this.alertInstall()
this.install()
}
}
} catch (e: any) {
Expand All @@ -101,8 +104,6 @@ export class MarketplaceShowControlsComponent {
}

private async alertInstall() {
this.dismissLoader()

const installAlert = this.pkg.manifest.alerts.install

if (!installAlert) return this.install()
Expand All @@ -127,13 +128,13 @@ export class MarketplaceShowControlsComponent {
await alert.present()
}

private async install() {
private async install(loader?: HTMLIonLoadingElement) {
const message = 'Beginning Install...'
if (this.loader) {
this.loader.message = message
if (loader) {
loader.message = message
} else {
this.loader = await this.loadingCtrl.create({ message })
await this.loader.present()
loader = await this.loadingCtrl.create({ message })
await loader.present()
}

const { id, version } = this.pkg.manifest
Expand All @@ -149,13 +150,11 @@ export class MarketplaceShowControlsComponent {
} catch (e: any) {
this.errToast.present(e)
} finally {
this.loader.dismiss()
loader.dismiss()
}
}

private async presentAlertBreakages(breakages: Breakages): Promise<boolean> {
await this.dismissLoader()

let message: string | IonicSafeString =
'As a result of this update, the following services will no longer work properly and may crash:<ul>'
const localPkgs = this.patch.getData()['package-data']
Expand Down Expand Up @@ -191,11 +190,4 @@ export class MarketplaceShowControlsComponent {
await alert.present()
})
}

async dismissLoader() {
if (this.loader) {
await this.loader.dismiss()
this.loader = undefined
}
}
}

0 comments on commit d878b71

Please sign in to comment.