From 09d7b2bc91009ae794e45142d064b4e8c5462022 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 30 Nov 2020 21:25:03 +0100 Subject: [PATCH] chore: remove deprecated shell.moveItemToTrash() (#26723) --- docs/api/shell.md | 11 ------ lib/common/api/shell.ts | 4 -- shell/common/api/electron_api_shell.cc | 11 ------ shell/common/platform_util.h | 3 -- shell/common/platform_util_mac.mm | 5 --- shell/common/platform_util_win.cc | 6 --- spec-main/api-shell-spec.ts | 52 -------------------------- spec/ts-smoke/electron/main.ts | 2 +- 8 files changed, 1 insertion(+), 93 deletions(-) diff --git a/docs/api/shell.md b/docs/api/shell.md index 59abeb2259..6b5cf97363 100644 --- a/docs/api/shell.md +++ b/docs/api/shell.md @@ -45,17 +45,6 @@ Returns `Promise` Open the given external protocol URL in the desktop's default manner. (For example, mailto: URLs in the user's default mail agent). -### `shell.moveItemToTrash(fullPath[, deleteOnFail])` _Deprecated_ - -* `fullPath` String -* `deleteOnFail` Boolean (optional) - Whether or not to unilaterally remove the item if the Trash is disabled or unsupported on the volume. _macOS_ - -Returns `Boolean` - Whether the item was successfully moved to the trash or otherwise deleted. - -> NOTE: This method is deprecated. Use `shell.trashItem` instead. - -Move the given file to trash and returns a boolean status for the operation. - ### `shell.trashItem(path)` * `path` String - path to the item to be moved to the trash. diff --git a/lib/common/api/shell.ts b/lib/common/api/shell.ts index a429306f74..056c3fdf82 100644 --- a/lib/common/api/shell.ts +++ b/lib/common/api/shell.ts @@ -1,7 +1,3 @@ -import { deprecate } from 'electron/main'; - const shell = process._linkedBinding('electron_common_shell'); -shell.moveItemToTrash = deprecate.renameFunction(shell.moveItemToTrash, 'shell.trashItem'); - export default shell; diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index 9f302331e2..9f341ac61d 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -85,16 +85,6 @@ v8::Local OpenPath(v8::Isolate* isolate, return handle; } -bool MoveItemToTrash(gin::Arguments* args) { - base::FilePath full_path; - args->GetNext(&full_path); - - bool delete_on_fail = false; - args->GetNext(&delete_on_fail); - - return platform_util::MoveItemToTrash(full_path, delete_on_fail); -} - v8::Local TrashItem(v8::Isolate* isolate, const base::FilePath& path) { gin_helper::Promise promise(isolate); @@ -181,7 +171,6 @@ void Initialize(v8::Local exports, dict.SetMethod("showItemInFolder", &platform_util::ShowItemInFolder); dict.SetMethod("openPath", &OpenPath); dict.SetMethod("openExternal", &OpenExternal); - dict.SetMethod("moveItemToTrash", &MoveItemToTrash); dict.SetMethod("trashItem", &TrashItem); dict.SetMethod("beep", &platform_util::Beep); #if defined(OS_WIN) diff --git a/shell/common/platform_util.h b/shell/common/platform_util.h index d1a6e4c124..541660003b 100644 --- a/shell/common/platform_util.h +++ b/shell/common/platform_util.h @@ -40,9 +40,6 @@ void OpenExternal(const GURL& url, const OpenExternalOptions& options, OpenCallback callback); -// Move a file to trash. (Deprecated.) -bool MoveItemToTrash(const base::FilePath& full_path, bool delete_on_fail); - // Move a file to trash, asynchronously. void TrashItem(const base::FilePath& full_path, base::OnceCallback callback); diff --git a/shell/common/platform_util_mac.mm b/shell/common/platform_util_mac.mm index db404f669b..c844c1d7bf 100644 --- a/shell/common/platform_util_mac.mm +++ b/shell/common/platform_util_mac.mm @@ -153,11 +153,6 @@ bool MoveItemToTrashWithError(const base::FilePath& full_path, return did_trash; } -bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) { - std::string error; // ignored - return MoveItemToTrashWithError(path, delete_on_fail, &error); -} - namespace internal { bool PlatformTrashItem(const base::FilePath& full_path, std::string* error) { diff --git a/shell/common/platform_util_win.cc b/shell/common/platform_util_win.cc index 9f95c5ce72..dae1e87720 100644 --- a/shell/common/platform_util_win.cc +++ b/shell/common/platform_util_win.cc @@ -422,12 +422,6 @@ bool MoveItemToTrashWithError(const base::FilePath& path, return true; } -bool MoveItemToTrash(const base::FilePath& path, bool delete_on_fail) { - std::string error; // ignored - base::win::ScopedCOMInitializer com_initializer; - return MoveItemToTrashWithError(path, delete_on_fail, &error); -} - namespace internal { bool PlatformTrashItem(const base::FilePath& full_path, std::string* error) { diff --git a/spec-main/api-shell-spec.ts b/spec-main/api-shell-spec.ts index e7a89ed622..8ec328c5e3 100644 --- a/spec-main/api-shell-spec.ts +++ b/spec-main/api-shell-spec.ts @@ -7,8 +7,6 @@ import * as fs from 'fs-extra'; import * as path from 'path'; import { AddressInfo } from 'net'; import { expect } from 'chai'; -import { ifit } from './spec-helpers'; -import { execSync } from 'child_process'; describe('shell module', () => { describe('shell.openExternal()', () => { @@ -63,56 +61,6 @@ describe('shell module', () => { }); }); - describe('shell.moveItemToTrash()', () => { - it('moves an item to the trash', async () => { - const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-')); - const filename = path.join(dir, 'temp-to-be-deleted'); - await fs.writeFile(filename, 'dummy-contents'); - const result = shell.moveItemToTrash(filename); - expect(result).to.be.true(); - expect(fs.existsSync(filename)).to.be.false(); - }); - - it('returns false when called with a nonexistent path', () => { - const filename = path.join(app.getPath('temp'), 'does-not-exist'); - const result = shell.moveItemToTrash(filename); - expect(result).to.be.false(); - }); - - ifit(process.platform === 'darwin')('returns false when file has immutable flag', async () => { - const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-')); - const tempPath = path.join(dir, 'locked-file'); - await fs.writeFile(tempPath, 'delete me if you can'); - - // https://ss64.com/osx/chflags.html - execSync(`chflags uchg ${tempPath}`); - expect(shell.moveItemToTrash(tempPath)).to.be.false(); - expect(await fs.pathExists(tempPath)).to.be.true(); - - execSync(`chflags nouchg ${tempPath}`); - expect(shell.moveItemToTrash(tempPath)).to.be.true(); - expect(await fs.pathExists(tempPath)).to.be.false(); - }); - - ifit(process.platform === 'win32')('returns false when path is in use', async () => { - const tempPath = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-')); - const cwd = process.cwd(); - try { - // A process working directory is automatically locked on Windows. - // This is a workaround to avoid pulling in fs-extras flock method. - process.chdir(tempPath); - - expect(shell.moveItemToTrash(tempPath)).to.be.false(); - expect(await fs.pathExists(tempPath)).to.be.true(); - } finally { - process.chdir(cwd); - } - - expect(shell.moveItemToTrash(tempPath)).to.be.true(); - expect(await fs.pathExists(tempPath)).to.be.false(); - }); - }); - describe('shell.trashItem()', () => { it('moves an item to the trash', async () => { const dir = await fs.mkdtemp(path.resolve(app.getPath('temp'), 'electron-shell-spec-')); diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index b00ce5c85a..a728cd5ec9 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -1051,7 +1051,7 @@ app.whenReady().then(() => { // https://github.com/electron/electron/blob/master/docs/api/shell.md shell.showItemInFolder('/home/user/Desktop/test.txt') -shell.moveItemToTrash('/home/user/Desktop/test.txt') +shell.trashItem('/home/user/Desktop/test.txt').then(() => {}) shell.openPath('/home/user/Desktop/test.txt').then(err => { if (err) console.log(err)