Skip to content

Commit 0f98c59

Browse files
author
Jeffrey Sul
committed
merge with slack Oauth
2 parents fce6b19 + 9b4fc4a commit 0f98c59

File tree

10 files changed

+33784
-734
lines changed

10 files changed

+33784
-734
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#secret Api keys, Webhook URLs etc
2+
slackApiStuff.js
3+
.env
4+
#
15
.quasar
26
.DS_Store
37
.thumbs.db
@@ -32,4 +36,7 @@ build/
3236
dist/
3337
node_modules/
3438
aws-exports.js
35-
awsconfiguration.json
39+
awsconfiguration.json
40+
41+
#secret Api keys, Webhook URLs etc
42+
slackApiStuff.js

package-lock.json

Lines changed: 33446 additions & 709 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "overvue",
3-
"version": "3.0.0",
3+
"version": "4.0.0",
44
"description": "Vue Prototype DevTool",
55
"productName": "OverVue",
66
"cordovaId": "org.cordova.quasar.app",
@@ -26,6 +26,8 @@
2626
"aws-amplify-vue": "^0.2.13",
2727
"aws-appsync": "^1.8.1",
2828
"dot-prop": "^6.0.0",
29+
"dotenv": "^10.0.0",
30+
"electron-deeplink": "^1.0.8",
2931
"fs-extra": "^8.1.0",
3032
"localforage": "^1.7.3",
3133
"lodash": "^4.17.21",
@@ -59,6 +61,8 @@
5961
"electron-builder": "^22.11.10",
6062
"electron-debug": "^3.0.1",
6163
"electron-devtools-installer": "^2.2.4",
64+
"electron-is-dev": "^2.0.0",
65+
"electron-packager": "^14.2.1",
6266
"eslint": "^7.32.0",
6367
"eslint-loader": "^2.1.1",
6468
"eslint-plugin-vue": "^5.0.0",

quasar.conf.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// https://quasar.dev/quasar-cli/quasar-conf-js
33

44
module.exports = function (ctx) {
5+
console.log('webpack\'s context parameter: ', ctx)
56
return {
67
// app boot file (/src/boot)
78
// --> boot files are part of "main.js"
@@ -158,7 +159,7 @@ module.exports = function (ctx) {
158159
},
159160

160161
electron: {
161-
bundler: 'builder',
162+
bundler: 'packager',
162163
// bundler: 'builder', // or 'packager'
163164

164165
extendWebpack (cfg) {
@@ -170,10 +171,10 @@ module.exports = function (ctx) {
170171
// https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#options
171172

172173
// OS X / Mac App Store
173-
// appBundleId: '',
174+
appBundleId: 'overvue',
174175
// appCategoryType: '',
175176
// osxSign: '',
176-
// protocol: 'myapp://path',
177+
protocol: 'overvue'
177178

178179
// Windows only
179180
// win32metadata: { ... }
@@ -185,7 +186,13 @@ module.exports = function (ctx) {
185186
appId: 'com.electron.OverVue',
186187
win: {
187188
target: 'nsis'
188-
}
189+
},
190+
protocols: [
191+
{
192+
name: 'overvue',
193+
schemes: ['overvue']
194+
}
195+
]
189196
}
190197
}
191198
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create a file, slackApiStuff.js, in this directory for sensitive variables like api keys, webhook urls, etc
2+
and make it similar to this:
3+
4+
const slackApiStuff = {};
5+
slackApiStuff.slackWebhookURL =
6+
"ENTER WEBHOOK HERE";
7+
8+
slackApiStuff.oauthURL = 'ENTER OAUTH URL HERE';
9+
10+
export default slackApiStuff;
Lines changed: 162 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,157 @@
1-
import { app, BrowserWindow } from 'electron'
1+
import { app, BrowserWindow, net, shell, ipcMain } from "electron";
2+
import { Deeplink } from "electron-deeplink";
3+
import isDev from "electron-is-dev";
4+
5+
import slackApiStuff from "../../secretStuff/slackApiStuff";
6+
7+
const clientId = slackApiStuff.clientId;
8+
const clientSecret = slackApiStuff.clientSecret;
9+
import dotenv from "dotenv";
10+
dotenv.config();
211

312
/**
413
* Set `__statics` path to static files in production;
514
* The reason we are setting it here is that the path needs to be evaluated at runtime
615
*/
716
if (process.env.PROD) {
8-
global.__statics = require('path')
9-
.join(__dirname, 'statics')
10-
.replace(/\\/g, '\\\\')
17+
global.__statics = require("path")
18+
.join(__dirname, "statics")
19+
.replace(/\\/g, "\\\\");
1120
}
1221

13-
let mainWindow
22+
let mainWindow;
23+
let authCode;
24+
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+
}
35+
}
36+
}
37+
38+
const protocol = isDev ? "overvuedev" : "overvue";
39+
const deeplink = new Deeplink({
40+
app,
41+
mainWindow,
42+
protocol,
43+
isDev,
44+
debugLogging: true,
45+
electronPath: "../../node_modules/electron/dist/electron.exe"
46+
});
47+
// ipcMain.handle('slackAuth', slackAuth)
48+
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();
1470

