Skip to content

Commit 592443c

Browse files
committed
electron.shell.openExternal -> window.open
1 parent 1f5f092 commit 592443c

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

open-in-mpv.plugin.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
* @name open in mpv
33
* @author binarynoise
44
* @description Use the context menu to open a video in mpv.
5-
* @version 2.1.0
5+
* @version 2.1.1
66
*/
77

88
'use strict';
9-
const electron = require('electron');
109

1110
// change this when mpv-scheme-handler.desktop changes
1211
const desktopFileVersion = 2;
@@ -26,36 +25,41 @@ function contextMenuPatch(tree, context) {
2625
}))
2726
tree.props.children.push(BdApi.ContextMenu.buildItem({
2827
type: "text", label: "open in mpv", action: () => {
29-
console.log("link is " + href);
28+
console.log("open-in-mpv: link is " + href);
3029

3130
if (settings.locallyInstalledVersion && settings.locallyInstalledVersion >= desktopFileVersion) {
31+
const newWindow = window.open(MPVSchemePrefix + href, "_blank", "noopener noreferrer");
3232

33-
electron.shell.openExternal(MPVSchemePrefix + href).then(() => {
33+
if (newWindow === null) { // is null because opens in external application
3434
BdApi.UI.showToast("" + href + " opened in mpv.", { type: "success" });
35-
console.log("success");
36-
}, (error) => {
37-
console.log(`failed to open ${MPVSchemePrefix}href`);
38-
console.log(error);
39-
}).catch((error) => {
40-
console.log(`failed to open ${MPVSchemePrefix}href`);
41-
console.log(error);
42-
})
35+
console.log("open-in-mpv: success");
36+
} else {
37+
BdApi.UI.showToast("" + href + " failed to open in mpv.", { type: "error" });
38+
console.log(`open-in-mpv: failed to open ${MPVSchemePrefix}${href} in mpv.`);
39+
}
4340
} else {
4441
BdApi.UI.showConfirmationModal("Open in mpv",
4542
"Open in mpv was updated or freshly installed. Please download and run setup.sh (again).",
4643
{
4744
confirmText: "Download setup.sh", onConfirm: () => {
48-
electron.shell.openExternal("https://raw.githubusercontent.com/binarynoise/open-in-mpv/main/setup.sh");
49-
settings.locallyInstalledVersion = desktopFileVersion;
50-
BdApi.Data.save("open-in-mpv", "settings", settings);
45+
downloadSetup();
5146
},
52-
})
47+
}
48+
)
5349
}
5450
},
5551
}))
5652
}
5753
}
5854

55+
function downloadSetup() {
56+
const newWindow = window.open("https://raw.githubusercontent.com/binarynoise/open-in-mpv/main/setup.sh", "_blank", "noopener noreferrer",);
57+
if (newWindow === null) { // is null because opens in external browser
58+
settings.locallyInstalledVersion = desktopFileVersion;
59+
BdApi.Data.save("open-in-mpv", "settings", settings);
60+
}
61+
}
62+
5963
const { React, React: { useState }, Webpack: { Filters, getModule } } = BdApi;
6064

6165
const TheBigBoyBundle = getModule(Filters.byProps("openModal", "FormSwitch", "Anchor"));

0 commit comments

Comments
 (0)