@@ -3,13 +3,6 @@ import { Deeplink } from "electron-deeplink";
33import isDev from "electron-is-dev" ;
44import jwt_decode from 'jwt-decode' ;
55
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-
136/**
147 * Set `__statics` path to static files in production;
158 * 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) {
2215
2316let mainWindow ;
2417let authCode ;
18+ const protocol = isDev ? "overvuedev" : "overvue" ;
2519
20+ // Used to console log for main process in production mode
2621function logEverywhere ( toBeLogged ) {
2722 if ( isDev ) {
2823 console . log ( toBeLogged ) ;
@@ -36,69 +31,24 @@ function logEverywhere(toBeLogged) {
3631 }
3732}
3833
39- const protocol = isDev ? "overvuedev" : "overvue" ;
4034const deeplink = new Deeplink ( {
4135 app,
4236 mainWindow,
4337 protocol,
4438 isDev,
45- debugLogging : true ,
46- electronPath : "../../node_modules/electron/dist/electron.exe"
39+ debugLogging : true
4740} ) ;
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- // }
8941
9042function getSlackAuth ( ) {
9143 logEverywhere ( "inside getSlackAuth" ) ;
92- // let chunkedTogether = ''
9344
9445 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 ,
9748 code : authCode ,
9849 redirect_uri : isDev ? "overvuedev://test" : "overvue://slack"
9950 } ;
10051 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
10252 const url =
10353 "https://slack.com/api/openid.connect.token?" +
10454 "client_id=" +
@@ -121,31 +71,16 @@ function getSlackAuth() {
12171 } ) ;
12272
12373 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");
13375 response . on ( "end" , ( ) => {
13476 logEverywhere ( "Response ended " ) ;
13577 } ) ;
13678 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;
14179 logEverywhere ( "res on data " ) ;
14280 const decoded = JSON . parse ( data . toString ( ) )
14381 decoded . id_token = jwt_decode ( decoded . id_token )
144-
145- // chunkedTogether += data
146-
14782 // logEverywhere(data + ')'); //error
148- logEverywhere ( `decoded: ${ decoded } ` )
83+ logEverywhere ( `decoded in response.on data : ${ decoded } ` )
14984 logEverywhere ( 'SEND #2' )
15085 mainWindow . webContents . send ( "tokenReceived" , decoded ) ;
15186 } ) ;
@@ -154,19 +89,19 @@ function getSlackAuth() {
15489}
15590
15691function 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 } ` ) ;
15794 return deeplink . on ( "received" , link => {
158- logEverywhere ( `auth worked here link: ${ link } ` ) ;
95+ // logEverywhere(`auth worked here link: ${link}`);
15996 authCode = link . split ( "=" ) [ 1 ] ;
160- // authCode = link.split("=")[1].split(".")[2];
16197 getSlackAuth ( ) ;
16298 } ) ;
16399}
164- // overvue://lkjasdgjkasdg-235235235.235235235.235235235235235235235235
165100
166101function createWindow ( ) {
167102 /**
168- * Initial window options
169- */
103+ * Initial window options
104+ */
170105
171106 mainWindow = new BrowserWindow ( {
172107 width : 1000 ,
@@ -178,7 +113,7 @@ function createWindow() {
178113 }
179114 } ) ;
180115
181- logEverywhere ( `current protocol ${ deeplink . getProtocol ( ) } ` ) ;
116+ logEverywhere ( `Current deeplink Protocol: ${ deeplink . getProtocol ( ) } ` ) ;
182117 mainWindow . loadURL ( process . env . APP_URL ) ;
183118
184119 mainWindow . on ( "closed" , ( ) => {
@@ -189,7 +124,6 @@ function createWindow() {
189124app . on ( "ready" , ( ) => {
190125 createWindow ( ) ;
191126 getSlackToken ( ) ;
192- logEverywhere ( `process.env.CLIENT_ID: ${ process . env . CLIENT_ID } ` ) ;
193127} ) ;
194128
195129app . on ( "window-all-closed" , ( ) => {
@@ -202,6 +136,5 @@ app.on("activate", () => {
202136 if ( mainWindow === null ) {
203137 createWindow ( ) ;
204138 getSlackToken ( ) ;
205- logEverywhere ( `process.env: ${ process . env } ` ) ;
206139 }
207140} ) ;
0 commit comments