@pmate/cli 0.42.3 → 0.42.5
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/dist/index.js
CHANGED
|
@@ -18263,7 +18263,7 @@ function readNamespaceFromPayload(payload) {
|
|
|
18263
18263
|
var import_node_fs27 = require("fs");
|
|
18264
18264
|
var import_promises5 = require("fs/promises");
|
|
18265
18265
|
var import_node_path32 = __toESM(require("path"));
|
|
18266
|
-
var
|
|
18266
|
+
var import_node_child_process15 = require("child_process");
|
|
18267
18267
|
var import_promises6 = require("readline/promises");
|
|
18268
18268
|
|
|
18269
18269
|
// src/services/NativeServiceDeploy.ts
|
|
@@ -18439,6 +18439,8 @@ async function buildDesktop(args) {
|
|
|
18439
18439
|
(0, import_node_fs21.writeFileSync)(import_node_path26.default.join(cache, "package.json"), JSON.stringify(toolPackage));
|
|
18440
18440
|
await runBuildCommand(["npm", (0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
|
|
18441
18441
|
}
|
|
18442
|
+
const entitlements = import_node_path26.default.join(staging, "entitlements.mac.plist");
|
|
18443
|
+
(0, import_node_fs21.writeFileSync)(entitlements, `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.cs.allow-jit</key><true/><key>com.apple.security.cs.allow-unsigned-executable-memory</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.device.audio-input</key><true/></dict></plist>`);
|
|
18442
18444
|
const builderConfig = {
|
|
18443
18445
|
appId: c.bundleId,
|
|
18444
18446
|
productName: c.productName,
|
|
@@ -18448,7 +18450,7 @@ async function buildDesktop(args) {
|
|
|
18448
18450
|
asar: true,
|
|
18449
18451
|
artifactName: "${productName}-${version}-${arch}.${ext}",
|
|
18450
18452
|
publish: [{ provider: "generic", url: `https://parrot-static.pmate.chat/desktop/${c.app.split(":").map(encodeURIComponent).join("/")}/${c.version}/${args.platform}/${args.arch}/` }],
|
|
18451
|
-
mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
|
|
18453
|
+
mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, entitlements, entitlementsInherit: entitlements, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
|
|
18452
18454
|
win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
|
|
18453
18455
|
forceCodeSigning: args.signed
|
|
18454
18456
|
};
|
|
@@ -18462,8 +18464,22 @@ async function buildDesktop(args) {
|
|
|
18462
18464
|
console.log(JSON.stringify({ phase: "complete", report: import_node_path26.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
|
|
18463
18465
|
}
|
|
18464
18466
|
|
|
18465
|
-
// src/services/
|
|
18467
|
+
// src/services/CurrentRepositoryRoot.ts
|
|
18466
18468
|
var import_node_child_process10 = require("child_process");
|
|
18469
|
+
function currentRepositoryRoot(repository, cwd = process.cwd()) {
|
|
18470
|
+
const canonical = (value) => value.trim().replace(/\/+$/, "").replace(/\.git$/i, "").replace(/^.*(?:github\.com[/:])/, "").toLowerCase();
|
|
18471
|
+
try {
|
|
18472
|
+
const options = { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] };
|
|
18473
|
+
const origin = (0, import_node_child_process10.execFileSync)("git", ["remote", "get-url", "origin"], options);
|
|
18474
|
+
if (canonical(origin) !== canonical(repository)) return void 0;
|
|
18475
|
+
return (0, import_node_child_process10.execFileSync)("git", ["rev-parse", "--show-toplevel"], options).trim();
|
|
18476
|
+
} catch {
|
|
18477
|
+
return void 0;
|
|
18478
|
+
}
|
|
18479
|
+
}
|
|
18480
|
+
|
|
18481
|
+
// src/services/AndroidApkReleaseService.ts
|
|
18482
|
+
var import_node_child_process11 = require("child_process");
|
|
18467
18483
|
var import_node_crypto5 = require("crypto");
|
|
18468
18484
|
var import_node_fs22 = require("fs");
|
|
18469
18485
|
var import_node_os11 = __toESM(require("os"));
|
|
@@ -18499,7 +18515,7 @@ async function signAndroidApk(apkPath, signing) {
|
|
|
18499
18515
|
try {
|
|
18500
18516
|
(0, import_node_fs22.writeFileSync)(keystorePath, signing.keystore, { mode: 384 });
|
|
18501
18517
|
await new Promise((resolve, reject) => {
|
|
18502
|
-
const child = (0,
|
|
18518
|
+
const child = (0, import_node_child_process11.spawn)(tool, ["sign", "--ks", keystorePath, "--ks-key-alias", signing.alias, "--ks-pass", "env:PMATE_APK_STORE_PASSWORD", "--key-pass", "env:PMATE_APK_KEY_PASSWORD", apkPath], {
|
|
18503
18519
|
env: { ...process.env, PMATE_APK_STORE_PASSWORD: signing.storePassword, PMATE_APK_KEY_PASSWORD: signing.keyPassword },
|
|
18504
18520
|
stdio: "ignore"
|
|
18505
18521
|
});
|
|
@@ -18816,6 +18832,8 @@ function buildAndroidLatestManifest(artifact, options = {}) {
|
|
|
18816
18832
|
};
|
|
18817
18833
|
}
|
|
18818
18834
|
function resolveRepositoryLocalRoot(repository) {
|
|
18835
|
+
const selected = currentRepositoryRoot(repository);
|
|
18836
|
+
if (selected) return selected;
|
|
18819
18837
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
18820
18838
|
if (!repoName) {
|
|
18821
18839
|
throw new Error(`Invalid repository: ${repository}`);
|
|
@@ -18915,7 +18933,7 @@ function listApks(dir) {
|
|
|
18915
18933
|
}
|
|
18916
18934
|
function runCommand(command, args, cwd) {
|
|
18917
18935
|
return new Promise((resolve, reject) => {
|
|
18918
|
-
const child = (0,
|
|
18936
|
+
const child = (0, import_node_child_process11.spawn)(command, args, { cwd, stdio: "inherit" });
|
|
18919
18937
|
child.on("error", reject);
|
|
18920
18938
|
child.on("close", (code) => {
|
|
18921
18939
|
if (code === 0) resolve();
|
|
@@ -18925,7 +18943,7 @@ function runCommand(command, args, cwd) {
|
|
|
18925
18943
|
}
|
|
18926
18944
|
function runCommandCapture(command, args, cwd) {
|
|
18927
18945
|
return new Promise((resolve, reject) => {
|
|
18928
|
-
const child = (0,
|
|
18946
|
+
const child = (0, import_node_child_process11.spawn)(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
18929
18947
|
const chunks = [];
|
|
18930
18948
|
const errorChunks = [];
|
|
18931
18949
|
child.stdout?.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
|
@@ -18981,7 +18999,7 @@ function capitalize(value) {
|
|
|
18981
18999
|
}
|
|
18982
19000
|
|
|
18983
19001
|
// src/services/HarmonyReleaseService.ts
|
|
18984
|
-
var
|
|
19002
|
+
var import_node_child_process12 = require("child_process");
|
|
18985
19003
|
var import_node_crypto6 = require("crypto");
|
|
18986
19004
|
var import_node_fs23 = require("fs");
|
|
18987
19005
|
var import_node_os12 = __toESM(require("os"));
|
|
@@ -19081,7 +19099,7 @@ var runHarmonyCommand = async (command, args, options) => {
|
|
|
19081
19099
|
const output = options.output ? (0, import_node_fs23.openSync)(options.output, "w", 384) : void 0;
|
|
19082
19100
|
try {
|
|
19083
19101
|
return await new Promise((resolve, reject) => {
|
|
19084
|
-
const child = (0,
|
|
19102
|
+
const child = (0, import_node_child_process12.spawn)(command, args, { cwd: options.cwd, env: options.env, detached: process.platform !== "win32", stdio: ["ignore", output ?? (options.capture ? "pipe" : log), log] });
|
|
19085
19103
|
let text = "", oversized = false;
|
|
19086
19104
|
child.stdout?.on("data", (chunk) => {
|
|
19087
19105
|
if (Buffer.byteLength(text) + chunk.length > 1024 * 1024) {
|
|
@@ -19242,7 +19260,7 @@ var HarmonyReleaseService = class {
|
|
|
19242
19260
|
if (options.local) return { ...plan, status: "local", output, log, artifacts };
|
|
19243
19261
|
let revision;
|
|
19244
19262
|
try {
|
|
19245
|
-
revision = (0,
|
|
19263
|
+
revision = (0, import_node_child_process12.execFileSync)("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
19246
19264
|
} catch {
|
|
19247
19265
|
}
|
|
19248
19266
|
const manifest = { schemaVersion: 1, serviceId: service.id, app: application, platform: "harmonyos", distribution: "oss", appGallerySubmitted: false, ...version, signature: "verified", certificateSha256: material.fingerprint, sourceRevision: revision, artifacts, publishedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -19262,7 +19280,7 @@ var HarmonyReleaseService = class {
|
|
|
19262
19280
|
};
|
|
19263
19281
|
|
|
19264
19282
|
// src/services/IosBuildService.ts
|
|
19265
|
-
var
|
|
19283
|
+
var import_node_child_process13 = require("child_process");
|
|
19266
19284
|
var import_node_crypto7 = require("crypto");
|
|
19267
19285
|
var import_node_fs24 = require("fs");
|
|
19268
19286
|
var import_node_os13 = __toESM(require("os"));
|
|
@@ -19275,7 +19293,7 @@ function iosBuildInteger(value) {
|
|
|
19275
19293
|
}
|
|
19276
19294
|
async function runXcode(args, cwd, logPath) {
|
|
19277
19295
|
return new Promise((resolve, reject) => {
|
|
19278
|
-
const child = (0,
|
|
19296
|
+
const child = (0, import_node_child_process13.spawn)("xcodebuild", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
19279
19297
|
let output = "";
|
|
19280
19298
|
child.stdout.on("data", (chunk) => {
|
|
19281
19299
|
if (args.includes("-json") || args.includes("-version")) output += chunk.toString();
|
|
@@ -19391,7 +19409,7 @@ ${String(error)}
|
|
|
19391
19409
|
};
|
|
19392
19410
|
async function readPlist(input) {
|
|
19393
19411
|
return new Promise((resolve, reject) => {
|
|
19394
|
-
const child = (0,
|
|
19412
|
+
const child = (0, import_node_child_process13.spawn)("plutil", ["-convert", "json", "-o", "-", "--", "-"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
19395
19413
|
let output = "";
|
|
19396
19414
|
let error = "";
|
|
19397
19415
|
child.stdout.on("data", (chunk) => {
|
|
@@ -19592,7 +19610,7 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
|
|
|
19592
19610
|
var import_node_fs26 = require("fs");
|
|
19593
19611
|
var import_node_os14 = __toESM(require("os"));
|
|
19594
19612
|
var import_node_path31 = __toESM(require("path"));
|
|
19595
|
-
var
|
|
19613
|
+
var import_node_child_process14 = require("child_process");
|
|
19596
19614
|
var import_node_readline = require("readline");
|
|
19597
19615
|
var import_chalk3 = __toESM(require("chalk"));
|
|
19598
19616
|
var import_dotenv = require("dotenv");
|
|
@@ -20095,6 +20113,8 @@ var ServiceRuntimeRunner = class {
|
|
|
20095
20113
|
}
|
|
20096
20114
|
const repository = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getRepoStaticSite(service).repository.trim() : this.getType(service) === "fc" ? this.getFc(service).repository?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).repository?.trim();
|
|
20097
20115
|
if (repository) {
|
|
20116
|
+
const selected = currentRepositoryRoot(repository);
|
|
20117
|
+
if (selected) return selected;
|
|
20098
20118
|
const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
|
|
20099
20119
|
if (repoName) {
|
|
20100
20120
|
const candidate = import_node_path31.default.join(import_node_os14.default.homedir(), "dev", "pmate", repoName);
|
|
@@ -21075,7 +21095,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21075
21095
|
writeRemoteConfig(server, content, remotePath) {
|
|
21076
21096
|
return new Promise((resolve, reject) => {
|
|
21077
21097
|
const target = `pmate@${server}`;
|
|
21078
|
-
const child = (0,
|
|
21098
|
+
const child = (0, import_node_child_process14.spawn)("ssh", [target, "sudo", "tee", remotePath], {
|
|
21079
21099
|
stdio: ["pipe", "inherit", "inherit"]
|
|
21080
21100
|
});
|
|
21081
21101
|
child.on("error", reject);
|
|
@@ -21090,7 +21110,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21090
21110
|
reloadNginx(server) {
|
|
21091
21111
|
return new Promise((resolve, reject) => {
|
|
21092
21112
|
const target = `pmate@${server}`;
|
|
21093
|
-
const child = (0,
|
|
21113
|
+
const child = (0, import_node_child_process14.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
21094
21114
|
stdio: ["ignore", "inherit", "inherit"]
|
|
21095
21115
|
});
|
|
21096
21116
|
child.on("error", reject);
|
|
@@ -21277,7 +21297,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21277
21297
|
}
|
|
21278
21298
|
runCommandWithEnv(command, args, cwd, env) {
|
|
21279
21299
|
return new Promise((resolve, reject) => {
|
|
21280
|
-
const child = (0,
|
|
21300
|
+
const child = (0, import_node_child_process14.spawn)(command, args, {
|
|
21281
21301
|
cwd,
|
|
21282
21302
|
stdio: "inherit",
|
|
21283
21303
|
env: { ...process.env, ...env ?? {} }
|
|
@@ -21288,7 +21308,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21288
21308
|
}
|
|
21289
21309
|
runShellCommand(command, cwd, env) {
|
|
21290
21310
|
return new Promise((resolve, reject) => {
|
|
21291
|
-
const child = (0,
|
|
21311
|
+
const child = (0, import_node_child_process14.spawn)(command, [], {
|
|
21292
21312
|
cwd,
|
|
21293
21313
|
stdio: "inherit",
|
|
21294
21314
|
shell: true,
|
|
@@ -21302,7 +21322,7 @@ var ServiceRuntimeRunner = class {
|
|
|
21302
21322
|
if (server === "local") return this.runCommandWithEnv("bash", ["-c", command], import_node_os14.default.homedir());
|
|
21303
21323
|
return new Promise((resolve, reject) => {
|
|
21304
21324
|
const target = `pmate@${server}`;
|
|
21305
|
-
const child = (0,
|
|
21325
|
+
const child = (0, import_node_child_process14.spawn)("ssh", [target, "bash -ls"], { stdio: ["pipe", "inherit", "inherit"] });
|
|
21306
21326
|
child.stdin.on("error", reject);
|
|
21307
21327
|
child.stdin.end(`${command}
|
|
21308
21328
|
`);
|
|
@@ -22447,7 +22467,7 @@ var ServiceCommandHandler = class {
|
|
|
22447
22467
|
removeRemoteConfig(server, remotePath) {
|
|
22448
22468
|
return new Promise((resolve, reject) => {
|
|
22449
22469
|
const target = `pmate@${server}`;
|
|
22450
|
-
const child = (0,
|
|
22470
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
|
|
22451
22471
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22452
22472
|
});
|
|
22453
22473
|
child.on("error", (error) => {
|
|
@@ -22465,7 +22485,7 @@ var ServiceCommandHandler = class {
|
|
|
22465
22485
|
reloadNginx(server) {
|
|
22466
22486
|
return new Promise((resolve, reject) => {
|
|
22467
22487
|
const target = `pmate@${server}`;
|
|
22468
|
-
const child = (0,
|
|
22488
|
+
const child = (0, import_node_child_process15.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
|
|
22469
22489
|
stdio: ["ignore", "inherit", "inherit"]
|
|
22470
22490
|
});
|
|
22471
22491
|
child.on("error", (error) => {
|
|
@@ -22538,9 +22558,9 @@ function sleep3(ms) {
|
|
|
22538
22558
|
}
|
|
22539
22559
|
|
|
22540
22560
|
// src/commands/VercelCommandHandler.ts
|
|
22541
|
-
var
|
|
22561
|
+
var import_node_child_process16 = require("child_process");
|
|
22542
22562
|
var import_node_util = require("util");
|
|
22543
|
-
var execFileAsync = (0, import_node_util.promisify)(
|
|
22563
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process16.execFile);
|
|
22544
22564
|
function parseDeploymentTimestamp(deployment) {
|
|
22545
22565
|
const candidates = [deployment.createdAt, deployment.readyAt, deployment.ready];
|
|
22546
22566
|
for (const value of candidates) {
|
|
@@ -23786,7 +23806,7 @@ function encodePathSegment3(value) {
|
|
|
23786
23806
|
var import_node_fs30 = require("fs");
|
|
23787
23807
|
var import_node_os15 = require("os");
|
|
23788
23808
|
var import_node_path35 = __toESM(require("path"));
|
|
23789
|
-
var
|
|
23809
|
+
var import_node_child_process17 = require("child_process");
|
|
23790
23810
|
var BLOCK_START = "# >>> pmate host env >>>";
|
|
23791
23811
|
var BLOCK_END = "# <<< pmate host env <<<";
|
|
23792
23812
|
var PROFILE_BLOCK = `${BLOCK_START}
|
|
@@ -23829,7 +23849,7 @@ async function applyHostEnvRemote(host, values) {
|
|
|
23829
23849
|
const content = serializeHostEnv(values);
|
|
23830
23850
|
const script = buildRemoteApplyScript(Buffer.from(content, "utf8").toString("base64"));
|
|
23831
23851
|
await new Promise((resolve, reject) => {
|
|
23832
|
-
const child = (0,
|
|
23852
|
+
const child = (0, import_node_child_process17.spawn)("ssh", [target, "bash -s"], { stdio: ["pipe", "pipe", "pipe"] });
|
|
23833
23853
|
let stdout = "";
|
|
23834
23854
|
let stderr = "";
|
|
23835
23855
|
child.stdout.on("data", (chunk) => {
|
|
@@ -8,6 +8,7 @@ function validApplicationUrl(raw) {
|
|
|
8
8
|
|
|
9
9
|
function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNavigationRestrictions, openExternal, trusted }) {
|
|
10
10
|
const children = new Set()
|
|
11
|
+
const microphoneOrigins = new Map()
|
|
11
12
|
ipcMain.handle('pmate:app:open', async (event, raw) => {
|
|
12
13
|
if (!trusted(event)) throw new Error('Untrusted app sender')
|
|
13
14
|
const target = validApplicationUrl(raw)
|
|
@@ -21,7 +22,8 @@ function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNa
|
|
|
21
22
|
webPreferences: { session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true },
|
|
22
23
|
})
|
|
23
24
|
children.add(child)
|
|
24
|
-
child.
|
|
25
|
+
microphoneOrigins.set(child.webContents, target.origin)
|
|
26
|
+
child.on('closed', () => { children.delete(child); microphoneOrigins.delete(child.webContents) })
|
|
25
27
|
// The child application owns its own document links. Keep shared authentication
|
|
26
28
|
// origins available in Electron, without inheriting Merry's external-link policy.
|
|
27
29
|
installNavigationRestrictions(child, { ...config, origin: target.origin, externalOrigins: [] }, openExternal)
|
|
@@ -33,7 +35,15 @@ function installDesktopApps({ ipcMain, BrowserWindow, session, config, installNa
|
|
|
33
35
|
throw error
|
|
34
36
|
}
|
|
35
37
|
})
|
|
36
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
getMicrophoneOrigin: contents => {
|
|
40
|
+
const expected = microphoneOrigins.get(contents)
|
|
41
|
+
if (!expected) return null
|
|
42
|
+
const child = [...children].find(window => !window.isDestroyed() && window.webContents === contents)
|
|
43
|
+
try { return child && new URL(contents.getURL()).origin === expected ? expected : null } catch { return null }
|
|
44
|
+
},
|
|
45
|
+
close: () => { for (const child of children) child.close(); children.clear(); microphoneOrigins.clear() },
|
|
46
|
+
}
|
|
37
47
|
}
|
|
38
48
|
|
|
39
49
|
module.exports = { installDesktopApps, validApplicationUrl }
|
|
@@ -38,7 +38,7 @@ else {
|
|
|
38
38
|
}
|
|
39
39
|
return desktopSession.fetch(request, { bypassCustomProtocolHandlers: true })
|
|
40
40
|
})
|
|
41
|
-
installMediaPermissions(desktopSession, { origin: config.origin, getWindow: () => mainWindow, getWindows: () => [mainWindow, desktopCalls?.getWindow()], desktopCapturer, BrowserWindow, ipcMain })
|
|
41
|
+
installMediaPermissions(desktopSession, { origin: config.origin, getWindow: () => mainWindow, getWindows: () => [mainWindow, desktopCalls?.getWindow()], getMicrophoneOrigin: contents => desktopApps?.getMicrophoneOrigin(contents), desktopCapturer, BrowserWindow, ipcMain })
|
|
42
42
|
ipcMain.handle('pmate:screen-settings', event => {
|
|
43
43
|
if (!mainWindow || event.sender !== mainWindow.webContents || event.senderFrame !== mainWindow.webContents.mainFrame || new URL(mainWindow.webContents.getURL()).origin !== config.origin) return false
|
|
44
44
|
if (process.platform === 'darwin') { void shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture'); return true }
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
const { chooseScreen } = require('./share-picker.cjs')
|
|
2
|
-
function installMediaPermissions(desktopSession, { origin, getWindow, getWindows = () => [getWindow()], desktopCapturer, BrowserWindow, ipcMain }) {
|
|
2
|
+
function installMediaPermissions(desktopSession, { origin, getWindow, getWindows = () => [getWindow()], desktopCapturer, BrowserWindow, ipcMain, getMicrophoneOrigin = () => null }) {
|
|
3
3
|
const sameOrigin = raw => { try { return new URL(raw).origin === origin } catch { return false } }
|
|
4
4
|
const trusted = contents => {
|
|
5
5
|
return getWindows().some(window => !!window && !window.isDestroyed() && contents === window.webContents && sameOrigin(contents.getURL()))
|
|
6
6
|
}
|
|
7
|
+
const audioAllowed = (contents, raw, details) => {
|
|
8
|
+
if (details.isMainFrame !== true) return false
|
|
9
|
+
if (trusted(contents) && sameOrigin(raw)) return true
|
|
10
|
+
const expected = getMicrophoneOrigin(contents)
|
|
11
|
+
try { return !!expected && new URL(raw).origin === expected } catch { return false }
|
|
12
|
+
}
|
|
7
13
|
desktopSession.setPermissionRequestHandler((contents, permission, callback, details) => {
|
|
8
14
|
const allowed = trusted(contents) && details.isMainFrame === true && sameOrigin(details.requestingUrl)
|
|
9
|
-
callback(Boolean(allowed &&
|
|
15
|
+
callback(Boolean((allowed && permission === 'display-capture') || (permission === 'media' && audioAllowed(contents, details.requestingUrl, details) && details.mediaTypes?.length && details.mediaTypes.every(type => type === 'audio'))))
|
|
10
16
|
})
|
|
11
17
|
desktopSession.setPermissionCheckHandler((contents, permission, requestingOrigin, details) => {
|
|
12
|
-
return Boolean(trusted(contents) && sameOrigin(requestingOrigin) && details.isMainFrame === true &&
|
|
18
|
+
return Boolean((trusted(contents) && sameOrigin(requestingOrigin) && details.isMainFrame === true && permission === 'display-capture') || (permission === 'media' && details.mediaType === 'audio' && audioAllowed(contents, requestingOrigin, details)))
|
|
13
19
|
})
|
|
14
20
|
desktopSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
|
15
21
|
const window = getWindows().find(window => window && !window.isDestroyed() && request.frame === window.webContents.mainFrame)
|