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kBAAkB,GAAG,sBAAsB,IAAI,IAA1B,GAAiC,IAAjC,GAAwC,sBAAsB,CAAC,kBAA1F;;AACA,QAAI,aAAa,IAAI,IAAjB,IAAyB,kBAAkB,IAAI,IAAnD,EAAyD;AACvD,WAAK,aAAL,CAAmB,IAAI,KAAJ,CAAU,mDAAV,CAAnB;AACA,aAAO,KAAP;AACD,KAZ0D,CAc3D;;;AACA,SAAK,oBAAL,GAA4B,IAA5B;;AAEA,QAAI;AACF,WAAK,OAAL,CAAa,IAAb,CAAkB,sBAAsB,QAAQ,sBAAsB,eAAe,EAArF;;AACA,aAAO,KAAK,SAAL,CAAe;AACpB,QAAA,aADoB;AAEpB,QAAA,QAFoB;AAGpB,QAAA,eAHoB;AAIpB,QAAA,qBAAqB,EAAE,kBAAkB,CAAC;AAJtB,OAAf,CAAP;AAMD,KARD,CASA,OAAO,CAAP,EAAU;AACR,WAAK,aAAL,CAAmB,CAAnB;AACA,aAAO,KAAP;AACD;AACF;;AAES,EAAA,cAAc,GAAA;AACtB,QAAI,KAAK,gBAAL,IAAyB,CAAC,KAAK,oBAAnC,EAAyD;AACvD;AACD;;AAED,SAAK,gBAAL,GAAwB,IAAxB;AAEA,SAAK,GAAL,CAAS,MAAT,CAAgB,QAAQ,IAAG;AACzB,UAAI,KAAK,oBAAT,EAA+B;AAC7B,aAAK,OAAL,CAAa,IAAb,CAAkB,oEAAlB;;AACA;AACD;;AAED,UAAI,QAAQ,KAAK,CAAjB,EAAoB;AAClB,aAAK,OAAL,CAAa,IAAb,CAAkB,uFAAuF,QAAQ,EAAjH;;AACA;AACD;;AAED,WAAK,OAAL,CAAa,IAAb,CAAkB,6BAAlB;;AACA,WAAK,OAAL,CAAa,IAAb,EAAmB,KAAnB;AACD,KAbD;AAcD;;AAxFiD,C","sourcesContent":["import { AllPublishOptions } from \"builder-util-runtime\"\nimport { AppAdapter } from \"./AppAdapter\"\nimport { AppUpdater, DownloadExecutorTask } from \"./AppUpdater\"\n\nexport abstract class BaseUpdater extends AppUpdater {\n protected quitAndInstallCalled = false\n private quitHandlerAdded = false\n\n protected constructor(options?: AllPublishOptions | null, app?: AppAdapter) {\n super(options, app)\n }\n\n quitAndInstall(isSilent = false, isForceRunAfter = false): void {\n this._logger.info(`Install on explicit quitAndInstall`)\n const isInstalled = this.install(isSilent, isSilent ? isForceRunAfter : true)\n if (isInstalled) {\n setImmediate(() => {\n this.app.quit()\n })\n }\n else {\n this.quitAndInstallCalled = false\n }\n }\n\n protected executeDownload(taskOptions: DownloadExecutorTask): Promise<Array<string>> {\n return super.executeDownload({\n ...taskOptions,\n done: async event => {\n this.dispatchUpdateDownloaded(event)\n this.addQuitHandler()\n }\n })\n }\n\n // must be sync\n protected abstract doInstall(options: InstallOptions): boolean\n\n // must be sync (because quit even handler is not async)\n protected install(isSilent: boolean, isForceRunAfter: boolean): boolean {\n if (this.quitAndInstallCalled) {\n this._logger.warn(\"install call ignored: quitAndInstallCalled is set to true\")\n return false\n }\n\n const downloadedUpdateHelper = this.downloadedUpdateHelper\n const installerPath = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.file\n const downloadedFileInfo = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.downloadedFileInfo\n if (installerPath == null || downloadedFileInfo == null) {\n this.dispatchError(new Error(\"No valid update available, can't quit and install\"))\n return false\n }\n\n // prevent calling several times\n this.quitAndInstallCalled = true\n\n try {\n this._logger.info(`Install: isSilent: ${isSilent}, isForceRunAfter: ${isForceRunAfter}`)\n return this.doInstall({\n installerPath,\n isSilent,\n isForceRunAfter,\n isAdminRightsRequired: downloadedFileInfo.isAdminRightsRequired,\n })\n }\n catch (e) {\n this.dispatchError(e)\n return false\n }\n }\n\n protected addQuitHandler(): void {\n if (this.quitHandlerAdded || !this.autoInstallOnAppQuit) {\n return\n }\n\n this.quitHandlerAdded = true\n\n this.app.onQuit(exitCode => {\n if (this.quitAndInstallCalled) {\n this._logger.info(\"Update installer has already been triggered. Quitting application.\")\n return\n }\n\n if (exitCode !== 0) {\n this._logger.info(`Update will be not installed on quit because application is quitting with exit code ${exitCode}`)\n return\n }\n\n this._logger.info(\"Auto install update on quit\")\n this.install(true, false)\n })\n }\n}\n\nexport interface InstallOptions {\n readonly installerPath: string\n readonly isSilent: boolean\n readonly isForceRunAfter: boolean\n readonly isAdminRightsRequired: boolean\n}"],"sourceRoot":""}