Skip to content

Commit 81f48b8

Browse files
committed
Add trash module
1 parent 499798f commit 81f48b8

5 files changed

Lines changed: 189 additions & 17 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@types/node": "^10.12.18",
19+
"@types/trash": "^4.3.1",
1920
"crypto-browserify": "^3.12.0",
2021
"css-loader": "^2.1.0",
2122
"file-loader": "^3.0.1",
@@ -47,6 +48,7 @@
4748
},
4849
"dependencies": {
4950
"node-loader": "^0.6.0",
51+
"trash": "^4.3.0",
5052
"webpack-merge": "^4.2.1"
5153
}
5254
}

packages/ide/src/fill/electron.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/// <reference path="../../../../lib/vscode/src/typings/electron.d.ts" />
2-
import { exec } from "child_process";
32
import { EventEmitter } from "events";
43
import * as fs from "fs";
5-
import { promisify } from "util";
64
import { logger, field } from "@coder/logger";
7-
import { escapePath } from "@coder/protocol";
85
import { IKey, Dialog as DialogBox } from "./dialog";
96
import { clipboard } from "./clipboard";
7+
import { client } from "./client";
8+
9+
// Use this to get around Webpack inserting our fills.
10+
declare var _require: typeof require;
1011

1112
// tslint:disable-next-line no-any
1213
(global as any).getOpenUrls = (): string[] => {
@@ -97,9 +98,11 @@ class Clipboard {
9798

9899
class Shell {
99100
public async moveItemToTrash(path: string): Promise<void> {
100-
await promisify(exec)(
101-
`trash-put --trash-dir ${escapePath("~/.Trash")} ${escapePath(path)}`,
102-
);
101+
await client.evaluate((path) => {
102+
const trash = _require("trash") as typeof import("trash");
103+
104+
return trash(path);
105+
}, path);
103106
}
104107
}
105108

packages/protocol/src/node/evaluate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ export const evaluate = (connection: SendableConnection, message: NewEvalMessage
7979
_Buffer: Buffer,
8080
require: typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require,
8181
_require: typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require,
82-
tslib_1: require("tslib"), // TODO: is there a better way to do this?
8382
setTimeout,
8483
}, {
85-
timeout: message.getTimeout() || 15000,
86-
});
84+
timeout: message.getTimeout() || 15000,
85+
});
8786
if (eventEmitter) {
8887
// Is an active evaluation and should NOT be ended
8988
eventEmitter.on("close", () => onDispose());

packages/server/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = merge({
4848
__dirname: false,
4949
setImmediate: false
5050
},
51-
externals: ["spdlog", "tslib"],
51+
externals: ["spdlog", "tslib", "trash"],
5252
entry: "./packages/server/src/cli.ts",
5353
target: "node",
5454
plugins: [

0 commit comments

Comments
 (0)