Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit b03302b

Browse files
committed
Add new shell API endpoints
1 parent 7a944d8 commit b03302b

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

dist/server/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const window_1 = __importDefault(require("./api/window"));
3131
const process_1 = __importDefault(require("./api/process"));
3232
const contextMenu_1 = __importDefault(require("./api/contextMenu"));
3333
const settings_1 = __importDefault(require("./api/settings"));
34+
const shell_1 = __importDefault(require("./api/shell"));
3435
const progressBar_1 = __importDefault(require("./api/progressBar"));
3536
function startAPIServer(randomSecret) {
3637
return __awaiter(this, void 0, void 0, function* () {
@@ -53,6 +54,7 @@ function startAPIServer(randomSecret) {
5354
httpServer.use("/api/window", window_1.default);
5455
httpServer.use("/api/process", process_1.default);
5556
httpServer.use("/api/settings", settings_1.default);
57+
httpServer.use("/api/shell", shell_1.default);
5658
httpServer.use("/api/context", contextMenu_1.default);
5759
httpServer.use("/api/menu-bar", menuBar_1.default);
5860
httpServer.use("/api/progress-bar", progressBar_1.default);

dist/server/api/shell.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4+
return new (P || (P = Promise))(function (resolve, reject) {
5+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8+
step((generator = generator.apply(thisArg, _arguments || [])).next());
9+
});
10+
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
14+
Object.defineProperty(exports, "__esModule", { value: true });
15+
const express_1 = __importDefault(require("express"));
16+
const electron_1 = require("electron");
17+
const router = express_1.default.Router();
18+
router.post("/show-item-in-folder", (req, res) => {
19+
const { path } = req.body;
20+
electron_1.shell.showItemInFolder(path);
21+
res.sendStatus(200);
22+
});
23+
router.post("/open-item", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
24+
const { path } = req.body;
25+
let result = yield electron_1.shell.openPath(path);
26+
res.json({
27+
result
28+
});
29+
}));
30+
router.post("/open-external", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
31+
const { url } = req.body;
32+
try {
33+
yield electron_1.shell.openExternal(url);
34+
res.sendStatus(200);
35+
}
36+
catch (e) {
37+
res.status(500).json({
38+
error: e
39+
});
40+
}
41+
}));
42+
router.delete("/trash-item", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
43+
const { path } = req.body;
44+
try {
45+
yield electron_1.shell.trashItem(path);
46+
res.sendStatus(200);
47+
}
48+
catch (e) {
49+
res.status(400).json();
50+
}
51+
}));
52+
exports.default = router;

src/server/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import windowRoutes from "./api/window";
1818
import processRoutes from "./api/process";
1919
import contextMenuRoutes from "./api/contextMenu";
2020
import settingsRoutes from "./api/settings";
21+
import shellRoutes from "./api/shell";
2122
import progressBarRoutes from "./api/progressBar";
2223
import { Server } from "net";
2324

@@ -47,6 +48,7 @@ async function startAPIServer(randomSecret: string): Promise<APIProcess> {
4748
httpServer.use("/api/window", windowRoutes);
4849
httpServer.use("/api/process", processRoutes);
4950
httpServer.use("/api/settings", settingsRoutes);
51+
httpServer.use("/api/shell", shellRoutes);
5052
httpServer.use("/api/context", contextMenuRoutes);
5153
httpServer.use("/api/menu-bar", menuBarRoutes);
5254
httpServer.use("/api/progress-bar", progressBarRoutes);

src/server/api/shell.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import express from "express";
2+
import { shell } from "electron";
3+
4+
const router = express.Router();
5+
6+
router.post("/show-item-in-folder", (req, res) => {
7+
const { path } = req.body;
8+
9+
shell.showItemInFolder(path);
10+
11+
res.sendStatus(200);
12+
});
13+
14+
router.post("/open-item", async (req, res) => {
15+
const { path } = req.body;
16+
17+
let result = await shell.openPath(path);
18+
19+
res.json({
20+
result
21+
})
22+
});
23+
24+
router.post("/open-external", async (req, res) => {
25+
const { url } = req.body;
26+
27+
try {
28+
await shell.openExternal(url);
29+
30+
res.sendStatus(200);
31+
} catch (e) {
32+
res.status(500).json({
33+
error: e
34+
});
35+
}
36+
});
37+
38+
router.delete("/trash-item", async (req, res) => {
39+
const { path } = req.body;
40+
41+
try {
42+
await shell.trashItem(path);
43+
44+
res.sendStatus(200);
45+
} catch (e) {
46+
res.status(400).json();
47+
}
48+
});
49+
50+
export default router;

0 commit comments

Comments
 (0)