@@ -3,13 +3,6 @@ import { Deeplink } from "electron-deeplink";
3
3
import isDev from "electron-is-dev" ;
4
4
import jwt_decode from 'jwt-decode' ;
5
5
6
- import slackApiStuff from "../../secretStuff/slackApiStuff" ;
7
-
8
- const clientId = slackApiStuff . clientId ;
9
- const clientSecret = slackApiStuff . clientSecret ;
10
- import dotenv from "dotenv" ;
11
- dotenv . config ( ) ;
12
-
13
6
/**
14
7
* Set `__statics` path to static files in production;
15
8
* The reason we are setting it here is that the path needs to be evaluated at runtime
@@ -22,7 +15,9 @@ if (process.env.PROD) {
22
15
23
16
let mainWindow ;
24
17
let authCode ;
18
+ const protocol = isDev ? "overvuedev" : "overvue" ;
25
19
20
+ // Used to console log for main process in production mode
26
21
function logEverywhere ( toBeLogged ) {
27
22
if ( isDev ) {
28
23
console . log ( toBeLogged ) ;
@@ -36,69 +31,24 @@ function logEverywhere(toBeLogged) {
36
31
}
37
32
}
38
33
39
- const protocol = isDev ? "overvuedev" : "overvue" ;
40
34
const deeplink = new Deeplink ( {
41
35
app,
42
36
mainWindow,
43
37
protocol,
44
38
isDev,
45
- debugLogging : true ,
46
- electronPath : "../../node_modules/electron/dist/electron.exe"
39
+ debugLogging : true
47
40
} ) ;
48
- // ipcMain.handle('slackAuth', slackAuth)
49
-
50
- // function customDeepLink() {
51
- // let deeplinkingUrl;
52
-
53
- // if (isDev && process.platform === 'win32') {
54
- // // Set the path of electron.exe and your app.
55
- // // These two additional parameters are only available on windows.
56
- // // Setting this is required to get this working in dev mode.
57
- // app.setAsDefaultProtocolClient('overvuedev', process.execPath, [
58
- // resolve(process.argv[1])
59
- // ]);
60
- // } else {
61
- // app.setAsDefaultProtocolClient('overvue');
62
- // }
63
-
64
- // app.on('open-url', function (event, url) {
65
- // event.preventDefault();
66
- // deeplinkingUrl = url;
67
- // });
68
-
69
- // // Force single application instance
70
- // const gotTheLock = app.requestSingleInstanceLock();
71
-
72
- // if (!gotTheLock) {
73
- // app.quit();
74
- // return;
75
- // } else {
76
- // app.on('second-instance', (e, argv) => {
77
- // if (process.platform !== 'darwin') {
78
- // // Find the arg that is our custom protocol url and store it
79
- // deeplinkingUrl = argv.find((arg) => arg.startsWith('overvuedev://test'));
80
- // }
81
-
82
- // if (myWindow) {
83
- // if (myWindow.isMinimized()) myWindow.restore();
84
- // myWindow.focus();
85
- // }
86
- // })
87
- // }
88
- // }
89
41
90
42
function getSlackAuth ( ) {
91
43
logEverywhere ( "inside getSlackAuth" ) ;
92
- // let chunkedTogether = ''
93
44
94
45
const authData = {
95
- client_id : clientId ,
96
- client_secret : clientSecret ,
46
+ client_id : process . env . SLACK_CLIENT_ID ,
47
+ client_secret : process . env . SLACK_CLIENT_SECRET ,
97
48
code : authCode ,
98
49
redirect_uri : isDev ? "overvuedev://test" : "overvue://slack"
99
50
} ;
100
51
logEverywhere ( authData . code ) ;
101
- // https://slack.com/api/openid.connect.token?client_id=2696943977700.2696948669268&client_secret=6a6206cc93da2e49243ee9683f958438&code=2696943977700.2713919388452.23b787dec24adec68eeca105f6b7d6e517425de1033a1b6bc5ba3e116b933619&redirect_uri=overvue://slack
102
52
const url =
103
53
"https://slack.com/api/openid.connect.token?" +
104
54
"client_id=" +
@@ -121,31 +71,16 @@ function getSlackAuth() {
121
71
} ) ;
122
72
123
73
request . on ( "response" , response => {
124
- logEverywhere ( `STATUS: ${ response . statusCode } ` )
125
- // logEverywhere(`HEADERS: ${JSON.stringify(response.headers)})`) //error
126
- // let body;
127
- logEverywhere ( "request.on response received" ) ;
128
- // logEverywhere('SEND #1')
129
- // mainWindow.webContents.send("tokenReceived", response);
130
-
131
- // logEverywhere('STATUS: ', response.statusCode)
132
- // logEverywhere(`HEADERS: ${JSON.stringify(response.headers)}`)
74
+ // logEverywhere("request.on response received");
133
75
response . on ( "end" , ( ) => {
134
76
logEverywhere ( "Response ended " ) ;
135
77
} ) ;
136
78
response . on ( "data" , data => {
137
- // logEverywhere(`response.on datas CHUNK: ${chunk}`)
138
- // logEverywhere("chunked");
139
- // logEverywhere(`data.id_token: ${data.id_token}`);
140
- // body = data;
141
79
logEverywhere ( "res on data " ) ;
142
80
const decoded = JSON . parse ( data . toString ( ) )
143
81
decoded . id_token = jwt_decode ( decoded . id_token )
144
-
145
- // chunkedTogether += data
146
-
147
82
// logEverywhere(data + ')'); //error
148
- logEverywhere ( `decoded: ${ decoded } ` )
83
+ logEverywhere ( `decoded in response.on data : ${ decoded } ` )
149
84
logEverywhere ( 'SEND #2' )
150
85
mainWindow . webContents . send ( "tokenReceived" , decoded ) ;
151
86
} ) ;
@@ -154,19 +89,19 @@ function getSlackAuth() {
154
89
}
155
90
156
91
function getSlackToken ( ) {
92
+ logEverywhere ( `process.env.SLACK_CLIENT_ID in electron-main: ${ process . env . SLACK_CLIENT_ID } ` ) ;
93
+ logEverywhere ( `process.env.SLACK_CLIENT_SECRET in electron-main: ${ process . env . SLACK_CLIENT_SECRET } ` ) ;
157
94
return deeplink . on ( "received" , link => {
158
- logEverywhere ( `auth worked here link: ${ link } ` ) ;
95
+ // logEverywhere(`auth worked here link: ${link}`);
159
96
authCode = link . split ( "=" ) [ 1 ] ;
160
- // authCode = link.split("=")[1].split(".")[2];
161
97
getSlackAuth ( ) ;
162
98
} ) ;
163
99
}
164
- // overvue://lkjasdgjkasdg-235235235.235235235.235235235235235235235235
165
100
166
101
function createWindow ( ) {
167
102
/**
168
- * Initial window options
169
- */
103
+ * Initial window options
104
+ */
170
105
171
106
mainWindow = new BrowserWindow ( {
172
107
width : 1000 ,
@@ -178,7 +113,7 @@ function createWindow() {
178
113
}
179
114
} ) ;
180
115
181
- logEverywhere ( `current protocol ${ deeplink . getProtocol ( ) } ` ) ;
116
+ logEverywhere ( `Current deeplink Protocol: ${ deeplink . getProtocol ( ) } ` ) ;
182
117
mainWindow . loadURL ( process . env . APP_URL ) ;
183
118
184
119
mainWindow . on ( "closed" , ( ) => {
@@ -189,7 +124,6 @@ function createWindow() {
189
124
app . on ( "ready" , ( ) => {
190
125
createWindow ( ) ;
191
126
getSlackToken ( ) ;
192
- logEverywhere ( `process.env.CLIENT_ID: ${ process . env . CLIENT_ID } ` ) ;
193
127
} ) ;
194
128
195
129
app . on ( "window-all-closed" , ( ) => {
@@ -202,6 +136,5 @@ app.on("activate", () => {
202
136
if ( mainWindow === null ) {
203
137
createWindow ( ) ;
204
138
getSlackToken ( ) ;
205
- logEverywhere ( `process.env: ${ process . env } ` ) ;
206
139
}
207
140
} ) ;
0 commit comments