1+ import { existsSync } from "node:fs" ;
12import Module from "node:module" ;
23import { resolve } from "node:path" ;
34import { constants } from "@moonlight-mod/types" ;
@@ -7,15 +8,48 @@ const logger = moonlightNode.getLogger("disableSentry");
78
89const preloadPath = ipcRenderer . sendSync ( constants . ipcGetOldPreloadPath ) ;
910try {
10- const sentryPath = require . resolve ( resolve ( preloadPath , ".." , "node_modules" , "@sentry" , "electron" ) ) ;
11- require . cache [ sentryPath ] = new Module ( sentryPath , require . cache [ require . resolve ( preloadPath ) ] ) ;
12- require . cache [ sentryPath ] ! . exports = {
13- init : ( ) => { } ,
14- setTag : ( ) => { } ,
15- setUser : ( ) => { } ,
16- captureMessage : ( ) => { }
17- } ;
18- logger . debug ( "Stubbed Sentry node side!" ) ;
11+ if ( existsSync ( resolve ( preloadPath , ".." , "node_modules" , "@sentry" , "electron" ) ) ) {
12+ const sentryPath = require . resolve ( resolve ( preloadPath , ".." , "node_modules" , "@sentry" , "electron" ) ) ;
13+ require . cache [ sentryPath ] = new Module ( sentryPath , require . cache [ require . resolve ( preloadPath ) ] ) ;
14+ require . cache [ sentryPath ] ! . exports = {
15+ init : ( ) => { } ,
16+ setTag : ( ) => { } ,
17+ setUser : ( ) => { } ,
18+ captureMessage : ( ) => { }
19+ } ;
20+ logger . debug ( "Stubbed Sentry node side!" ) ;
21+ } else if ( existsSync ( resolve ( preloadPath , ".." , "bundle.js" ) ) ) {
22+ let realGetGlobalSentry : any ;
23+ Object . defineProperty ( Object . prototype , "getGlobalSentry" , {
24+ configurable : true ,
25+ set ( getGlobalSentry ) {
26+ realGetGlobalSentry = getGlobalSentry ;
27+ if ( this . init ) {
28+ const oldInit = this . init ;
29+ this . init = ( buildInfo : any , _sentry : any ) => {
30+ oldInit ( buildInfo ) ;
31+ } ;
32+
33+ Object . defineProperty ( this , "getGlobalSentry" , {
34+ configurable : true ,
35+ writable : true ,
36+ enumerable : true ,
37+ value : getGlobalSentry
38+ } ) ;
39+
40+ logger . debug ( "Patched crash reporter to not have Sentry" ) ;
41+
42+ // @ts -expect-error yes it in fact doesn't exist
43+ delete Object . prototype . getGlobalSentry ;
44+ }
45+ } ,
46+ get ( ) {
47+ return realGetGlobalSentry ;
48+ }
49+ } ) ;
50+ } else {
51+ logger . error ( "Cannot find Sentry, something in asar changed" ) ;
52+ }
1953} catch ( err ) {
2054 logger . error ( "Failed to stub Sentry:" , err ) ;
2155}
0 commit comments