-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.js
72 lines (62 loc) · 1.63 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const fetch = require('node-fetch');
app.whenReady().then(() => createWindow());
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.on('open-partition', () => createPartitionWindow());
ipcMain.on('upload-file', () => uploadFile());
const createWindow = () => {
const win = new BrowserWindow({
width: 1000,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
const filePath = `file://${path.join(__dirname, './dist/index.html')}`;
win.loadURL(filePath);
};
const createPartitionWindow = () => {
const win = new BrowserWindow({
width: 500,
height: 500,
});
win.loadURL('http://localhost:8080/partition');
};
const uploadFile = () => {
dialog
.showOpenDialog({
title: 'Select docker-compose file',
defaultPath: path.join(__dirname, '../assets/'),
buttonLabel: 'Select',
filters: [
{
name: 'YML file',
extensions: ['yml', 'yaml'],
},
],
properties:
process.platform !== 'darwin'
? ['openFile']
: ['openFile', 'openDirectory'],
})
.then(file => {
if (!file.canceled) {
const filePath = file.filePaths[0].toString();
const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ filePath }),
};
fetch('http://localhost:3000/api/composeup', options).catch(e =>
console.log('error: docker compose up', e)
);
}
});
};