Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('window-all-closed', () => {
app.quit();
});
app.on('before-quit', () => {
if (rendererState.isLoggedIn) {
config.set('windowState', mainWindow.getNormalBounds());
}
});
ipc.answerRenderer('start-marketmaker', async seedPhrase => {
// We have to do this dance as IPC doesn't correctly serialize errors.
try {
await marketmaker.start({seedPhrase});
} catch (error) {
logger.error('Failed to start Marketmaker:', error);
throw error;
}
return marketmaker.port;
});
ipc.answerRenderer('stop-marketmaker', async () => {
await marketmaker.stop();
});
ipc.answerRenderer('set-active-view-on-dom-ready', view => {
app.on("activate", () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow(mainWindow);
}
});
// create main BrowserWindow when electron is ready
app.on("ready", () => {
mainWindow = createMainWindow(mainWindow);
createMenu();
new AppUpdater();
});
answerRenderer("app-quit", () => {
app.quit();
});
answerRenderer("app-minimize", () => {
if (!mainWindow.isMinimized()) {
mainWindow.minimize();
} else {
mainWindow.restore();
}
});
answerRenderer("app-maximize", () => {
if (!mainWindow.isFullScreen()) {
mainWindow.setFullScreen(true);
} else {
mainWindow.setFullScreen(false);
const connectResult = await connect({ host, port, username, password })
// connection created - we can start pushing updates
startLiveStats()
startClusterReadWriteChanges()
return connectResult
})
ipc.answerRenderer(QUERIES_CHANNEL_NAME, async query => {
return queryResolver(query)
})
ipc.answerRenderer(ACTIONS_CHANNEL_NAME, async action => {
return actionResolver(action)
})
ipc.answerRenderer(EVAL_QUERY_CHANNEL_NAME, async code => {
return evalQuery(code)
})
const ipc = require('electron-better-ipc')
const { connect } = require('./driver')
const evalQuery = require('./evalQuery')
const { startLiveStats } = require('./models/stats')
const { startClusterReadWriteChanges } = require('./models/cluster')
const queryResolver = require('./resolvers/queryResolver')
const actionResolver = require('./resolvers/actionResolver')
const url = require('../helpers/url')
const {
CONNECT_CHANNEL_NAME,
QUERIES_CHANNEL_NAME,
ACTIONS_CHANNEL_NAME,
EVAL_QUERY_CHANNEL_NAME
} = require('../../shared/channels')
ipc.answerRenderer(CONNECT_CHANNEL_NAME, async ({ name, address, username, password }) => {
const { host, port } = url.extract(address)
const connectResult = await connect({ host, port, username, password })
// connection created - we can start pushing updates
startLiveStats()
startClusterReadWriteChanges()
return connectResult
})
ipc.answerRenderer(QUERIES_CHANNEL_NAME, async query => {
return queryResolver(query)
})
ipc.answerRenderer(ACTIONS_CHANNEL_NAME, async action => {
return actionResolver(action)
})
// We have to do this dance as IPC doesn't correctly serialize errors.
try {
await marketmaker.start({seedPhrase});
} catch (error) {
logger.error('Failed to start Marketmaker:', error);
throw error;
}
return marketmaker.port;
});
ipc.answerRenderer('stop-marketmaker', async () => {
await marketmaker.stop();
});
ipc.answerRenderer('set-active-view-on-dom-ready', view => {
mainWindow.webContents.once('dom-ready', () => {
mainWindow.webContents.send('set-active-view', view);
});
});
const setupListeners = () => {
ipc.answerRenderer('open-dialog', onOpenDialog);
ipc.answerRenderer('import-config', importConfig);
ipc.answerRenderer('apply-plugin-actions', applyPlugin);
ipc.answerRenderer('command-exists', async command => {
const result = await sync(command);
return !!result;
});
ipc.answerRenderer('run-plop-generator', async ({ generatorName, actions, projectPath }) => {
const plop = nodePlop(path.join(projectPath, 'plopfile.js'));
return plop.getGenerator(generatorName).runActions(actions);
});
};
loadPath: path.join(__dirname, 'locales', '{{lng}}', '{{ns}}.json'),
jsonIndent: 4,
},
});
(async () => {
if (isDevelopment && config.has('debug_forcedLanguage')) {
i18next.changeLanguage(config.get('debug_forcedLanguage'));
return;
}
await appReady;
i18next.changeLanguage(app.getLocale());
})();
ipc.answerRenderer('get-translations', async () => {
await appReady;
return i18next;
});
exports.i18n = i18next;
exports.translate = namespaces => namespaces ? i18next.getFixedT(null, namespaces) : i18next.t.bind(i18next);
const setupListeners = () => {
ipc.answerRenderer('open-dialog', onOpenDialog);
ipc.answerRenderer('import-config', importConfig);
ipc.answerRenderer('apply-plugin-actions', applyPlugin);
ipc.answerRenderer('command-exists', async command => {
const result = await sync(command);
return !!result;
});
ipc.answerRenderer('run-plop-generator', async ({ generatorName, actions, projectPath }) => {
const plop = nodePlop(path.join(projectPath, 'plopfile.js'));
return plop.getGenerator(generatorName).runActions(actions);
});
};
/**
* Handle messages from renderer process.
*/
ipc.answerRenderer('openProject', async (p) => {
const res = await openWindow(p);
if (res) closeSplashWindow();
return res;
});
ipc.answerRenderer('closeSplashWindow', async () => {
closeSplashWindow();
});
ipc.answerRenderer('closeIntroWindow', async () => {
await fs.ensureFile(path.join(home, '.opus'));
closeIntroWindow();
createSplashWindow();
});
/**
* Create editor windows for each previosly active window.
*/
function createWindows(windows) {
windows.forEach((win) => {
createEditorWindow(win);
});
}
app.on('ready', async () => {
const setupListeners = () => {
ipc.answerRenderer('open-dialog', onOpenDialog);
ipc.answerRenderer('import-config', importConfig);
ipc.answerRenderer('apply-plugin-actions', applyPlugin);
ipc.answerRenderer('command-exists', async command => {
const result = await sync(command);
return !!result;
});
ipc.answerRenderer('run-plop-generator', async ({ generatorName, actions, projectPath }) => {
const plop = nodePlop(path.join(projectPath, 'plopfile.js'));
return plop.getGenerator(generatorName).runActions(actions);
});
};