57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
const { app, BrowserWindow, ipcMain } = require('electron');
|
||
const path = require('path');
|
||
const { post } = require('./request')
|
||
const { deputyUrl, deputyToken } = require('../env.json');
|
||
const { getConfig, setConfig } = require('./config');
|
||
|
||
function createWindow() {
|
||
const mainWindow = new BrowserWindow({
|
||
width: 1440 ,
|
||
height: 900,
|
||
show: false,
|
||
icon: path.join(__dirname, 'favicon-32x32.png'),
|
||
webPreferences: {
|
||
preload: path.join(__dirname, 'preload.js'),
|
||
allowRunningInsecureContent: true,
|
||
}
|
||
});
|
||
|
||
ipcMain.handle('getTimesheet', async(event, body) => {
|
||
try {
|
||
const { apitoken } = getConfig();
|
||
const token = apitoken || deputyToken;
|
||
return await post(deputyUrl, body, { Authorization: `OAuth ${token}` });
|
||
} catch (err) {
|
||
console.log('err :>> ', err);
|
||
}
|
||
});
|
||
|
||
ipcMain.handle('getAppConfig', () => {
|
||
const config = getConfig();
|
||
return {... { apitoken: deputyToken }, ...config };
|
||
});
|
||
|
||
ipcMain.handle('setAppConfig', (event, config) => {
|
||
return setConfig(config);
|
||
})
|
||
|
||
mainWindow.maximize();
|
||
mainWindow.removeMenu();
|
||
mainWindow.loadFile(path.join(__dirname, '..', 'ui', 'dist', 'index.html'));
|
||
|
||
// Open the DevTools.
|
||
// mainWindow.webContents.openDevTools();
|
||
mainWindow.show();
|
||
}
|
||
|
||
app.whenReady().then(() => {
|
||
createWindow();
|
||
|
||
app.on('activate', () => {
|
||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||
})
|
||
});
|
||
|
||
app.on('window-all-closed', function() {
|
||
if (process.platform !== 'darwin') app.quit()
|
||
}); |