You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cpgc/index.js

86 lines
2.0 KiB
JavaScript

5 years ago
'use strict';
// Electron dependencies
const { app, BrowserWindow, ipcMain } = require('electron');
5 years ago
// project dependencies
const modules = require('./modules/git');
const api = require('./modules/api');
5 years ago
// global electron window object
5 years ago
let win, authWindow;
5 years ago
// global var for dir
let dir;
// global vars for user and repo info.
let user, repo;
async function createWindow() {
user = modules.getUserInfo();
win = new BrowserWindow({
width: 1280,
height: 800,
5 years ago
webPreferences: {
nodeIntegration: true
}
});
5 years ago
// load the index.html file
win.loadFile('src/intro.html');
if(user.name == undefined || user.email == undefined) {
win.webContents.on('did-finish-load', function() {
win.webContents.send('get-user-name', true);
});
}
5 years ago
}
5 years ago
// when done init, create the window.
app.on('ready', createWindow);
5 years ago
5 years ago
ipcMain.on('changeUser', function(evet, data) {
modules.changeUser(data);
5 years ago
5 years ago
win.loadFile('src/intro.html');
win.webContents.on('did-finish-load', function() {
win.webContents.send('get-user-name', false);
});
});
5 years ago
ipcMain.on('login', async () => {
console.log('received login, creating window...');
authWindow = await api.handleGitHub();
authWindow.webContents.on('will-navigate', (event, url) => {
console.log('received will-navigate');
api.handleGitHubCallback(authWindow, url, win);
});
authWindow.on('close', () => {
authWindow = null;
}, false);
});
5 years ago
ipcMain.on('chooseDir', async function(event, data) {
// set dir
dir = modules.chooseDir(win);
// load main view
win.loadFile('src/index.html');
// load the user info
repo = await modules.getRepoInfo(dir);
// when done loading the window, send the details.
win.webContents.on('did-finish-load', () => {
win.webContents.send('send_username', user.name);
win.webContents.send('send_useremail', user.email);
win.webContents.send('send_remote', repo.remote);
win.webContents.send('send_status', repo.status);
win.webContents.send('send_log', repo.log);
win.webContents.send('send_branch', repo.branch);
});
});