UNPKG

4.92 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.LibUiFramework = void 0;
4const fs_extra_1 = require("fs-extra");
5const promises_1 = require("fs/promises");
6const path = require("path");
7const builder_util_1 = require("builder-util");
8const core_1 = require("../core");
9const appBuilder_1 = require("../util/appBuilder");
10class LibUiFramework {
11 constructor(version, distMacOsAppName, isUseLaunchUi) {
12 this.version = version;
13 this.distMacOsAppName = distMacOsAppName;
14 this.isUseLaunchUi = isUseLaunchUi;
15 this.name = "libui";
16 // noinspection JSUnusedGlobalSymbols
17 this.macOsDefaultTargets = ["dmg"];
18 this.defaultAppIdPrefix = "com.libui.";
19 // noinspection JSUnusedGlobalSymbols
20 this.isCopyElevateHelper = false;
21 // noinspection JSUnusedGlobalSymbols
22 this.isNpmRebuildRequired = false;
23 }
24 async prepareApplicationStageDirectory(options) {
25 await (0, fs_extra_1.emptyDir)(options.appOutDir);
26 const packager = options.packager;
27 const platform = packager.platform;
28 if (this.isUseLaunchUiForPlatform(platform)) {
29 const appOutDir = options.appOutDir;
30 await (0, builder_util_1.executeAppBuilder)([
31 "proton-native",
32 "--node-version",
33 this.version,
34 "--use-launch-ui",
35 "--platform",
36 platform.nodeName,
37 "--arch",
38 options.arch,
39 "--stage",
40 appOutDir,
41 "--executable",
42 `${packager.appInfo.productFilename}${platform === core_1.Platform.WINDOWS ? ".exe" : ""}`,
43 ]);
44 return;
45 }
46 if (platform === core_1.Platform.MAC) {
47 await this.prepareMacosApplicationStageDirectory(packager, options);
48 }
49 else if (platform === core_1.Platform.LINUX) {
50 await this.prepareLinuxApplicationStageDirectory(options);
51 }
52 }
53 async prepareMacosApplicationStageDirectory(packager, options) {
54 const appContentsDir = path.join(options.appOutDir, this.distMacOsAppName, "Contents");
55 await (0, promises_1.mkdir)(path.join(appContentsDir, "Resources"), { recursive: true });
56 await (0, promises_1.mkdir)(path.join(appContentsDir, "MacOS"), { recursive: true });
57 await (0, builder_util_1.executeAppBuilder)(["proton-native", "--node-version", this.version, "--platform", "darwin", "--stage", path.join(appContentsDir, "MacOS")]);
58 const appPlist = {
59 // https://github.com/albe-rosado/create-proton-app/issues/13
60 NSHighResolutionCapable: true,
61 };
62 await packager.applyCommonInfo(appPlist, appContentsDir);
63 await Promise.all([
64 (0, appBuilder_1.executeAppBuilderAndWriteJson)(["encode-plist"], { [path.join(appContentsDir, "Info.plist")]: appPlist }),
65 writeExecutableMain(path.join(appContentsDir, "MacOS", appPlist.CFBundleExecutable), `#!/bin/sh
66 DIR=$(dirname "$0")
67 "$DIR/node" "$DIR/../Resources/app/${options.packager.info.metadata.main || "index.js"}"
68 `),
69 ]);
70 }
71 async prepareLinuxApplicationStageDirectory(options) {
72 const appOutDir = options.appOutDir;
73 await (0, builder_util_1.executeAppBuilder)(["proton-native", "--node-version", this.version, "--platform", "linux", "--arch", options.arch, "--stage", appOutDir]);
74 const mainPath = path.join(appOutDir, options.packager.executableName);
75 await writeExecutableMain(mainPath, `#!/bin/sh
76 DIR=$(dirname "$0")
77 "$DIR/node" "$DIR/app/${options.packager.info.metadata.main || "index.js"}"
78 `);
79 }
80 async afterPack(context) {
81 const packager = context.packager;
82 if (!this.isUseLaunchUiForPlatform(packager.platform)) {
83 return;
84 }
85 // LaunchUI requires main.js, rename if need
86 const userMain = packager.info.metadata.main || "index.js";
87 if (userMain === "main.js") {
88 return;
89 }
90 await (0, promises_1.rename)(path.join(context.appOutDir, "app", userMain), path.join(context.appOutDir, "app", "main.js"));
91 }
92 getMainFile(platform) {
93 return this.isUseLaunchUiForPlatform(platform) ? "main.js" : null;
94 }
95 isUseLaunchUiForPlatform(platform) {
96 return platform === core_1.Platform.WINDOWS || (this.isUseLaunchUi && platform === core_1.Platform.LINUX);
97 }
98 getExcludedDependencies(platform) {
99 // part of launchui
100 return this.isUseLaunchUiForPlatform(platform) ? ["libui-node"] : null;
101 }
102}
103exports.LibUiFramework = LibUiFramework;
104async function writeExecutableMain(file, content) {
105 await (0, promises_1.writeFile)(file, content, { mode: 0o755 });
106 await (0, promises_1.chmod)(file, 0o755);
107}
108//# sourceMappingURL=LibUiFramework.js.map
\No newline at end of file