66 */
77
88'use strict' ;
9+ const electron = require ( 'electron' ) ;
910
10- const settings = { showAgain : true } ;
11+ // change this when mpv-scheme-handler.desktop changes
12+ const desktopFileVersion = 2 ;
13+
14+ const settings = {
15+ locallyInstalledVersion : null
16+ } ;
1117
1218const MPVSchemePrefix = "mpv://watch#" ;
1319
@@ -21,33 +27,30 @@ function contextMenuPatch(tree, context) {
2127 tree . props . children . push ( BdApi . ContextMenu . buildItem ( {
2228 type : "text" , label : "open in mpv" , action : ( ) => {
2329 console . log ( "link is " + href ) ;
24- const electron = require ( 'electron' ) ;
25-
26- electron . shell . openExternal ( MPVSchemePrefix + href ) . then ( ( ) => {
27- if ( settings . showAgain !== false ) {
28- BdApi . UI . showConfirmationModal ( "Open in mpv" ,
29- "Successfully opened " + href + " in mpv. Did nothing happen? Download and run setup.sh" ,
30- {
31- confirmText : "Download setup.sh" , onConfirm : ( ) => {
32- electron . shell . openExternal ( 'https://raw.githubusercontent.com/binarynoise/open-in-mpv/main/setup.sh' ) ;
33- } ,
34-
35- cancelText : "Ok, don't show again" , onCancel : ( ) => {
36- settings . showAgain = false ;
37- BdApi . Data . save ( "open-in-mpv" , "settings" , settings ) ;
38- } ,
39- } )
40- } else {
30+
31+ if ( settings . locallyInstalledVersion && settings . locallyInstalledVersion >= desktopFileVersion ) {
32+
33+ electron . shell . openExternal ( MPVSchemePrefix + href ) . then ( ( ) => {
4134 BdApi . UI . showToast ( "" + href + " opened in mpv." , { type : "success" } ) ;
42- }
43- console . log ( "success" ) ;
44- } , ( error ) => {
45- console . log ( `failed to open ${ MPVSchemePrefix } href` ) ;
46- console . log ( error ) ;
47- } ) . catch ( ( error ) => {
48- console . log ( `failed to open ${ MPVSchemePrefix } href` ) ;
49- console . log ( error ) ;
50- } )
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+ } )
43+ } else {
44+ BdApi . UI . showConfirmationModal ( "Open in mpv" ,
45+ "Open in mpv was updated or freshly installed. Please download and run setup.sh (again)." ,
46+ {
47+ 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 ) ;
51+ } ,
52+ } )
53+ }
5154 } ,
5255 } ) )
5356 }
@@ -89,7 +92,7 @@ module.exports = () => ({
8992 BdApi . ContextMenu . patch ( "message" , contextMenuPatch ) ;
9093 } , stop ( ) {
9194 BdApi . ContextMenu . unpatch ( "message" , contextMenuPatch ) ;
92- } , getSettingsPanel : ( ) => React . createElement ( SettingComponent ) ,
95+ } , // getSettingsPanel: () => React.createElement(SettingComponent),
9396} ) ;
9497
9598function isEmpty ( obj ) {
0 commit comments