electron/lib/browser/api/app.ts

118 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
import * as fs from 'fs';
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
import { Menu, deprecate } from 'electron/main';
const bindings = process._linkedBinding('electron_browser_app');
const commandLine = process._linkedBinding('electron_common_command_line');
2020-07-28 23:43:43 +00:00
const { app } = bindings;
// Only one app object permitted.
2020-03-20 20:28:31 +00:00
export default app;
2020-03-20 20:28:31 +00:00
let dockMenu: Electron.Menu | null = null;
// Properties.
2020-03-20 20:28:31 +00:00
const nativeASGetter = app.isAccessibilitySupportEnabled;
const nativeASSetter = app.setAccessibilitySupportEnabled;
2020-07-28 23:43:43 +00:00
Object.defineProperty(app, 'accessibilitySupportEnabled', {
get: () => nativeASGetter.call(app),
set: (enabled) => nativeASSetter.call(app, enabled)
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const nativeBCGetter = app.getBadgeCount;
const nativeBCSetter = app.setBadgeCount;
2020-07-28 23:43:43 +00:00
Object.defineProperty(app, 'badgeCount', {
get: () => nativeBCGetter.call(app),
set: (count) => nativeBCSetter.call(app, count)
2020-03-20 20:28:31 +00:00
});
2020-03-20 20:28:31 +00:00
const nativeNGetter = app.getName;
const nativeNSetter = app.setName;
2020-07-28 23:43:43 +00:00
Object.defineProperty(app, 'name', {
get: () => nativeNGetter.call(app),
set: (name) => nativeNSetter.call(app, name)
2020-03-20 20:28:31 +00:00
});
Object.assign(app, {
commandLine: {
hasSwitch: (theSwitch: string) => commandLine.hasSwitch(String(theSwitch)),
getSwitchValue: (theSwitch: string) => commandLine.getSwitchValue(String(theSwitch)),
appendSwitch: (theSwitch: string, value?: string) => commandLine.appendSwitch(String(theSwitch), typeof value === 'undefined' ? value : String(value)),
appendArgument: (arg: string) => commandLine.appendArgument(String(arg)),
removeSwitch: (theSwitch: string) => commandLine.removeSwitch(String(theSwitch))
} as Electron.CommandLine
2020-03-20 20:28:31 +00:00
});
// we define this here because it'd be overly complicated to
// do in native land
Object.defineProperty(app, 'applicationMenu', {
get () {
2020-03-20 20:28:31 +00:00
return Menu.getApplicationMenu();
},
set (menu: Electron.Menu | null) {
2020-03-20 20:28:31 +00:00
return Menu.setApplicationMenu(menu);
}
2020-03-20 20:28:31 +00:00
});
// The native implementation is not provided on non-windows platforms
app.setAppUserModelId = app.setAppUserModelId || (() => {});
if (process.platform === 'darwin') {
2020-03-20 20:28:31 +00:00
const setDockMenu = app.dock!.setMenu;
app.dock!.setMenu = (menu) => {
2020-03-20 20:28:31 +00:00
dockMenu = menu;
setDockMenu(menu);
};
app.dock!.getMenu = () => dockMenu;
}
if (process.platform === 'linux') {
2020-03-20 20:28:31 +00:00
const patternVmRSS = /^VmRSS:\s*(\d+) kB$/m;
const patternVmHWM = /^VmHWM:\s*(\d+) kB$/m;
const getStatus = (pid: number) => {
try {
2020-03-20 20:28:31 +00:00
return fs.readFileSync(`/proc/${pid}/status`, 'utf8');
} catch {
2020-03-20 20:28:31 +00:00
return '';
}
2020-03-20 20:28:31 +00:00
};
const getEntry = (file: string, pattern: RegExp) => {
2020-03-20 20:28:31 +00:00
const match = file.match(pattern);
return match ? parseInt(match[1], 10) : 0;
};
const getProcessMemoryInfo = (pid: number) => {
2020-03-20 20:28:31 +00:00
const file = getStatus(pid);
return {
workingSetSize: getEntry(file, patternVmRSS),
peakWorkingSetSize: getEntry(file, patternVmHWM)
2020-03-20 20:28:31 +00:00
};
};
2020-03-20 20:28:31 +00:00
const nativeFn = app.getAppMetrics;
app.getAppMetrics = () => {
2020-03-20 20:28:31 +00:00
const metrics = nativeFn.call(app);
for (const metric of metrics) {
2020-03-20 20:28:31 +00:00
metric.memory = getProcessMemoryInfo(metric.pid);
}
2020-03-20 20:28:31 +00:00
return metrics;
};
}
// Routes the events to webContents.
2020-03-20 20:28:31 +00:00
const events = ['certificate-error', 'select-client-certificate'];
for (const name of events) {
app.on(name as 'certificate-error', (event, webContents, ...args: any[]) => {
2020-03-20 20:28:31 +00:00
webContents.emit(name, event, ...args);
});
}
chore: bump chromium to 102.0.4989.0 (main) (#33557) * chore: bump chromium in DEPS to 102.0.4975.0 * chore: bump chromium in DEPS to 102.0.4977.0 * chore: update patches * Remove parameter of OnGpuProcessCrashed() https://chromium-review.googlesource.com/c/chromium/src/+/3543396 * hid: Add exclusionFilters option to requestDevice https://chromium-review.googlesource.com/c/chromium/src/+/3478175 * chore: bump chromium in DEPS to 102.0.4979.0 * chore: bump chromium in DEPS to 102.0.4981.0 * chore: update patches * Deny notification/push permission for documents in non-standard StoragePartitions https://chromium-review.googlesource.com/c/chromium/src/+/3257305 * Improve FrameTreeNode tracking in URLLoaderNetworkContext https://chromium-review.googlesource.com/c/chromium/src/+/3341866 * fixup! Remove parameter of OnGpuProcessCrashed() * chore: fix lint * Reland "Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome" https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * chore: bump chromium in DEPS to 102.0.4983.0 * Ensure EyeDropperView does not access a destroyed window https://chromium-review.googlesource.com/c/chromium/src/+/3561542 * ci: don't delete dawn .git directory 83901: Adds a generated file with the dawn git hash encoded at build time. | https://dawn-review.googlesource.com/c/dawn/+/83901 * ci: update Windows toolchain 3550827: New toolchain for Windows 10 20348 SDK | https://chromium-review.googlesource.com/c/chromium/src/+/3550827 * chore: bump chromium in DEPS to 102.0.4985.0 * chore: update patches * chore: bump chromium in DEPS to 102.0.4987.0 * chore: update patches * 3563432: codehealth: remove uses of DictionaryValue in cbui/webui https://chromium-review.googlesource.com/c/chromium/src/+/3563432 * chore: update patches after rebase * Use gfx::Insets[F]::TLBR() and gfx::Insets[F]::VH() in the rest of Chrome https://chromium-review.googlesource.com/c/chromium/src/+/3554236 * 3565724: Preserve "proper method names" as-is in error.stack. https://chromium-review.googlesource.com/c/v8/v8/+/3565724 * chore: bump chromium in DEPS to 102.0.4989.0 * chore: update patches * fixup ci: don't delete dawn .git directory for Windows * 3560843: Remove multi-parameter version of gfx::Rect[F]::Inset() https://chromium-review.googlesource.com/c/chromium/src/+/3560843 * 3572711: Remove unused IDS_PDF_TOOLTIP_ROTATE_CW resource. https://chromium-review.googlesource.com/c/chromium/src/+/3572711 * 3572926: Reland "[Sysroot] Switch to Debian Bullseye stable" https://chromium-review.googlesource.com/c/chromium/src/+/3572926 * build: fixup sysroots with electron specific dependencies * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * fixup 3565724: Preserve "proper method names" as-is in error.stack. * fixup Remove multi-parameter version of gfx::Rect[F]::Inset() * test: add spec for navigator.hid.requestDevice({ exclusionFilters: [...] } * fixup 3565724: Preserve "proper method names" as-is in error.stack. * ci: use python3 to get the windows toolchain profile 3525960: Explicitly run everything with python3 | https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3525960 * chore: add diagnostic logging * fix: try calling process.crash() * chore: remove logging Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2022-04-12 11:19:14 +00:00
// Deprecation.
deprecate.event(app, 'gpu-process-crashed', 'child-process-gone');
deprecate.event(app, 'renderer-process-crashed', 'render-process-gone');