@@ -2,10 +2,12 @@ import { app, BrowserWindow, net, shell, ipcMain } from "electron";
2
2
import { Deeplink } from "electron-deeplink" ;
3
3
import isDev from "electron-is-dev" ;
4
4
5
- import slackApiStuff from ' ../../secretStuff/slackApiStuff'
5
+ import slackApiStuff from " ../../secretStuff/slackApiStuff" ;
6
6
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 ( ) ;
9
11
10
12
/**
11
13
* Set `__statics` path to static files in production;
@@ -20,103 +22,127 @@ if (process.env.PROD) {
20
22
let mainWindow ;
21
23
let authCode ;
22
24
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
+ }
27
35
}
28
36
}
29
37
30
- const protocol = isDev ? ' overvuedev' : ' overvue'
38
+ const protocol = isDev ? " overvuedev" : " overvue" ;
31
39
const deeplink = new Deeplink ( {
32
40
app,
33
41
mainWindow,
34
42
protocol,
35
- isDev ,
43
+ isDev,
36
44
debugLogging : true ,
37
- electronPath : ' ../../node_modules/electron/dist/electron.exe'
45
+ electronPath : " ../../node_modules/electron/dist/electron.exe"
38
46
} ) ;
39
47
// ipcMain.handle('slackAuth', slackAuth)
40
48
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" ) ;
81
91
82
- function getSlackAuth ( ) {
83
92
const authData = {
84
93
client_id : clientId ,
85
94
client_secret : clientSecret ,
86
95
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 ) ;
90
111
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 ,
97
114
headers : {
98
- ' Content-Type' : ' application/x-www-form-urlencoded' ,
115
+ " Content-Type" : " application/x-www-form-urlencoded"
99
116
// 'Content-Length': authData.length
100
117
}
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 ( ) ;
113
138
}
114
139
115
- function getSlackToken ( ) {
140
+ function getSlackToken ( ) {
116
141
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 ( ) ;
120
146
} ) ;
121
147
}
122
148
@@ -135,18 +161,18 @@ function createWindow() {
135
161
}
136
162
} ) ;
137
163
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 ) ;
140
166
141
167
mainWindow . on ( "closed" , ( ) => {
142
168
mainWindow = null ;
143
169
} ) ;
144
170
}
145
171
146
172
app . 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 } ` ) ;
150
176
} ) ;
151
177
152
178
app . on ( "window-all-closed" , ( ) => {
@@ -157,8 +183,8 @@ app.on("window-all-closed", () => {
157
183
158
184
app . on ( "activate" , ( ) => {
159
185
if ( mainWindow === null ) {
160
- createWindow ( )
161
- getSlackToken ( )
162
- logEverywhere ( " process.env: " , process . env )
186
+ createWindow ( ) ;
187
+ getSlackToken ( ) ;
188
+ logEverywhere ( ` process.env: ${ process . env } ` ) ;
163
189
}
164
- } )
190
+ } ) ;
0 commit comments