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AAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;gBACnF,YAAY;YACd,CAAC,CAAC;KACP,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { asArray, executeAppBuilder, log } from \"builder-util\"\nimport { CONCURRENCY, copyDir, DO_NOT_USE_HARD_LINKS, statOrNull, unlinkIfExists } from \"builder-util/out/fs\"\nimport { emptyDir, readdir, rename } from \"fs-extra\"\nimport * as path from \"path\"\nimport { Configuration } from \"../configuration\"\nimport { BeforeCopyExtraFilesOptions, Framework, PrepareApplicationStageDirectoryOptions } from \"../Framework\"\nimport { Packager, Platform } from \"../index\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport MacPackager from \"../macPackager\"\nimport { getTemplatePath } from \"../util/pathManager\"\nimport { createMacApp } from \"./electronMac\"\nimport { computeElectronVersion, getElectronVersionFromInstalled } from \"./electronVersion\"\nimport * as fs from \"fs/promises\"\nimport injectFFMPEG from \"./injectFFMPEG\"\n\nexport type ElectronPlatformName = \"darwin\" | \"linux\" | \"win32\" | \"mas\"\n\n/**\n * Electron distributables branding options.\n * @see [Electron BRANDING.json](https://github.com/electron/electron/blob/master/shell/app/BRANDING.json).\n */\nexport interface ElectronBrandingOptions {\n projectName?: string\n productName?: string\n}\n\nexport function createBrandingOpts(opts: Configuration): Required {\n return {\n projectName: opts.electronBranding?.projectName || \"electron\",\n productName: opts.electronBranding?.productName || \"Electron\",\n }\n}\n\nexport interface ElectronDownloadOptions {\n // https://github.com/electron-userland/electron-builder/issues/3077\n // must be optional\n version?: string\n\n /**\n * The [cache location](https://github.com/electron-userland/electron-download#cache-location).\n */\n cache?: string | null\n\n /**\n * The mirror.\n */\n mirror?: string | null\n\n /** @private */\n customDir?: string | null\n /** @private */\n customFilename?: string | null\n\n strictSSL?: boolean\n isVerifyChecksum?: boolean\n\n platform?: ElectronPlatformName\n arch?: string\n}\n\nfunction createDownloadOpts(opts: Configuration, platform: ElectronPlatformName, arch: string, electronVersion: string): ElectronDownloadOptions {\n return {\n platform,\n arch,\n version: electronVersion,\n ...opts.electronDownload,\n }\n}\n\nasync function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {\n const { appOutDir, packager } = options\n const electronBranding = createBrandingOpts(packager.config)\n if (packager.platform === Platform.LINUX) {\n const linuxPackager = packager as LinuxPackager\n const executable = path.join(appOutDir, linuxPackager.executableName)\n await rename(path.join(appOutDir, electronBranding.projectName), executable)\n } else if (packager.platform === Platform.WINDOWS) {\n const executable = path.join(appOutDir, `${packager.appInfo.productFilename}.exe`)\n await rename(path.join(appOutDir, `${electronBranding.projectName}.exe`), executable)\n } else {\n await createMacApp(packager as MacPackager, appOutDir, options.asarIntegrity, (options.platformName as ElectronPlatformName) === \"mas\")\n }\n await removeUnusedLanguagesIfNeeded(options)\n}\n\nasync function removeUnusedLanguagesIfNeeded(options: BeforeCopyExtraFilesOptions) {\n const {\n packager: { config, platformSpecificBuildOptions },\n } = options\n const wantedLanguages = asArray(platformSpecificBuildOptions.electronLanguages || config.electronLanguages)\n if (!wantedLanguages.length) {\n return\n }\n\n const { dir, langFileExt } = getLocalesConfig(options)\n // noinspection SpellCheckingInspection\n await BluebirdPromise.map(\n readdir(dir),\n file => {\n if (!file.endsWith(langFileExt)) {\n return\n }\n\n const language = file.substring(0, file.length - langFileExt.length)\n if (!wantedLanguages.includes(language)) {\n return fs.rm(path.join(dir, file), { recursive: true, force: true })\n }\n return\n },\n CONCURRENCY\n )\n\n function getLocalesConfig(options: BeforeCopyExtraFilesOptions) {\n const { appOutDir, packager } = options\n if (packager.platform === Platform.MAC) {\n return { dir: packager.getResourcesDir(appOutDir), langFileExt: \".lproj\" }\n } else {\n return { dir: path.join(packager.getResourcesDir(appOutDir), \"..\", \"locales\"), langFileExt: \".pak\" }\n }\n }\n}\n\nclass ElectronFramework implements Framework {\n // noinspection JSUnusedGlobalSymbols\n readonly macOsDefaultTargets = [\"zip\", \"dmg\"]\n // noinspection JSUnusedGlobalSymbols\n readonly defaultAppIdPrefix = \"com.electron.\"\n // noinspection JSUnusedGlobalSymbols\n readonly isCopyElevateHelper = true\n // noinspection JSUnusedGlobalSymbols\n readonly isNpmRebuildRequired = true\n\n constructor(readonly name: string, readonly version: string, readonly distMacOsAppName: string) {}\n\n getDefaultIcon(platform: Platform) {\n if (platform === Platform.LINUX) {\n return path.join(getTemplatePath(\"icons\"), \"electron-linux\")\n } else {\n // default icon is embedded into app skeleton\n return null\n }\n }\n\n async prepareApplicationStageDirectory(options: PrepareApplicationStageDirectoryOptions) {\n await unpack(options, createDownloadOpts(options.packager.config, options.platformName, options.arch, this.version), this.distMacOsAppName)\n if (options.packager.config.downloadAlternateFFmpeg) {\n await injectFFMPEG(options, this.version)\n }\n }\n\n beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {\n return beforeCopyExtraFiles(options)\n }\n}\n\nexport async function createElectronFrameworkSupport(configuration: Configuration, packager: Packager): Promise {\n let version = configuration.electronVersion\n if (version == null) {\n // for prepacked app asar no dev deps in the app.asar\n if (packager.isPrepackedAppAsar) {\n version = await getElectronVersionFromInstalled(packager.projectDir)\n if (version == null) {\n throw new Error(`Cannot compute electron version for prepacked asar`)\n }\n } else {\n version = await computeElectronVersion(packager.projectDir)\n }\n configuration.electronVersion = version\n }\n\n const branding = createBrandingOpts(configuration)\n return new ElectronFramework(branding.projectName, version, `${branding.productName}.app`)\n}\n\nasync function unpack(prepareOptions: PrepareApplicationStageDirectoryOptions, options: ElectronDownloadOptions, distMacOsAppName: string) {\n const { packager, appOutDir, platformName } = prepareOptions\n\n const electronDist = packager.config.electronDist\n let dist: string | undefined | null = typeof electronDist === \"function\" ? electronDist(prepareOptions) : electronDist\n if (dist != null) {\n const zipFile = `electron-v${options.version}-${platformName}-${options.arch}.zip`\n const resolvedDist = path.isAbsolute(dist) ? dist : path.resolve(packager.projectDir, dist)\n if ((await statOrNull(path.join(resolvedDist, zipFile))) != null) {\n log.info({ resolvedDist, zipFile }, \"resolved electronDist\")\n options.cache = resolvedDist\n dist = null\n }\n }\n\n let isFullCleanup = false\n if (dist == null) {\n await executeAppBuilder([\"unpack-electron\", \"--configuration\", JSON.stringify([options]), \"--output\", appOutDir, \"--distMacOsAppName\", distMacOsAppName])\n } else {\n isFullCleanup = true\n const source = packager.getElectronSrcDir(dist)\n const destination = packager.getElectronDestinationDir(appOutDir)\n log.info({ source, destination }, \"copying Electron\")\n await emptyDir(appOutDir)\n await copyDir(source, destination, {\n isUseHardLink: DO_NOT_USE_HARD_LINKS,\n })\n }\n\n await cleanupAfterUnpack(prepareOptions, distMacOsAppName, isFullCleanup)\n}\n\nfunction cleanupAfterUnpack(prepareOptions: PrepareApplicationStageDirectoryOptions, distMacOsAppName: string, isFullCleanup: boolean) {\n const out = prepareOptions.appOutDir\n const isMac = prepareOptions.packager.platform === Platform.MAC\n const resourcesPath = isMac ? path.join(out, distMacOsAppName, \"Contents\", \"Resources\") : path.join(out, \"resources\")\n\n return Promise.all([\n isFullCleanup ? unlinkIfExists(path.join(resourcesPath, \"default_app.asar\")) : Promise.resolve(),\n isFullCleanup ? unlinkIfExists(path.join(out, \"version\")) : Promise.resolve(),\n isMac\n ? Promise.resolve()\n : rename(path.join(out, \"LICENSE\"), path.join(out, \"LICENSE.electron.txt\")).catch(() => {\n /* ignore */\n }),\n ])\n}\n"]}