Commit ebe044ca authored by Chris Hines's avatar Chris Hines
Browse files

forgot this one too

parent 76066959
Pipeline #16955 passed with stages
in 9 minutes and 1 second
import { app, BrowserWindow, screen, ipcMain, IpcMainEvent } from 'electron';
import * as path from 'path';
import * as url from 'url';
import * as fs from 'fs';
import * as YAML from 'yaml';
import * as child from 'child_process';
import * as temp from 'tmp';
let win: BrowserWindow = null;
const args = process.argv.slice(1),
serve = args.some(val => val === '--serve');
let lastUrl: string = null;
console.log('resources path', __dirname );
var config: any;
let configPath = path.join(app.getPath('userData'),'localConfig.yml');
try {
config = YAML.parse(fs.readFileSync(configPath).toString());
} catch {
console.log(`please create a config file at ${configPath}`)
}
//let config = YAML.parse(fs.readFileSync(path.join(__dirname,'localConfig.yml')).toString())
function createWindow(): BrowserWindow {
const electronScreen = screen;
const size = electronScreen.getPrimaryDisplay().workAreaSize;
// Create the browser window.
win = new BrowserWindow({
x: 0,
y: 0,
width: size.width,
height: size.height,
webPreferences: {
nodeIntegration: true,
allowRunningInsecureContent: (serve) ? true : false,
contextIsolation: false, // false if you want to run 2e2 test with Spectron
enableRemoteModule : true // true if you want to run 2e2 test with Spectron or use remote module in renderer context (ie. Angular)
},
});
if (serve) {
win.webContents.openDevTools();
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)
});
win.loadURL('http://localhost:4200');
} else {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
}
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
const redirectUri = 'http://localhost:4200/sshauthz_callback'
const filter = {
urls: [redirectUri + '*']
};
win.webContents.session.webRequest.onBeforeRequest(filter, function(details, callback) {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
win.webContents.on('did-finish-load', () => {
if (lastUrl != details.url) {
console.log('sending oauth2-redirect with ',details.url);
console.log(details);
win.webContents.send('oauth2-redirect',details.url);
lastUrl = details.url;
}
})
callback({ cancel: false });
});
return win;
}
try {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
app.on('ready', () => setTimeout(createWindow, 400));
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
ipcMain.on('addCert', async (event: IpcMainEvent,data: any) => await addCert(event, data))
console.log('ipcMain on set');
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
} catch (e) {
// Catch Error
// throw e;
}
async function addCert(event: IpcMainEvent, data: any) {
console.log('adding Cert', data)
let tmpfile = temp.fileSync();
let path = tmpfile.path;
fs.writeFileSync(`${path}`,data.key, {encoding: 'utf8', mode: 0o600 });
fs.writeFileSync(`${path}-cert.pub`,data.cert, {encoding: 'utf8', mode: 0o600 });
let sa = child.execSync(`${config['ssh-add']} ${path}`);
event.reply('addCertResponse',null);
fs.unlinkSync(`${path}`);
fs.unlinkSync(`${path}-cert.pub`);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment