v0.1.0 achieved
parent
37fc62cfe5
commit
f83ce96bcc
@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
const { BrowserWindow, ipcRenderer } = require('electron');
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
let options = {
|
||||
client_id: '552f169c185b172eda15',
|
||||
client_secret: 'e4e065e669f64a60a979990000ea2b321303e1d0',
|
||||
scopes: ["repo", "user:email"]
|
||||
};
|
||||
|
||||
function handleGitHub() {
|
||||
let authWindow = new BrowserWindow({
|
||||
width: 600,
|
||||
height: 800,
|
||||
show: false,
|
||||
'node-integration': true
|
||||
});
|
||||
|
||||
let url = `https://github.com/login/oauth/authorize?client_id=${options.client_id}&scope=${options.scopes}`
|
||||
authWindow.loadURL(url);
|
||||
authWindow.show();
|
||||
|
||||
return authWindow;
|
||||
}
|
||||
|
||||
function handleGitHubCallback(authWindow, url, mainWin) {
|
||||
console.log('handleGitHubCallback hit');
|
||||
let raw_code = /code=([^&]*)/.exec(url) || null;
|
||||
let code = (raw_code && raw_code.length > 1) ? raw_code[1] : null;
|
||||
let error = /\?error=(.+)$/.exec(url);
|
||||
|
||||
if(code || error) {
|
||||
authWindow.destroy();
|
||||
|
||||
if(code) {
|
||||
requestGitHubToken(code, mainWin);
|
||||
} else {
|
||||
console.log('Error in handleGitHubCallback');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function requestGitHubToken(code, mainWin) {
|
||||
axios.post('https://github.com/login/oauth/access_token', {
|
||||
client_id: options.client_id,
|
||||
client_secret: options.client_secret,
|
||||
code: code
|
||||
})
|
||||
.then((response) => {
|
||||
let token = response.data.split('&')[0].split('=')[1];
|
||||
mainWin.webContents.send("token", token);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleGitHub,
|
||||
handleGitHubCallback
|
||||
};
|
@ -0,0 +1,34 @@
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
ipcRenderer.on('get-user-name', function(event, data) {
|
||||
if(data == true) {
|
||||
document.querySelector('.user_info').style.display = "block";
|
||||
document.querySelector('#chooseRepo').style.display = "none";
|
||||
}
|
||||
});
|
||||
|
||||
ipcRenderer.on('token', function(event, data) {
|
||||
localStorage.setItem('token', data);
|
||||
});
|
||||
|
||||
function handleClick() {
|
||||
ipcRenderer.sendSync('chooseDir');
|
||||
}
|
||||
|
||||
function handleUserChange() {
|
||||
event.preventDefault();
|
||||
let name = document.getElementById('user.name').value;
|
||||
let email = document.getElementById('user.email').value;
|
||||
|
||||
let user = {
|
||||
'name': name,
|
||||
'email': email
|
||||
}
|
||||
|
||||
ipcRenderer.sendSync('changeUser', user);
|
||||
}
|
||||
|
||||
function login() {
|
||||
event.preventDefault();
|
||||
ipcRenderer.send('login');
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
const electron = require('electron');
|
||||
const ipc = electron.ipcRenderer;
|
||||
|
||||
ipc.on('send_username', function(event, args) {
|
||||
document.getElementById("user_name").innerHTML = args;
|
||||
console.log(args);
|
||||
});
|
||||
ipc.on('send_useremail', function(event, args) {
|
||||
document.getElementById("user_email").innerHTML = args;
|
||||
console.log(args);
|
||||
});
|
||||
ipc.on('send_remote', function(event, args) {
|
||||
document.getElementById("remote").innerHTML = args;
|
||||
console.log(args);
|
||||
});
|
||||
|
||||
ipc.on('send_status', function(event, args) {
|
||||
document.getElementById("status").innerHTML = args;
|
||||
console.log(args);
|
||||
});
|
||||
|
||||
ipc.on('send_log', function(event, args) {
|
||||
document.getElementById("log").innerHTML = args;
|
||||
console.log(args);
|
||||
});
|
Loading…
Reference in New Issue