@@ -2,10 +2,12 @@ import { app, BrowserWindow, net, shell, ipcMain } from "electron";
22import { Deeplink } from "electron-deeplink" ;
33import isDev from "electron-is-dev" ;
44
5- import slackApiStuff from ' ../../secretStuff/slackApiStuff'
5+ import slackApiStuff from " ../../secretStuff/slackApiStuff" ;
66
7- const clientId = slackApiStuff . clientId
8- const clientSecret = slackApiStuff . clientSecret
7+ const clientId = slackApiStuff . clientId ;
8+ const clientSecret = slackApiStuff . clientSecret ;
9+ import dotenv from "dotenv" ;
10+ dotenv . config ( ) ;
911
1012/**
1113 * Set `__statics` path to static files in production;
@@ -20,103 +22,127 @@ if (process.env.PROD) {
2022let mainWindow ;
2123let authCode ;
2224
23- function logEverywhere ( ...toBeLogged ) {
24- console . log ( ...toBeLogged ) ;
25- if ( mainWindow && mainWindow . webContents ) {
26- mainWindow . webContents . executeJavaScript ( `console.log("${ toBeLogged } ")` ) ;
25+ function logEverywhere ( toBeLogged ) {
26+ if ( isDev ) {
27+ console . log ( toBeLogged ) ;
28+ } else {
29+ console . log ( toBeLogged ) ;
30+ if ( mainWindow && mainWindow . webContents ) {
31+ mainWindow . webContents . executeJavaScript (
32+ 'console.log("' + toBeLogged + '" )'
33+ ) ;
34+ }
2735 }
2836}
2937
30- const protocol = isDev ? ' overvuedev' : ' overvue'
38+ const protocol = isDev ? " overvuedev" : " overvue" ;
3139const deeplink = new Deeplink ( {
3240 app,
3341 mainWindow,
3442 protocol,
35- isDev ,
43+ isDev,
3644 debugLogging : true ,
37- electronPath : ' ../../node_modules/electron/dist/electron.exe'
45+ electronPath : " ../../node_modules/electron/dist/electron.exe"
3846} ) ;
3947// ipcMain.handle('slackAuth', slackAuth)
4048
41- let deeplinkingUrl ;
42-
43- function customDeepLink ( ) {
44- if ( isDev && process . platform === 'win32' ) {
45- // Set the path of electron.exe and your app.
46- // These two additional parameters are only available on windows.
47- // Setting this is required to get this working in dev mode.
48- app . setAsDefaultProtocolClient ( 'overvuedev' , process . execPath , [
49- resolve ( process . argv [ 1 ] )
50- ] ) ;
51- } else {
52- app . setAsDefaultProtocolClient ( 'overvue' ) ;
53- }
54-
55- app . on ( 'open-url' , function ( event , url ) {
56- event . preventDefault ( ) ;
57- deeplinkingUrl = url ;
58- } ) ;
59-
60- // Force single application instance
61- const gotTheLock = app . requestSingleInstanceLock ( ) ;
62-
63- if ( ! gotTheLock ) {
64- app . quit ( ) ;
65- return ;
66- } else {
67- app . on ( 'second-instance' , ( e , argv ) => {
68- if ( process . platform !== 'darwin' ) {
69- // Find the arg that is our custom protocol url and store it
70- deeplinkingUrl = argv . find ( ( arg ) => arg . startsWith ( 'overvuedev://test' ) ) ;
71- }
72-
73- if ( myWindow ) {
74- if ( myWindow . isMinimized ( ) ) myWindow . restore ( ) ;
75- myWindow . focus ( ) ;
76- }
77- } )
78- }
79- }
80-
49+ // function customDeepLink() {
50+ // let deeplinkingUrl;
51+
52+ // if (isDev && process.platform === 'win32') {
53+ // // Set the path of electron.exe and your app.
54+ // // These two additional parameters are only available on windows.
55+ // // Setting this is required to get this working in dev mode.
56+ // app.setAsDefaultProtocolClient('overvuedev', process.execPath, [
57+ // resolve(process.argv[1])
58+ // ]);
59+ // } else {
60+ // app.setAsDefaultProtocolClient('overvue');
61+ // }
62+
63+ // app.on('open-url', function (event, url) {
64+ // event.preventDefault();
65+ // deeplinkingUrl = url;
66+ // });
67+
68+ // // Force single application instance
69+ // const gotTheLock = app.requestSingleInstanceLock();
70+
71+ // if (!gotTheLock) {
72+ // app.quit();
73+ // return;
74+ // } else {
75+ // app.on('second-instance', (e, argv) => {
76+ // if (process.platform !== 'darwin') {
77+ // // Find the arg that is our custom protocol url and store it
78+ // deeplinkingUrl = argv.find((arg) => arg.startsWith('overvuedev://test'));
79+ // }
80+
81+ // if (myWindow) {
82+ // if (myWindow.isMinimized()) myWindow.restore();
83+ // myWindow.focus();
84+ // }
85+ // })
86+ // }
87+ // }
88+
89+ function getSlackAuth ( ) {
90+ logEverywhere ( "inside getSlackAuth" ) ;
8191
82- function getSlackAuth ( ) {
8392 const authData = {
8493 client_id : clientId ,
8594 client_secret : clientSecret ,
8695 code : authCode ,
87- redirect_uri : isDev ? 'overvuedev://test' : 'overvue://slack'
88- }
89-
96+ redirect_uri : isDev ? "overvuedev://test" : "overvue://slack"
97+ } ;
98+ logEverywhere ( authData . code )
99+ // https://slack.com/api/openid.connect.token?client_id=2696943977700.2696948669268&client_secret=6a6206cc93da2e49243ee9683f958438&code=2696943977700.2713919388452.23b787dec24adec68eeca105f6b7d6e517425de1033a1b6bc5ba3e116b933619&redirect_uri=overvue://slack
100+ const url =
101+ "https://slack.com/api/openid.connect.token?" +
102+ "client_id=" +
103+ authData . client_id +
104+ "&client_secret=" +
105+ authData . client_secret +
106+ "&code=" +
107+ authData . code +
108+ "&redirect_uri=" +
109+ authData . redirect_uri ;
110+ logEverywhere ( url ) ;
90111 const request = net . request ( {
91- method : 'POST' ,
92- url : 'https://slack.com/api/openid.connect.token?' +
93- 'client_id=' + authData . client_id +
94- '&client_secret=' + authData . client_secret +
95- '&code=' + authData . authCode +
96- '&redirect_uri=' + authData . redirect_uri ,
112+ method : "POST" ,
113+ url : url ,
97114 headers : {
98- ' Content-Type' : ' application/x-www-form-urlencoded' ,
115+ " Content-Type" : " application/x-www-form-urlencoded"
99116 // 'Content-Length': authData.length
100117 }
101- } )
102-
103- request . on ( 'response' , ( response ) => {
104- logEverywhere ( 'RESPONSE RECEIVED SON' )
105- JSON . parse ( response )
106- . then ( data => {
107- logEverywhere ( 'response with token: ' )
108- logEverywhere ( response )
109- mainWindow . webContents . send ( 'tokenReceived' , response )
110- } )
111- } )
112- request . end ( )
118+ } ) ;
119+
120+ request . on ( "response" , response => {
121+ let body ;
122+ logEverywhere ( "RESPONSE RECEIVED SON" ) ;
123+ mainWindow . webContents . send ( "tokenReceived" , response ) ;
124+ // logEverywhere('STATUS: ', response.statusCode)
125+ // logEverywhere(`HEADERS: ${JSON.stringify(response.headers)}`)
126+ response . on ( "data" , data => {
127+ // logEverywhere(`response.on datas CHUNK: ${chunk}`)
128+ logEverywhere ( "chunked" ) ;
129+ logEverywhere ( data ) ;
130+ body = data ;
131+ } ) ;
132+ response . on ( "end" , ( ) => {
133+ logEverywhere ( "Response ended " ) ;
134+ mainWindow . webContents . send ( "tokenReceived" , body ) ;
135+ } ) ;
136+ } ) ;
137+ request . end ( ) ;
113138}
114139
115- function getSlackToken ( ) {
140+ function getSlackToken ( ) {
116141 return deeplink . on ( "received" , link => {
117- logEverywhere ( 'auth worked here link: ' , link )
118- authCode = link . split ( '=' ) [ 1 ]
119- getSlackAuth ( )
142+ logEverywhere ( `auth worked here link: ${ link } ` ) ;
143+ authCode = link . split ( "=" ) [ 1 ] ;
144+ // authCode = link.split("=")[1].split(".")[2];
145+ getSlackAuth ( ) ;
120146 } ) ;
121147}
122148
@@ -135,18 +161,18 @@ function createWindow() {
135161 }
136162 } ) ;
137163
138- logEverywhere ( ' current protocol ' , deeplink . getProtocol ( ) )
139- mainWindow . loadURL ( process . env . APP_URL )
164+ logEverywhere ( ` current protocol ${ deeplink . getProtocol ( ) } ` ) ;
165+ mainWindow . loadURL ( process . env . APP_URL ) ;
140166
141167 mainWindow . on ( "closed" , ( ) => {
142168 mainWindow = null ;
143169 } ) ;
144170}
145171
146172app . on ( "ready" , ( ) => {
147- createWindow ( )
148- getSlackToken ( )
149- logEverywhere ( " process.env: " , process . env )
173+ createWindow ( ) ;
174+ getSlackToken ( ) ;
175+ logEverywhere ( ` process.env.CLIENT_ID: ${ process . env . CLIENT_ID } ` ) ;
150176} ) ;
151177
152178app . on ( "window-all-closed" , ( ) => {
@@ -157,8 +183,8 @@ app.on("window-all-closed", () => {
157183
158184app . on ( "activate" , ( ) => {
159185 if ( mainWindow === null ) {
160- createWindow ( )
161- getSlackToken ( )
162- logEverywhere ( " process.env: " , process . env )
186+ createWindow ( ) ;
187+ getSlackToken ( ) ;
188+ logEverywhere ( ` process.env: ${ process . env } ` ) ;
163189 }
164- } )
190+ } ) ;
0 commit comments