@heybox/hb-sdk 0.9.1-alpha.5 → 0.9.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +29 -4
- package/dist/cli-chunks/browser-DS7b1F4w.cjs +15 -0
- package/dist/cli-chunks/{build-D91J_GAa.cjs → build-Blt2jVCf.cjs} +14 -8
- package/dist/cli-chunks/{context-Xdd45FFd.cjs → context-LHhIFnwm.cjs} +12 -12
- package/dist/cli-chunks/{create-BzpdRC5r.cjs → create-BCtecycP.cjs} +12 -5
- package/dist/cli-chunks/{dev-C7acO3Kt.cjs → dev-5yTbdw-i.cjs} +12 -13
- package/dist/cli-chunks/{doctor-BgHRDQmG.cjs → doctor-CnMPJ0xu.cjs} +13 -6
- package/dist/cli-chunks/{index-TQwjvNjL.cjs → index-85kvRV7B.cjs} +10810 -6510
- package/dist/cli-chunks/{index-CjhQXbxy.cjs → index-CCEGxh9a.cjs} +3 -3
- package/dist/cli-chunks/{index.esm-dgqkvowo.cjs → index.esm-B2j8wByD.cjs} +18 -19
- package/dist/cli-chunks/{login-B14iGXHh.cjs → login-BShtjJMm.cjs} +32 -33
- package/dist/cli-chunks/{project-vite-CN6mMjzX.cjs → project-vite-C9OxeWTo.cjs} +1 -1
- package/dist/cli-chunks/{remote-C9RUiZxK.cjs → remote-CKXsKfSJ.cjs} +35 -32
- package/dist/cli-chunks/{runtime-gate-CfAkz0p-.cjs → runtime-gate-MNA7lKMW.cjs} +2 -2
- package/dist/cli-chunks/{runtime-permission-env-L7OfyRcl.cjs → runtime-permission-env-lj-frZ7T.cjs} +3 -2
- package/dist/cli-chunks/{skill-BHTVho1a.cjs → skill-ag7O2U_r.cjs} +14 -7
- package/dist/cli-chunks/{version-C_NaCZ8O.cjs → version-CrnB-YNH.cjs} +1 -1
- package/dist/cli.cjs +14 -6
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-CjvQmKkG.js +102 -0
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-BNF9Yk4P.js → desktop-app-launch-DoA60Rdl.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/{index-DRRtB9Nm.js → index-BDvaA1DV.js} +3 -3
- package/dist/devtools/browser-dev-host/index.html +2 -2
- package/dist/index.cjs.js +80 -2
- package/dist/index.esm.js +80 -2
- package/dist/miniapp-publish.cjs.js +2 -1
- package/dist/miniapp-publish.esm.js +2 -1
- package/dist/protocol.cjs.js +9 -0
- package/dist/protocol.esm.js +9 -1
- package/dist/vite.cjs.js +3 -2
- package/dist/vite.esm.js +3 -2
- package/package.json +4 -4
- package/skill/SKILL.md +15 -0
- package/skill/skill.json +5 -5
- package/types/index.d.ts +85 -1
- package/types/protocol.d.ts +4 -1
- package/dist/cli-chunks/browser-RAy8e8cV.cjs +0 -635
- package/dist/cli-chunks/session-DZrr6RYK.cjs +0 -3404
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-KPFU0Lsa.js +0 -102
package/types/protocol.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MiniProgramEventName, MiniProgramEventPayloadMap, LoginScope as LoginScope$1 } from '@heybox/hb-sdk-protocol';
|
|
2
|
-
export { AUTH_LOGIN_METHOD, AuthorizedUserInfo, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DEVICE_EXECUTE_PROTOCOL_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, DIRECTORY_CREATE_METHOD, DIRECTORY_EXISTS_METHOD, DIRECTORY_LIST_METHOD, DIRECTORY_REMOVE_METHOD, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, DirectoryCreatePayload, DirectoryCreateResult, DirectoryExistsPayload, DirectoryExistsResult, DirectoryListPayload, DirectoryListResult, DirectoryRemovePayload, DirectoryRemoveResult, DownloadProgressPayload, FILES_PICK_DIRECTORY_METHOD, FILES_PICK_FILES_METHOD, FILES_SAVE_FILE_METHOD, FILE_CREATE_METHOD, FILE_EXISTS_METHOD, FILE_READ_BYTES_METHOD, FILE_READ_TEXT_METHOD, FILE_REMOVE_METHOD, FILE_STAT_METHOD, FILE_WRITE_BYTES_METHOD, FILE_WRITE_TEXT_METHOD, FileCreatePayload, FileCreateResult, FileExistsPayload, FileExistsResult, FileReadBytesPayload, FileReadBytesResult, FileReadTextPayload, FileReadTextResult, FileRemovePayload, FileRemoveResult, FileStatPayload, FileStatResult, FileWriteBytesPayload, FileWriteBytesResult, FileWriteTextPayload, FileWriteTextResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetSteamGameListPayload, GetSteamGameListResult, GetStoragePayload, GetStorageResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, HideLoadingPayload, HideLoadingResult, LeaderboardEntry, LeaderboardOrder, LoginPayload, LoginResult, LoginScope, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_OPERATION_PROGRESS_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, MiniProgramAuthMethod, MiniProgramBridgeCancelMessage, MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramBridgeMethod, MiniProgramBridgeProgressMessage, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramDirectDirectoryRef, MiniProgramDirectFileRef, MiniProgramDirectoryDescriptor, MiniProgramDirectoryMethod, MiniProgramDirectoryRef, MiniProgramDisplayState, MiniProgramEventName, MiniProgramEventPayloadMap, MiniProgramFileDescriptor, MiniProgramFileMethod, MiniProgramFileMode, MiniProgramFileRef, MiniProgramFileStat, MiniProgramFileSystemEntityDescriptor, MiniProgramFileSystemEntityRef, MiniProgramFilesMethod, MiniProgramNavigationBarForegroundStyle, MiniProgramNavigationMethod, MiniProgramNetworkHeaders, MiniProgramNetworkMethod, MiniProgramNetworkParams, MiniProgramNetworkRequestMethod, MiniProgramOperatingSystemName, MiniProgramOrientationMode, MiniProgramPathRootRef, MiniProgramRuntimeEnvironmentInfo, MiniProgramRuntimeMode, MiniProgramRuntimePermissionEntry, MiniProgramRuntimePermissionStatus, MiniProgramRuntimePermissionsSnapshot, MiniProgramSafeArea, MiniProgramSandboxRootRef, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareMethod, MiniProgramSharePostOptions, MiniProgramStorageMethod, MiniProgramToastStatus, MiniProgramUiMethod, MiniProgramUserInfoResult, MiniProgramUserMethod, MiniProgramVibrateIntensity, MiniProgramViewportMethod, MiniProgramWindowInfoResult, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_DOWNLOAD_METHOD, NETWORK_REQUEST_METHOD, NetworkDownloadPayload, NetworkDownloadResult, NetworkRequestPayload, NetworkResponsePayload, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenMiniProgramAppPagePayload, OpenPostDetailAppPagePayload, OpenUserDetailAppPagePayload, ParsedMiniProgramRuntimePermissions, PickDirectoryPayload, PickDirectoryResult, PickFilesPayload, PickFilesResult, RUNTIME_LOCATION_PROBE_METHOD, ReloadPayload, ReloadResult, RevokeAuthorizationPayload, RevokeAuthorizationResult, RuntimeLocationProbePayload, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKHandshakeResult, SDKLocationReportPayload, SDKLocationReportTrigger, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, SaveFilePayload, SaveFileResult, ScreenshotPayload, ScreenshotResult, SetClipboardPayload, SetClipboardResult, SetDisplayPayload, SetDisplayResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_INFO_AUTHORIZATION_SCOPES, USER_REVOKE_AUTHORIZATION_METHOD, UserInfoAuthorization, UserInfoAuthorizationScope, UserInfoAuthorizationStatus, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_DISPLAY_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, VibratePayload, VibrateResult, isManagedMiniProgramRuntimePermissionKey, isMiniProgramBridgeMessage, isMiniProgramByteArray, isMiniProgramDirectoryDescriptor, isMiniProgramDirectoryRef, isMiniProgramDownloadProgressPayload, isMiniProgramFileDescriptor, isMiniProgramFileRef, isMiniProgramFileStat, isMiniProgramFileSystemEntityDescriptor, isMiniProgramPathRootRef, isMiniProgramRelativePath, parseMiniProgramRuntimePermissions } from '@heybox/hb-sdk-protocol';
|
|
2
|
+
export { AUTH_LOGIN_METHOD, AuthorizedUserInfo, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DEVICE_EXECUTE_PROTOCOL_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, DIRECTORY_CREATE_METHOD, DIRECTORY_EXISTS_METHOD, DIRECTORY_LIST_METHOD, DIRECTORY_REMOVE_METHOD, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, DirectoryCreatePayload, DirectoryCreateResult, DirectoryExistsPayload, DirectoryExistsResult, DirectoryListPayload, DirectoryListResult, DirectoryRemovePayload, DirectoryRemoveResult, DownloadProgressPayload, FILES_PICK_DIRECTORY_METHOD, FILES_PICK_FILES_METHOD, FILES_SAVE_FILE_METHOD, FILE_CREATE_METHOD, FILE_EXISTS_METHOD, FILE_READ_BYTES_METHOD, FILE_READ_TEXT_METHOD, FILE_REMOVE_METHOD, FILE_STAT_METHOD, FILE_WRITE_BYTES_METHOD, FILE_WRITE_TEXT_METHOD, FileCreatePayload, FileCreateResult, FileExistsPayload, FileExistsResult, FileReadBytesPayload, FileReadBytesResult, FileReadTextPayload, FileReadTextResult, FileRemovePayload, FileRemoveResult, FileStatPayload, FileStatResult, FileWriteBytesPayload, FileWriteBytesResult, FileWriteTextPayload, FileWriteTextResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetSteamGameListPayload, GetSteamGameListResult, GetStoragePayload, GetStorageResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, HideLoadingPayload, HideLoadingResult, LeaderboardEntry, LeaderboardOrder, LoginPayload, LoginResult, LoginScope, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_OPERATION_PROGRESS_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, MiniProgramAuthMethod, MiniProgramBridgeCancelMessage, MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramBridgeMethod, MiniProgramBridgeProgressMessage, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramDirectDirectoryRef, MiniProgramDirectFileRef, MiniProgramDirectoryDescriptor, MiniProgramDirectoryMethod, MiniProgramDirectoryRef, MiniProgramDisplayState, MiniProgramEventName, MiniProgramEventPayloadMap, MiniProgramFileDescriptor, MiniProgramFileMethod, MiniProgramFileMode, MiniProgramFileRef, MiniProgramFileStat, MiniProgramFileSystemEntityDescriptor, MiniProgramFileSystemEntityRef, MiniProgramFilesMethod, MiniProgramNavigationBarForegroundStyle, MiniProgramNavigationMethod, MiniProgramNetworkHeaders, MiniProgramNetworkMethod, MiniProgramNetworkParams, MiniProgramNetworkRequestMethod, MiniProgramOperatingSystemName, MiniProgramOrientationMode, MiniProgramPathRootRef, MiniProgramRuntimeEnvironmentInfo, MiniProgramRuntimeMode, MiniProgramRuntimePermissionEntry, MiniProgramRuntimePermissionStatus, MiniProgramRuntimePermissionsSnapshot, MiniProgramSafeArea, MiniProgramSandboxRootRef, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareMethod, MiniProgramSharePostOptions, MiniProgramStorageMethod, MiniProgramToastStatus, MiniProgramUiMethod, MiniProgramUserInfoResult, MiniProgramUserMethod, MiniProgramVibrateIntensity, MiniProgramViewportMethod, MiniProgramWindowInfoResult, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_DOWNLOAD_METHOD, NETWORK_REQUEST_METHOD, NETWORK_UPLOAD_METHOD, NetworkDownloadPayload, NetworkDownloadResult, NetworkRequestPayload, NetworkResponsePayload, NetworkUploadPayload, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenMiniProgramAppPagePayload, OpenPostDetailAppPagePayload, OpenUserDetailAppPagePayload, ParsedMiniProgramRuntimePermissions, PickDirectoryPayload, PickDirectoryResult, PickFilesPayload, PickFilesResult, RUNTIME_LOCATION_PROBE_METHOD, ReloadPayload, ReloadResult, RevokeAuthorizationPayload, RevokeAuthorizationResult, RuntimeLocationProbePayload, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKHandshakeResult, SDKLocationReportPayload, SDKLocationReportTrigger, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, SaveFilePayload, SaveFileResult, ScreenshotPayload, ScreenshotResult, SetClipboardPayload, SetClipboardResult, SetDisplayPayload, SetDisplayResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_INFO_AUTHORIZATION_SCOPES, USER_REVOKE_AUTHORIZATION_METHOD, UploadProgressPayload, UserInfoAuthorization, UserInfoAuthorizationScope, UserInfoAuthorizationStatus, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_DISPLAY_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, VibratePayload, VibrateResult, isManagedMiniProgramRuntimePermissionKey, isMiniProgramBridgeMessage, isMiniProgramByteArray, isMiniProgramDirectoryDescriptor, isMiniProgramDirectoryRef, isMiniProgramDownloadProgressPayload, isMiniProgramFileDescriptor, isMiniProgramFileRef, isMiniProgramFileStat, isMiniProgramFileSystemEntityDescriptor, isMiniProgramPathRootRef, isMiniProgramRelativePath, parseMiniProgramRuntimePermissions } from '@heybox/hb-sdk-protocol';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 小程序生命周期或业务事件监听函数。
|
|
@@ -1332,6 +1332,7 @@ interface FilesModule {
|
|
|
1332
1332
|
* 必须直接从按钮点击等可信用户操作调用。不要先 `await` 握手或其他异步任务;应提前通过
|
|
1333
1333
|
* `getHandshakeState()` / `onHandshakeStateChange()` 控制按钮只在 ready 时可用,再在点击回调
|
|
1334
1334
|
* 中立即调用 picker。取消是正常用户结果,应按 `FILE_PICKER_CANCELLED` 结束当前流程。
|
|
1335
|
+
* 选择器等待不设固定超时;用户确认、取消或当前 SDK / Runtime 会话结束后才结束操作。
|
|
1335
1336
|
*
|
|
1336
1337
|
* 默认 `mode: 'read'`、`multiple: false` 且无 `accept`。返回的是用户选择范围内的精确外部
|
|
1337
1338
|
* File direct handles,不是浏览器原生 `File`,不能扩张到父目录或兄弟文件;每项授权只在
|
|
@@ -1421,6 +1422,7 @@ interface FilesModule {
|
|
|
1421
1422
|
* 必须直接从按钮点击等可信用户操作调用。不要先 `await` 握手或其他异步任务;应提前通过
|
|
1422
1423
|
* `getHandshakeState()` / `onHandshakeStateChange()` 控制按钮只在 ready 时可用,再在点击回调
|
|
1423
1424
|
* 中立即调用 picker。取消是正常用户结果,应按 `FILE_PICKER_CANCELLED` 结束当前流程。
|
|
1425
|
+
* 选择器等待不设固定超时;用户确认、取消或当前 SDK / Runtime 会话结束后才结束操作。
|
|
1424
1426
|
*
|
|
1425
1427
|
* 默认授权模式为 `read`。返回的是用户选择范围的精确外部目录授权,只在当前 Runtime
|
|
1426
1428
|
* session 有效;session 结束或授权撤销后不能恢复或持久化复用。其 `file()` / `directory()`
|
|
@@ -1507,6 +1509,7 @@ interface FilesModule {
|
|
|
1507
1509
|
* 必须直接从按钮点击等可信用户操作调用。不要先 `await` 握手或其他异步任务;应提前通过
|
|
1508
1510
|
* `getHandshakeState()` / `onHandshakeStateChange()` 控制按钮只在 ready 时可用,再在点击回调
|
|
1509
1511
|
* 中立即调用。取消是正常用户结果,应按 `FILE_PICKER_CANCELLED` 结束当前流程。
|
|
1512
|
+
* 选择器等待不设固定超时;用户确认、取消或当前 SDK / Runtime 会话结束后才结束操作。
|
|
1510
1513
|
*
|
|
1511
1514
|
* 返回的是当前 Runtime session 内一个精确外部 File 授权,不会额外保留或暴露父 Directory
|
|
1512
1515
|
* handle。它占用 picker / `saveFile()` 共享的 1024 direct-handle 配额中的一个;session 结束
|
|
@@ -1,635 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var process = require('node:process');
|
|
4
|
-
var node_buffer = require('node:buffer');
|
|
5
|
-
var path = require('node:path');
|
|
6
|
-
var node_url = require('node:url');
|
|
7
|
-
var node_util = require('node:util');
|
|
8
|
-
var childProcess = require('node:child_process');
|
|
9
|
-
var fs$1 = require('node:fs/promises');
|
|
10
|
-
var os = require('node:os');
|
|
11
|
-
var fs = require('node:fs');
|
|
12
|
-
|
|
13
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
|
-
let isDockerCached;
|
|
15
|
-
|
|
16
|
-
function hasDockerEnv() {
|
|
17
|
-
try {
|
|
18
|
-
fs.statSync('/.dockerenv');
|
|
19
|
-
return true;
|
|
20
|
-
} catch {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function hasDockerCGroup() {
|
|
26
|
-
try {
|
|
27
|
-
return fs.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
|
28
|
-
} catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isDocker() {
|
|
34
|
-
// TODO: Use `??=` when targeting Node.js 16.
|
|
35
|
-
if (isDockerCached === undefined) {
|
|
36
|
-
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return isDockerCached;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let cachedResult;
|
|
43
|
-
|
|
44
|
-
// Podman detection
|
|
45
|
-
const hasContainerEnv = () => {
|
|
46
|
-
try {
|
|
47
|
-
fs.statSync('/run/.containerenv');
|
|
48
|
-
return true;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function isInsideContainer() {
|
|
55
|
-
// TODO: Use `??=` when targeting Node.js 16.
|
|
56
|
-
if (cachedResult === undefined) {
|
|
57
|
-
cachedResult = hasContainerEnv() || isDocker();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return cachedResult;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const isWsl = () => {
|
|
64
|
-
if (process.platform !== 'linux') {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (os.release().toLowerCase().includes('microsoft')) {
|
|
69
|
-
if (isInsideContainer()) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
if (fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')) {
|
|
78
|
-
return !isInsideContainer();
|
|
79
|
-
}
|
|
80
|
-
} catch {}
|
|
81
|
-
|
|
82
|
-
// Fallback for custom kernels: check WSL-specific paths.
|
|
83
|
-
if (
|
|
84
|
-
fs.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop')
|
|
85
|
-
|| fs.existsSync('/run/WSL')
|
|
86
|
-
) {
|
|
87
|
-
return !isInsideContainer();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return false;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
var isWsl$1 = process.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
94
|
-
|
|
95
|
-
const wslDrivesMountPoint = (() => {
|
|
96
|
-
// Default value for "root" param
|
|
97
|
-
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
|
|
98
|
-
const defaultMountPoint = '/mnt/';
|
|
99
|
-
|
|
100
|
-
let mountPoint;
|
|
101
|
-
|
|
102
|
-
return async function () {
|
|
103
|
-
if (mountPoint) {
|
|
104
|
-
// Return memoized mount point value
|
|
105
|
-
return mountPoint;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const configFilePath = '/etc/wsl.conf';
|
|
109
|
-
|
|
110
|
-
let isConfigFileExists = false;
|
|
111
|
-
try {
|
|
112
|
-
await fs$1.access(configFilePath, fs$1.constants.F_OK);
|
|
113
|
-
isConfigFileExists = true;
|
|
114
|
-
} catch {}
|
|
115
|
-
|
|
116
|
-
if (!isConfigFileExists) {
|
|
117
|
-
return defaultMountPoint;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const configContent = await fs$1.readFile(configFilePath, {encoding: 'utf8'});
|
|
121
|
-
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
122
|
-
|
|
123
|
-
if (!configMountPoint) {
|
|
124
|
-
return defaultMountPoint;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
128
|
-
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
|
129
|
-
|
|
130
|
-
return mountPoint;
|
|
131
|
-
};
|
|
132
|
-
})();
|
|
133
|
-
|
|
134
|
-
const powerShellPathFromWsl = async () => {
|
|
135
|
-
const mountPoint = await wslDrivesMountPoint();
|
|
136
|
-
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const powerShellPath = async () => {
|
|
140
|
-
if (isWsl$1) {
|
|
141
|
-
return powerShellPathFromWsl();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return `${process.env.SYSTEMROOT || process.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
148
|
-
const define = value => Object.defineProperty(object, propertyName, {value, enumerable: true, writable: true});
|
|
149
|
-
|
|
150
|
-
Object.defineProperty(object, propertyName, {
|
|
151
|
-
configurable: true,
|
|
152
|
-
enumerable: true,
|
|
153
|
-
get() {
|
|
154
|
-
const result = valueGetter();
|
|
155
|
-
define(result);
|
|
156
|
-
return result;
|
|
157
|
-
},
|
|
158
|
-
set(value) {
|
|
159
|
-
define(value);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
return object;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const execFileAsync$3 = node_util.promisify(childProcess.execFile);
|
|
167
|
-
|
|
168
|
-
async function defaultBrowserId() {
|
|
169
|
-
if (process.platform !== 'darwin') {
|
|
170
|
-
throw new Error('macOS only');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const {stdout} = await execFileAsync$3('defaults', ['read', 'com.apple.LaunchServices/com.apple.launchservices.secure', 'LSHandlers']);
|
|
174
|
-
|
|
175
|
-
// `(?!-)` is to prevent matching `LSHandlerRoleAll = "-";`.
|
|
176
|
-
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
177
|
-
|
|
178
|
-
const browserId = match?.groups.id ?? 'com.apple.Safari';
|
|
179
|
-
|
|
180
|
-
// Correct the case for Safari's bundle identifier
|
|
181
|
-
if (browserId === 'com.apple.safari') {
|
|
182
|
-
return 'com.apple.Safari';
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return browserId;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const execFileAsync$2 = node_util.promisify(childProcess.execFile);
|
|
189
|
-
|
|
190
|
-
async function runAppleScript(script, {humanReadableOutput = true, signal} = {}) {
|
|
191
|
-
if (process.platform !== 'darwin') {
|
|
192
|
-
throw new Error('macOS only');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const outputArguments = humanReadableOutput ? [] : ['-ss'];
|
|
196
|
-
|
|
197
|
-
const execOptions = {};
|
|
198
|
-
if (signal) {
|
|
199
|
-
execOptions.signal = signal;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const {stdout} = await execFileAsync$2('osascript', ['-e', script, outputArguments], execOptions);
|
|
203
|
-
return stdout.trim();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async function bundleName(bundleId) {
|
|
207
|
-
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const execFileAsync$1 = node_util.promisify(childProcess.execFile);
|
|
211
|
-
|
|
212
|
-
// TODO: Fix the casing of bundle identifiers in the next major version.
|
|
213
|
-
|
|
214
|
-
// Windows doesn't have browser IDs in the same way macOS/Linux does so we give fake
|
|
215
|
-
// ones that look real and match the macOS/Linux versions for cross-platform apps.
|
|
216
|
-
const windowsBrowserProgIds = {
|
|
217
|
-
MSEdgeHTM: {name: 'Edge', id: 'com.microsoft.edge'}, // The missing `L` is correct.
|
|
218
|
-
MSEdgeBHTML: {name: 'Edge Beta', id: 'com.microsoft.edge.beta'},
|
|
219
|
-
MSEdgeDHTML: {name: 'Edge Dev', id: 'com.microsoft.edge.dev'},
|
|
220
|
-
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {name: 'Edge', id: 'com.microsoft.edge.old'},
|
|
221
|
-
ChromeHTML: {name: 'Chrome', id: 'com.google.chrome'},
|
|
222
|
-
ChromeBHTML: {name: 'Chrome Beta', id: 'com.google.chrome.beta'},
|
|
223
|
-
ChromeDHTML: {name: 'Chrome Dev', id: 'com.google.chrome.dev'},
|
|
224
|
-
ChromiumHTM: {name: 'Chromium', id: 'org.chromium.Chromium'},
|
|
225
|
-
BraveHTML: {name: 'Brave', id: 'com.brave.Browser'},
|
|
226
|
-
BraveBHTML: {name: 'Brave Beta', id: 'com.brave.Browser.beta'},
|
|
227
|
-
BraveDHTML: {name: 'Brave Dev', id: 'com.brave.Browser.dev'},
|
|
228
|
-
BraveSSHTM: {name: 'Brave Nightly', id: 'com.brave.Browser.nightly'},
|
|
229
|
-
FirefoxURL: {name: 'Firefox', id: 'org.mozilla.firefox'},
|
|
230
|
-
OperaStable: {name: 'Opera', id: 'com.operasoftware.Opera'},
|
|
231
|
-
VivaldiHTM: {name: 'Vivaldi', id: 'com.vivaldi.Vivaldi'},
|
|
232
|
-
'IE.HTTP': {name: 'Internet Explorer', id: 'com.microsoft.ie'},
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
new Map(Object.entries(windowsBrowserProgIds));
|
|
236
|
-
|
|
237
|
-
class UnknownBrowserError extends Error {}
|
|
238
|
-
|
|
239
|
-
async function defaultBrowser$1(_execFileAsync = execFileAsync$1) {
|
|
240
|
-
const {stdout} = await _execFileAsync('reg', [
|
|
241
|
-
'QUERY',
|
|
242
|
-
' HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice',
|
|
243
|
-
'/v',
|
|
244
|
-
'ProgId',
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
|
-
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
248
|
-
if (!match) {
|
|
249
|
-
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const {id} = match.groups;
|
|
253
|
-
|
|
254
|
-
// Windows can append a hash suffix to ProgIds using a dot or hyphen
|
|
255
|
-
// (e.g., `ChromeHTML.ABC123`, `FirefoxURL-6F193CCC56814779`).
|
|
256
|
-
// Try exact match first, then try without the suffix.
|
|
257
|
-
const dotIndex = id.lastIndexOf('.');
|
|
258
|
-
const hyphenIndex = id.lastIndexOf('-');
|
|
259
|
-
const baseIdByDot = dotIndex === -1 ? undefined : id.slice(0, dotIndex);
|
|
260
|
-
const baseIdByHyphen = hyphenIndex === -1 ? undefined : id.slice(0, hyphenIndex);
|
|
261
|
-
|
|
262
|
-
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? {name: id, id};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const execFileAsync = node_util.promisify(childProcess.execFile);
|
|
266
|
-
|
|
267
|
-
// Inlined: https://github.com/sindresorhus/titleize/blob/main/index.js
|
|
268
|
-
const titleize = string => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, x => x.toUpperCase());
|
|
269
|
-
|
|
270
|
-
async function defaultBrowser() {
|
|
271
|
-
if (process.platform === 'darwin') {
|
|
272
|
-
const id = await defaultBrowserId();
|
|
273
|
-
const name = await bundleName(id);
|
|
274
|
-
return {name, id};
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (process.platform === 'linux') {
|
|
278
|
-
const {stdout} = await execFileAsync('xdg-mime', ['query', 'default', 'x-scheme-handler/http']);
|
|
279
|
-
const id = stdout.trim();
|
|
280
|
-
const name = titleize(id.replace(/.desktop$/, '').replace('-', ' '));
|
|
281
|
-
return {name, id};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (process.platform === 'win32') {
|
|
285
|
-
return defaultBrowser$1();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
throw new Error('Only macOS, Linux, and Windows are supported');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const execFile = node_util.promisify(childProcess.execFile);
|
|
292
|
-
|
|
293
|
-
// Path to included `xdg-open`.
|
|
294
|
-
const __dirname$1 = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/browser-RAy8e8cV.cjs', document.baseURI).href))));
|
|
295
|
-
const localXdgOpenPath = path.join(__dirname$1, 'xdg-open');
|
|
296
|
-
|
|
297
|
-
const {platform, arch} = process;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
Get the default browser name in Windows from WSL.
|
|
301
|
-
|
|
302
|
-
@returns {Promise<string>} Browser name.
|
|
303
|
-
*/
|
|
304
|
-
async function getWindowsDefaultBrowserFromWsl() {
|
|
305
|
-
const powershellPath = await powerShellPath();
|
|
306
|
-
const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
307
|
-
const encodedCommand = node_buffer.Buffer.from(rawCommand, 'utf16le').toString('base64');
|
|
308
|
-
|
|
309
|
-
const {stdout} = await execFile(
|
|
310
|
-
powershellPath,
|
|
311
|
-
[
|
|
312
|
-
'-NoProfile',
|
|
313
|
-
'-NonInteractive',
|
|
314
|
-
'-ExecutionPolicy',
|
|
315
|
-
'Bypass',
|
|
316
|
-
'-EncodedCommand',
|
|
317
|
-
encodedCommand,
|
|
318
|
-
],
|
|
319
|
-
{encoding: 'utf8'},
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
const progId = stdout.trim();
|
|
323
|
-
|
|
324
|
-
// Map ProgId to browser IDs
|
|
325
|
-
const browserMap = {
|
|
326
|
-
ChromeHTML: 'com.google.chrome',
|
|
327
|
-
BraveHTML: 'com.brave.Browser',
|
|
328
|
-
MSEdgeHTM: 'com.microsoft.edge',
|
|
329
|
-
FirefoxURL: 'org.mozilla.firefox',
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
return browserMap[progId] ? {id: browserMap[progId]} : {};
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const pTryEach = async (array, mapper) => {
|
|
336
|
-
let latestError;
|
|
337
|
-
|
|
338
|
-
for (const item of array) {
|
|
339
|
-
try {
|
|
340
|
-
return await mapper(item); // eslint-disable-line no-await-in-loop
|
|
341
|
-
} catch (error) {
|
|
342
|
-
latestError = error;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
throw latestError;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
// eslint-disable-next-line complexity
|
|
350
|
-
const baseOpen = async options => {
|
|
351
|
-
options = {
|
|
352
|
-
wait: false,
|
|
353
|
-
background: false,
|
|
354
|
-
newInstance: false,
|
|
355
|
-
allowNonzeroExitCode: false,
|
|
356
|
-
...options,
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
if (Array.isArray(options.app)) {
|
|
360
|
-
return pTryEach(options.app, singleApp => baseOpen({
|
|
361
|
-
...options,
|
|
362
|
-
app: singleApp,
|
|
363
|
-
}));
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
let {name: app, arguments: appArguments = []} = options.app ?? {};
|
|
367
|
-
appArguments = [...appArguments];
|
|
368
|
-
|
|
369
|
-
if (Array.isArray(app)) {
|
|
370
|
-
return pTryEach(app, appName => baseOpen({
|
|
371
|
-
...options,
|
|
372
|
-
app: {
|
|
373
|
-
name: appName,
|
|
374
|
-
arguments: appArguments,
|
|
375
|
-
},
|
|
376
|
-
}));
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (app === 'browser' || app === 'browserPrivate') {
|
|
380
|
-
// IDs from default-browser for macOS and windows are the same
|
|
381
|
-
const ids = {
|
|
382
|
-
'com.google.chrome': 'chrome',
|
|
383
|
-
'google-chrome.desktop': 'chrome',
|
|
384
|
-
'com.brave.Browser': 'brave',
|
|
385
|
-
'org.mozilla.firefox': 'firefox',
|
|
386
|
-
'firefox.desktop': 'firefox',
|
|
387
|
-
'com.microsoft.msedge': 'edge',
|
|
388
|
-
'com.microsoft.edge': 'edge',
|
|
389
|
-
'com.microsoft.edgemac': 'edge',
|
|
390
|
-
'microsoft-edge.desktop': 'edge',
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
// Incognito flags for each browser in `apps`.
|
|
394
|
-
const flags = {
|
|
395
|
-
chrome: '--incognito',
|
|
396
|
-
brave: '--incognito',
|
|
397
|
-
firefox: '--private-window',
|
|
398
|
-
edge: '--inPrivate',
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
const browser = isWsl$1 ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser();
|
|
402
|
-
if (browser.id in ids) {
|
|
403
|
-
const browserName = ids[browser.id];
|
|
404
|
-
|
|
405
|
-
if (app === 'browserPrivate') {
|
|
406
|
-
appArguments.push(flags[browserName]);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return baseOpen({
|
|
410
|
-
...options,
|
|
411
|
-
app: {
|
|
412
|
-
name: apps[browserName],
|
|
413
|
-
arguments: appArguments,
|
|
414
|
-
},
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
let command;
|
|
422
|
-
const cliArguments = [];
|
|
423
|
-
const childProcessOptions = {};
|
|
424
|
-
|
|
425
|
-
if (platform === 'darwin') {
|
|
426
|
-
command = 'open';
|
|
427
|
-
|
|
428
|
-
if (options.wait) {
|
|
429
|
-
cliArguments.push('--wait-apps');
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (options.background) {
|
|
433
|
-
cliArguments.push('--background');
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
if (options.newInstance) {
|
|
437
|
-
cliArguments.push('--new');
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if (app) {
|
|
441
|
-
cliArguments.push('-a', app);
|
|
442
|
-
}
|
|
443
|
-
} else if (platform === 'win32' || (isWsl$1 && !isInsideContainer() && !app)) {
|
|
444
|
-
command = await powerShellPath();
|
|
445
|
-
|
|
446
|
-
cliArguments.push(
|
|
447
|
-
'-NoProfile',
|
|
448
|
-
'-NonInteractive',
|
|
449
|
-
'-ExecutionPolicy',
|
|
450
|
-
'Bypass',
|
|
451
|
-
'-EncodedCommand',
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
if (!isWsl$1) {
|
|
455
|
-
childProcessOptions.windowsVerbatimArguments = true;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const encodedArguments = ['Start'];
|
|
459
|
-
|
|
460
|
-
if (options.wait) {
|
|
461
|
-
encodedArguments.push('-Wait');
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
if (app) {
|
|
465
|
-
// Double quote with double quotes to ensure the inner quotes are passed through.
|
|
466
|
-
// Inner quotes are delimited for PowerShell interpretation with backticks.
|
|
467
|
-
encodedArguments.push(`"\`"${app}\`""`);
|
|
468
|
-
if (options.target) {
|
|
469
|
-
appArguments.push(options.target);
|
|
470
|
-
}
|
|
471
|
-
} else if (options.target) {
|
|
472
|
-
encodedArguments.push(`"${options.target}"`);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (appArguments.length > 0) {
|
|
476
|
-
appArguments = appArguments.map(argument => `"\`"${argument}\`""`);
|
|
477
|
-
encodedArguments.push('-ArgumentList', appArguments.join(','));
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Using Base64-encoded command, accepted by PowerShell, to allow special characters.
|
|
481
|
-
options.target = node_buffer.Buffer.from(encodedArguments.join(' '), 'utf16le').toString('base64');
|
|
482
|
-
} else {
|
|
483
|
-
if (app) {
|
|
484
|
-
command = app;
|
|
485
|
-
} else {
|
|
486
|
-
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
|
|
487
|
-
const isBundled = !__dirname$1 || __dirname$1 === '/';
|
|
488
|
-
|
|
489
|
-
// Check if local `xdg-open` exists and is executable.
|
|
490
|
-
let exeLocalXdgOpen = false;
|
|
491
|
-
try {
|
|
492
|
-
await fs$1.access(localXdgOpenPath, fs$1.constants.X_OK);
|
|
493
|
-
exeLocalXdgOpen = true;
|
|
494
|
-
} catch {}
|
|
495
|
-
|
|
496
|
-
const useSystemXdgOpen = process.versions.electron
|
|
497
|
-
?? (platform === 'android' || isBundled || !exeLocalXdgOpen);
|
|
498
|
-
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if (appArguments.length > 0) {
|
|
502
|
-
cliArguments.push(...appArguments);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
if (!options.wait) {
|
|
506
|
-
// `xdg-open` will block the process unless stdio is ignored
|
|
507
|
-
// and it's detached from the parent even if it's unref'd.
|
|
508
|
-
childProcessOptions.stdio = 'ignore';
|
|
509
|
-
childProcessOptions.detached = true;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
if (platform === 'darwin' && appArguments.length > 0) {
|
|
514
|
-
cliArguments.push('--args', ...appArguments);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// This has to come after `--args`.
|
|
518
|
-
if (options.target) {
|
|
519
|
-
cliArguments.push(options.target);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
523
|
-
|
|
524
|
-
if (options.wait) {
|
|
525
|
-
return new Promise((resolve, reject) => {
|
|
526
|
-
subprocess.once('error', reject);
|
|
527
|
-
|
|
528
|
-
subprocess.once('close', exitCode => {
|
|
529
|
-
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
530
|
-
reject(new Error(`Exited with code ${exitCode}`));
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
resolve(subprocess);
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
subprocess.unref();
|
|
540
|
-
|
|
541
|
-
return subprocess;
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
const open = (target, options) => {
|
|
545
|
-
if (typeof target !== 'string') {
|
|
546
|
-
throw new TypeError('Expected a `target`');
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return baseOpen({
|
|
550
|
-
...options,
|
|
551
|
-
target,
|
|
552
|
-
});
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
function detectArchBinary(binary) {
|
|
556
|
-
if (typeof binary === 'string' || Array.isArray(binary)) {
|
|
557
|
-
return binary;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const {[arch]: archBinary} = binary;
|
|
561
|
-
|
|
562
|
-
if (!archBinary) {
|
|
563
|
-
throw new Error(`${arch} is not supported`);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
return archBinary;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {
|
|
570
|
-
if (wsl && isWsl$1) {
|
|
571
|
-
return detectArchBinary(wsl);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
if (!platformBinary) {
|
|
575
|
-
throw new Error(`${platform} is not supported`);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
return detectArchBinary(platformBinary);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const apps = {};
|
|
582
|
-
|
|
583
|
-
defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({
|
|
584
|
-
darwin: 'google chrome',
|
|
585
|
-
win32: 'chrome',
|
|
586
|
-
linux: ['google-chrome', 'google-chrome-stable', 'chromium'],
|
|
587
|
-
}, {
|
|
588
|
-
wsl: {
|
|
589
|
-
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
590
|
-
x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'],
|
|
591
|
-
},
|
|
592
|
-
}));
|
|
593
|
-
|
|
594
|
-
defineLazyProperty(apps, 'brave', () => detectPlatformBinary({
|
|
595
|
-
darwin: 'brave browser',
|
|
596
|
-
win32: 'brave',
|
|
597
|
-
linux: ['brave-browser', 'brave'],
|
|
598
|
-
}, {
|
|
599
|
-
wsl: {
|
|
600
|
-
ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe',
|
|
601
|
-
x64: ['/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'],
|
|
602
|
-
},
|
|
603
|
-
}));
|
|
604
|
-
|
|
605
|
-
defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({
|
|
606
|
-
darwin: 'firefox',
|
|
607
|
-
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
608
|
-
linux: 'firefox',
|
|
609
|
-
}, {
|
|
610
|
-
wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe',
|
|
611
|
-
}));
|
|
612
|
-
|
|
613
|
-
defineLazyProperty(apps, 'edge', () => detectPlatformBinary({
|
|
614
|
-
darwin: 'microsoft edge',
|
|
615
|
-
win32: 'msedge',
|
|
616
|
-
linux: ['microsoft-edge', 'microsoft-edge-dev'],
|
|
617
|
-
}, {
|
|
618
|
-
wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
|
619
|
-
}));
|
|
620
|
-
|
|
621
|
-
defineLazyProperty(apps, 'browser', () => 'browser');
|
|
622
|
-
|
|
623
|
-
defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate');
|
|
624
|
-
|
|
625
|
-
async function openExternalUrl(url) {
|
|
626
|
-
try {
|
|
627
|
-
await open(url);
|
|
628
|
-
return true;
|
|
629
|
-
}
|
|
630
|
-
catch {
|
|
631
|
-
return false;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
exports.openExternalUrl = openExternalUrl;
|