@@ -105,116 +105,8 @@ ipcMain.handle(SHELL_OPCODE.TRASH_ITEM, async (event, ...args) => {
105105app . disableHardwareAcceleration ( )
106106
107107
108- const REDIRECT_URI_PREFIX = 'https://login.microsoftonline.com/common/oauth2/nativeclient?'
109-
110- // Microsoft Auth Login
111- let msftAuthWindow
112- let msftAuthSuccess
113- let msftAuthViewSuccess
114- let msftAuthViewOnClose
115- ipcMain . on ( MSFT_OPCODE . OPEN_LOGIN , ( ipcEvent , ...arguments_ ) => {
116- if ( msftAuthWindow ) {
117- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . ALREADY_OPEN , msftAuthViewOnClose )
118- return
119- }
120- msftAuthSuccess = false
121- msftAuthViewSuccess = arguments_ [ 0 ]
122- msftAuthViewOnClose = arguments_ [ 1 ]
123- msftAuthWindow = new BrowserWindow ( {
124- title : 'Microsoft Login' ,
125- backgroundColor : '#222222' ,
126- width : 520 ,
127- height : 600 ,
128- frame : true ,
129- icon : getPlatformIcon ( 'SealCircle' )
130- } )
131-
132- msftAuthWindow . on ( 'closed' , ( ) => {
133- msftAuthWindow = undefined
134- } )
135-
136- msftAuthWindow . on ( 'close' , ( ) => {
137- if ( ! msftAuthSuccess ) {
138- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . NOT_FINISHED , msftAuthViewOnClose )
139- }
140- } )
141-
142- msftAuthWindow . webContents . on ( 'did-navigate' , ( _ , uri ) => {
143- if ( uri . startsWith ( REDIRECT_URI_PREFIX ) ) {
144- let queries = uri . substring ( REDIRECT_URI_PREFIX . length ) . split ( '#' , 1 ) . toString ( ) . split ( '&' )
145- let queryMap = { }
146-
147- queries . forEach ( query => {
148- const [ name , value ] = query . split ( '=' )
149- queryMap [ name ] = decodeURI ( value )
150- } )
151-
152- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . SUCCESS , queryMap , msftAuthViewSuccess )
153-
154- msftAuthSuccess = true
155- msftAuthWindow . close ( )
156- msftAuthWindow = null
157- }
158- } )
159-
160- msftAuthWindow . removeMenu ( )
161- msftAuthWindow . loadURL ( `https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?prompt=select_account&client_id=${ AZURE_CLIENT_ID } &response_type=code&scope=XboxLive.signin%20offline_access&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient` )
162- } )
163-
164- // Microsoft Auth Logout
165- let msftLogoutWindow
166- let msftLogoutSuccess
167- let msftLogoutSuccessSent
168- ipcMain . on ( MSFT_OPCODE . OPEN_LOGOUT , ( ipcEvent , uuid , isLastAccount ) => {
169- if ( msftLogoutWindow ) {
170- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGOUT , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . ALREADY_OPEN )
171- return
172- }
173-
174- msftLogoutSuccess = false
175- msftLogoutSuccessSent = false
176- msftLogoutWindow = new BrowserWindow ( {
177- title : 'Microsoft Logout' ,
178- backgroundColor : '#222222' ,
179- width : 520 ,
180- height : 600 ,
181- frame : true ,
182- icon : getPlatformIcon ( 'SealCircle' )
183- } )
184-
185- msftLogoutWindow . on ( 'closed' , ( ) => {
186- msftLogoutWindow = undefined
187- } )
188-
189- msftLogoutWindow . on ( 'close' , ( ) => {
190- if ( ! msftLogoutSuccess ) {
191- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGOUT , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . NOT_FINISHED )
192- } else if ( ! msftLogoutSuccessSent ) {
193- msftLogoutSuccessSent = true
194- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGOUT , MSFT_REPLY_TYPE . SUCCESS , uuid , isLastAccount )
195- }
196- } )
197-
198- msftLogoutWindow . webContents . on ( 'did-navigate' , ( _ , uri ) => {
199- if ( uri . startsWith ( 'https://login.microsoftonline.com/common/oauth2/v2.0/logoutsession' ) ) {
200- msftLogoutSuccess = true
201- setTimeout ( ( ) => {
202- if ( ! msftLogoutSuccessSent ) {
203- msftLogoutSuccessSent = true
204- ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGOUT , MSFT_REPLY_TYPE . SUCCESS , uuid , isLastAccount )
205- }
108+
206109
207- if ( msftLogoutWindow ) {
208- msftLogoutWindow . close ( )
209- msftLogoutWindow = null
210- }
211- } , 5000 )
212- }
213- } )
214-
215- msftLogoutWindow . removeMenu ( )
216- msftLogoutWindow . loadURL ( 'https://login.microsoftonline.com/common/oauth2/v2.0/logout' )
217- } )
218110
219111// Keep a global reference of the window object, if you don't, the window will
220112// be closed automatically when the JavaScript object is garbage collected.
@@ -223,8 +115,8 @@ let win
223115function createWindow ( ) {
224116
225117 win = new BrowserWindow ( {
226- width : 980 ,
227- height : 552 ,
118+ width : 1143 ,
119+ height : 700 ,
228120 icon : getPlatformIcon ( 'SealCircle' ) ,
229121 frame : false ,
230122 webPreferences : {
@@ -350,4 +242,83 @@ app.on('activate', () => {
350242 if ( win === null ) {
351243 createWindow ( )
352244 }
245+ } )
246+
247+ const REDIRECT_URI_PREFIX = 'https://login.microsoftonline.com/common/oauth2/nativeclient?'
248+
249+ // Microsoft Auth Login
250+ let msftAuthWindow
251+ let msftAuthSuccess
252+ let msftAuthViewSuccess
253+ let msftAuthViewOnClose
254+ ipcMain . on ( MSFT_OPCODE . OPEN_LOGIN , ( ipcEvent , ...arguments_ ) => {
255+ /*
256+ Clear cookies from live.com and github.com from Microsoft Login, since there isn't an actual way to invalidate Microsoft access token
257+ */
258+ session . defaultSession . cookies . get ( { domain : 'live.com' } ) . then ( ( cookies ) => {
259+ for ( let cookie of cookies ) {
260+ let urlcookie = `http${ cookie . secure ? "s" : "" } ://${ cookie . domain . replace ( / $ \. / , "" ) + cookie . path } ` ;
261+ session . defaultSession . cookies . remove ( urlcookie , cookie . name )
262+ }
263+ } )
264+ session . defaultSession . cookies . get ( { domain : 'github.com' } ) . then ( ( cookies ) => {
265+ for ( let cookie of cookies ) {
266+ let urlcookie = `http${ cookie . secure ? "s" : "" } ://${ cookie . domain . replace ( / $ \. / , "" ) + cookie . path } ` ;
267+ session . defaultSession . cookies . remove ( urlcookie , cookie . name )
268+ }
269+ } )
270+ if ( msftAuthWindow ) {
271+ ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . ALREADY_OPEN , msftAuthViewOnClose )
272+ return
273+ }
274+ msftAuthSuccess = false
275+ msftAuthViewSuccess = arguments_ [ 0 ]
276+ msftAuthViewOnClose = arguments_ [ 1 ]
277+ msftAuthWindow = new BrowserWindow ( {
278+ parent : win ,
279+ modal : true ,
280+ resizable : false ,
281+ title : 'Microsoft Login' ,
282+ backgroundColor : '#222222' ,
283+ width : 520 ,
284+ height : 700 ,
285+ frame : true ,
286+ icon : getPlatformIcon ( 'SealCircle' )
287+ } )
288+
289+ msftAuthWindow . on ( 'closed' , ( ) => {
290+ msftAuthWindow = undefined
291+ } )
292+
293+ msftAuthWindow . on ( 'close' , ( ) => {
294+ if ( ! msftAuthSuccess ) {
295+ ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . ERROR , MSFT_ERROR . NOT_FINISHED , msftAuthViewOnClose )
296+ }
297+ } )
298+
299+ msftAuthWindow . webContents . on ( 'did-navigate' , ( _ , uri ) => {
300+ if ( uri . startsWith ( REDIRECT_URI_PREFIX ) ) {
301+ let queries = uri . substring ( REDIRECT_URI_PREFIX . length ) . split ( '#' , 1 ) . toString ( ) . split ( '&' )
302+ let queryMap = { }
303+
304+ queries . forEach ( query => {
305+ const [ name , value ] = query . split ( '=' )
306+ queryMap [ name ] = decodeURI ( value )
307+ } )
308+
309+ ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGIN , MSFT_REPLY_TYPE . SUCCESS , queryMap , msftAuthViewSuccess )
310+
311+ msftAuthSuccess = true
312+ msftAuthWindow . close ( )
313+ msftAuthWindow = null
314+ }
315+ } )
316+
317+ msftAuthWindow . removeMenu ( )
318+ msftAuthWindow . loadURL ( `https://login.live.com/oauth20_authorize.srf?prompt=select_account&client_id=${ AZURE_CLIENT_ID } &response_type=code&scope=XboxLive.signin%20offline_access&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient&cobrandid=8058f65d-ce06-4c30-9559-473c9275a65d` ) //Cobrandid adds the Minecraft branding on the login page
319+ } )
320+
321+ // Microsoft Auth Logout
322+ ipcMain . on ( MSFT_OPCODE . OPEN_LOGOUT , ( ipcEvent , uuid , isLastAccount ) => {
323+ ipcEvent . reply ( MSFT_OPCODE . REPLY_LOGOUT , MSFT_REPLY_TYPE . SUCCESS , uuid , isLastAccount ) //Just reply to the event, since logout pop up isn't that much useful
353324} )
0 commit comments