initial commit
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
let electronMain;
|
||||
try {
|
||||
electronMain = require('electron/main');
|
||||
} catch {
|
||||
electronMain = require('electron');
|
||||
}
|
||||
|
||||
const { app, BrowserWindow, ipcMain, Menu } = electronMain;
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
listJLinks,
|
||||
startTest,
|
||||
stopTest,
|
||||
getStatus,
|
||||
syncSessionConfig,
|
||||
canStartSession,
|
||||
stopAllSessions,
|
||||
} = require('./services/dtmController.cjs');
|
||||
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = async () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 1500,
|
||||
height: 980,
|
||||
minWidth: 1180,
|
||||
minHeight: 760,
|
||||
backgroundColor: '#f3f0e8',
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
},
|
||||
});
|
||||
|
||||
const devServerUrl = process.env.VITE_DEV_SERVER_URL;
|
||||
|
||||
if (devServerUrl) {
|
||||
await mainWindow.loadURL(devServerUrl);
|
||||
mainWindow.webContents.openDevTools({ mode: 'detach' });
|
||||
} else {
|
||||
await mainWindow.loadFile(path.join(app.getAppPath(), 'dist', 'index.html'));
|
||||
}
|
||||
};
|
||||
|
||||
ipcMain.handle('jlink:list', async () => listJLinks());
|
||||
ipcMain.handle('serial:list', async () => listJLinks());
|
||||
ipcMain.handle('dtm:status', async (_, sessionId) => getStatus(sessionId));
|
||||
ipcMain.handle('dtm:stop', async (_, sessionId) => stopTest(sessionId));
|
||||
ipcMain.handle('dtm:sync-config', async (_, sessionId, config) => syncSessionConfig(sessionId, config));
|
||||
ipcMain.handle('dtm:can-start', async (_, sessionId, config) => canStartSession(sessionId, config));
|
||||
ipcMain.handle('dtm:start', async (_, sessionId, config) =>
|
||||
startTest(sessionId, config, event => {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
mainWindow.webContents.send('dtm:event', event);
|
||||
})
|
||||
);
|
||||
|
||||
app.whenReady().then(() => {
|
||||
Menu.setApplicationMenu(null);
|
||||
return createWindow();
|
||||
});
|
||||
|
||||
app.on('before-quit', () => {
|
||||
stopAllSessions().catch(() => {});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow().catch(console.error);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user