15-
function createWindow () {
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");
91+
92+
const authData = {
93+
client_id: clientId,
94+
client_secret: clientSecret,
95+
code: authCode,
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+
"&grant_type=authorization_key" +
109+
"&redirect_uri=" +
110+
authData.redirect_uri;
111+
logEverywhere(url);
112+
const request = net.request({
113+
method: "POST",
114+
url: url,
115+
headers: {
116+
"Content-Type": "application/x-www-form-urlencoded"
117+
// 'Content-Length': authData.length
118+
}
119+
});
120+
121+
request.on("response", response => {
122+
let body;
123+
logEverywhere("RESPONSE RECEIVED SON");
124+
mainWindow.webContents.send("tokenReceived", response);
125+
// logEverywhere('STATUS: ', response.statusCode)
126+
// logEverywhere(`HEADERS: ${JSON.stringify(response.headers)}`)
127+
response.on("data", data => {
128+
// logEverywhere(`response.on datas CHUNK: ${chunk}`)
129+
logEverywhere("chunked");
130+
logEverywhere(data);
131+
body = data;
132+
});
133+
response.on("end", () => {
134+
logEverywhere("Response ended ");
135+
mainWindow.webContents.send("tokenReceived", body);
136+
});
137+
});
138+
request.end();
139+
}
140+
141+
function getSlackToken() {
142+
return deeplink.on("received", link => {
143+
logEverywhere(`auth worked here link: ${link}`);
144+
// authCode = link.split("=")[1];
145+
authCode = link.split("=")[1].split(".")[2];
146+
getSlackAuth();
147+
});
148+
}
149+
150+
function createWindow() {
16151
/**
17152
* Initial window options
18153
*/
154+
19155
mainWindow = new BrowserWindow({
20156
width: 1000,
21157
height: 600,
@@ -24,25 +160,32 @@ function createWindow () {
24160
nodeIntegration: true,
25161
webSecurity: false
26162
}
27-
})
163+
});
28164

29-
mainWindow.loadURL(process.env.APP_URL)
165+
logEverywhere(`current protocol ${deeplink.getProtocol()}`);
166+
mainWindow.loadURL(process.env.APP_URL);
30167

31-
mainWindow.on('closed', () => {
32-
mainWindow = null
33-
})
168+
mainWindow.on("closed", () => {
169+
mainWindow = null;
170+
});
34171
}
35172

36-
app.on('ready', createWindow)
173+
app.on("ready", () => {
174+
createWindow();
175+
getSlackToken();
176+
logEverywhere(`process.env.CLIENT_ID: ${process.env.CLIENT_ID}`);
177+
});
37178

38-
app.on('window-all-closed', () => {
39-
if (process.platform !== 'darwin') {
40-
app.quit()
179+
app.on("window-all-closed", () => {
180+
if (process.platform !== "darwin") {
181+
app.quit();
41182
}
42-
})
183+
});
43184

44-
app.on('activate', () => {
185+
app.on("activate", () => {
45186
if (mainWindow === null) {
46-
createWindow()
187+
createWindow();
188+
getSlackToken();
189+
logEverywhere(`process.env: ${process.env}`);
47190
}
48-
})
191+
});

src/components/file_system_interface/SaveProjectComponent.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import fs from 'fs-extra'
1616
const { remote } = require('electron')
1717
const Mousetrap = require('mousetrap')
1818
19+
// might not be optimal to import like this, since entire slackApiStuff object is imported while only one of its properties is used
20+
import slackApiStuff from '../../../secretStuff/slackApiStuff.js'
21+
const slackWebhookURL = slackApiStuff.slackWebhookURL
22+
1923
export default {
2024
name: 'SaveProjetComponent',
2125
methods: {
@@ -110,8 +114,29 @@ export default {
110114
// console.log('saved ', fileName, 'to local forage')
111115
// console.log('result is', result)
112116
// })
117+
113118
// console.log('PROJECT SAVED AS A JSON OBJECT!')
119+
this.notifySlack()
114120
}
121+
},
122+
// creates a popup dialog box, where if you click on yes, it will send a message to our test Slack workspace
123+
// still must refactor to dynamically work with user's Slack
124+
notifySlack () {
125+
remote.dialog.showMessageBox({
126+
title: 'Notify Slack?',
127+
message: 'Save successful. Would you like to notify your team on Slack?',
128+
buttons: ['No', 'Yes'],
129+
defaultId: 1
130+
},
131+
response => {
132+
if (response === 1) {
133+
fetch(slackWebhookURL, {
134+
method: 'POST',
135+
body: JSON.stringify({ 'text': 'A team member saved an OverVue project file!' }),
136+
headers: { 'Content-Type': 'application/json' }
137+
})
138+
}
139+
})
115140
}
116141
},
117142
// on components creation these key presses will trigger save project

0 commit comments

Comments
 (0)