From 022bafc485986b0a00625bc8976a54801145a5bc Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 26 Nov 2020 20:07:40 +0100 Subject: [PATCH] chore: remove deprecated crashReporter APIs (#26695) --- docs/api/crash-reporter.md | 16 ++++--------- docs/breaking-changes.md | 12 ++++++++++ lib/browser/api/crash-reporter.ts | 4 ---- lib/browser/rpc-server.ts | 22 +---------------- lib/common/ipc-messages.ts | 6 ----- lib/renderer/api/crash-reporter.ts | 36 ---------------------------- spec-main/api-crash-reporter-spec.ts | 10 +++----- 7 files changed, 21 insertions(+), 85 deletions(-) diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index e81729e4632d..c03f8a7e0398 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -128,7 +128,7 @@ must be at most 39 bytes long, and values must be no longer than 127 bytes. Keys with names longer than the maximum will be silently ignored. Key values longer than the maximum length will be truncated. -**Note:** Calling this method from the renderer process is deprecated. +**Note:** This method is only available in the main process. ### `crashReporter.getLastCrashReport()` @@ -137,7 +137,7 @@ last crash report. Only crash reports that have been uploaded will be returned; even if a crash report is present on disk it will not be returned until it is uploaded. In the case that there are no uploaded reports, `null` is returned. -**Note:** Calling this method from the renderer process is deprecated. +**Note:** This method is only available in the main process. ### `crashReporter.getUploadedReports()` @@ -146,14 +146,14 @@ Returns [`CrashReport[]`](structures/crash-report.md): Returns all uploaded crash reports. Each report contains the date and uploaded ID. -**Note:** Calling this method from the renderer process is deprecated. +**Note:** This method is only available in the main process. ### `crashReporter.getUploadToServer()` Returns `Boolean` - Whether reports should be submitted to the server. Set through the `start` method or `setUploadToServer`. -**Note:** Calling this method from the renderer process is deprecated. +**Note:** This method is only available in the main process. ### `crashReporter.setUploadToServer(uploadToServer)` @@ -162,13 +162,7 @@ the `start` method or `setUploadToServer`. This would normally be controlled by user preferences. This has no effect if called before `start` is called. -**Note:** Calling this method from the renderer process is deprecated. - -### `crashReporter.getCrashesDirectory()` _Deprecated_ - -Returns `String` - The directory where crashes are temporarily stored before being uploaded. - -**Note:** This method is deprecated, use `app.getPath('crashDumps')` instead. +**Note:** This method is only available in the main process. ### `crashReporter.addExtraParameter(key, value)` diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 73525e37cd9d..166be0241cce 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -43,6 +43,18 @@ We [recommend having contextIsolation enabled](https://github.com/electron/elect For more details see: https://github.com/electron/electron/issues/23506 +### Removed: `crashReporter.getCrashesDirectory()` + +The `crashReporter.getCrashesDirectory` method has been removed. Usage +should be replaced by `app.getPath('crashDumps')`. + +```js +// Removed in Electron 12 +crashReporter.getCrashesDirectory() +// Replace with +app.getPath('crashDumps') +``` + ### Removed: `crashReporter` methods in the renderer process The following `crashReporter` methods are no longer available in the renderer diff --git a/lib/browser/api/crash-reporter.ts b/lib/browser/api/crash-reporter.ts index 6e882db244ab..14c3ff347a59 100644 --- a/lib/browser/api/crash-reporter.ts +++ b/lib/browser/api/crash-reporter.ts @@ -51,10 +51,6 @@ class CrashReporter { return binding.getUploadedReports(); } - getCrashesDirectory () { - return app.getPath('crashDumps'); - } - getUploadToServer () { if (process.type === 'browser') { return binding.getUploadToServer(); diff --git a/lib/browser/rpc-server.ts b/lib/browser/rpc-server.ts index 4d7a78701439..f99e3b813a9f 100644 --- a/lib/browser/rpc-server.ts +++ b/lib/browser/rpc-server.ts @@ -1,6 +1,6 @@ import { app } from 'electron/main'; import type { WebContents } from 'electron/main'; -import { clipboard, crashReporter, nativeImage } from 'electron/common'; +import { clipboard, nativeImage } from 'electron/common'; import * as fs from 'fs'; import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal'; import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils'; @@ -104,26 +104,6 @@ ipcMainInternal.on(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, function (event, preloadP event.sender.emit('preload-error', event, preloadPath, error); }); -ipcMainUtils.handleSync(IPC_MESSAGES.CRASH_REPORTER_GET_LAST_CRASH_REPORT, () => { - return crashReporter.getLastCrashReport(); -}); - -ipcMainUtils.handleSync(IPC_MESSAGES.CRASH_REPORTER_GET_UPLOADED_REPORTS, () => { - return crashReporter.getUploadedReports(); -}); - -ipcMainUtils.handleSync(IPC_MESSAGES.CRASH_REPORTER_GET_UPLOAD_TO_SERVER, () => { - return crashReporter.getUploadToServer(); -}); - -ipcMainUtils.handleSync(IPC_MESSAGES.CRASH_REPORTER_SET_UPLOAD_TO_SERVER, (event, uploadToServer: boolean) => { - return crashReporter.setUploadToServer(uploadToServer); -}); - -ipcMainUtils.handleSync(IPC_MESSAGES.CRASH_REPORTER_GET_CRASHES_DIRECTORY, () => { - return crashReporter.getCrashesDirectory(); -}); - ipcMainInternal.handle(IPC_MESSAGES.NATIVE_IMAGE_CREATE_THUMBNAIL_FROM_PATH, async (_, path: string, size: Electron.Size) => { return typeUtils.serialize(await nativeImage.createThumbnailFromPath(path, size)); }); diff --git a/lib/common/ipc-messages.ts b/lib/common/ipc-messages.ts index 1ee697f73733..468e9ad5d40f 100644 --- a/lib/common/ipc-messages.ts +++ b/lib/common/ipc-messages.ts @@ -5,12 +5,6 @@ export const enum IPC_MESSAGES { BROWSER_SANDBOX_LOAD = 'BROWSER_SANDBOX_LOAD', BROWSER_WINDOW_CLOSE = 'BROWSER_WINDOW_CLOSE', - CRASH_REPORTER_GET_LAST_CRASH_REPORT = 'CRASH_REPORTER_GET_LAST_CRASH_REPORT', - CRASH_REPORTER_GET_UPLOADED_REPORTS = 'CRASH_REPORTER_GET_UPLOADED_REPORTS', - CRASH_REPORTER_GET_UPLOAD_TO_SERVER = 'CRASH_REPORTER_GET_UPLOAD_TO_SERVER', - CRASH_REPORTER_SET_UPLOAD_TO_SERVER = 'CRASH_REPORTER_SET_UPLOAD_TO_SERVER', - CRASH_REPORTER_GET_CRASHES_DIRECTORY = 'CRASH_REPORTER_GET_CRASHES_DIRECTORY', - GUEST_INSTANCE_VISIBILITY_CHANGE = 'GUEST_INSTANCE_VISIBILITY_CHANGE', GUEST_VIEW_INTERNAL_DESTROY_GUEST = 'GUEST_VIEW_INTERNAL_DESTROY_GUEST', diff --git a/lib/renderer/api/crash-reporter.ts b/lib/renderer/api/crash-reporter.ts index 2f2427b9fcb9..753894f7a108 100644 --- a/lib/renderer/api/crash-reporter.ts +++ b/lib/renderer/api/crash-reporter.ts @@ -1,42 +1,6 @@ -import { invokeSync } from '../ipc-renderer-internal-utils'; -import { deprecate } from 'electron'; -import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages'; - const binding = process._linkedBinding('electron_renderer_crash_reporter'); export default { - start (options: Electron.CrashReporterStartOptions) { - deprecate.log('crashReporter.start is deprecated in the renderer process. Call it from the main process instead.'); - for (const [k, v] of Object.entries(options.extra || {})) { - binding.addExtraParameter(k, String(v)); - } - }, - - getLastCrashReport (): Electron.CrashReport | null { - deprecate.log('crashReporter.getLastCrashReport is deprecated in the renderer process. Call it from the main process instead.'); - return invokeSync(IPC_MESSAGES.CRASH_REPORTER_GET_LAST_CRASH_REPORT); - }, - - getUploadedReports () { - deprecate.log('crashReporter.getUploadedReports is deprecated in the renderer process. Call it from the main process instead.'); - return invokeSync(IPC_MESSAGES.CRASH_REPORTER_GET_UPLOADED_REPORTS); - }, - - getUploadToServer () { - deprecate.log('crashReporter.getUploadToServer is deprecated in the renderer process. Call it from the main process instead.'); - return invokeSync(IPC_MESSAGES.CRASH_REPORTER_GET_UPLOAD_TO_SERVER); - }, - - setUploadToServer (uploadToServer: boolean) { - deprecate.log('crashReporter.setUploadToServer is deprecated in the renderer process. Call it from the main process instead.'); - return invokeSync(IPC_MESSAGES.CRASH_REPORTER_SET_UPLOAD_TO_SERVER, uploadToServer); - }, - - getCrashesDirectory () { - deprecate.log('crashReporter.getCrashesDirectory is deprecated in the renderer process. Call it from the main process instead.'); - return invokeSync(IPC_MESSAGES.CRASH_REPORTER_GET_CRASHES_DIRECTORY); - }, - addExtraParameter (key: string, value: string) { binding.addExtraParameter(key, value); }, diff --git a/spec-main/api-crash-reporter-spec.ts b/spec-main/api-crash-reporter-spec.ts index 1aaf34b5d5b8..8d9ee46b763d 100644 --- a/spec-main/api-crash-reporter-spec.ts +++ b/spec-main/api-crash-reporter-spec.ts @@ -523,10 +523,6 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ expect(app.getPath('crashDumps')).to.include(app.getPath('userData')); }); - it('matches getCrashesDirectory', async () => { - expect(app.getPath('crashDumps')).to.equal(require('electron').crashReporter.getCrashesDirectory()); - }); - function crash (processType: string, remotely: Function) { if (processType === 'main') { return remotely(() => { @@ -565,9 +561,9 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ it('stores crashes in the crash dump directory when uploadToServer: false', async () => { const { remotely } = await startRemoteControlApp(); const crashesDir = await remotely(() => { - const { crashReporter } = require('electron'); + const { crashReporter, app } = require('electron'); crashReporter.start({ submitURL: 'http://127.0.0.1', uploadToServer: false, ignoreSystemCrashHandler: true }); - return crashReporter.getCrashesDirectory(); + return app.getPath('crashDumps'); }); let reportsDir = crashesDir; if (process.platform === 'darwin') { @@ -599,7 +595,7 @@ ifdescribe(!isLinuxOnArm && !process.mas && !process.env.DISABLE_CRASH_REPORTER_ const { crashReporter, app } = require('electron'); app.setPath('crashDumps', crashesDir); crashReporter.start({ submitURL: 'http://127.0.0.1', uploadToServer: false, ignoreSystemCrashHandler: true }); - return crashReporter.getCrashesDirectory(); + return app.getPath('crashDumps'); }, crashesDir); expect(remoteCrashesDir).to.equal(crashesDir);