This commit is contained in:
2021-11-09 11:25:24 +01:00
parent c956ff08e5
commit d0ba6312c2
12 changed files with 422 additions and 360 deletions

View File

@@ -12,57 +12,28 @@ import 'core-js/stable';
import 'regenerator-runtime/runtime';
import path from 'path';
import { app, BrowserWindow, shell, ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';
export default class AppUpdater {
constructor() {
log.transports.file.level = 'info';
autoUpdater.logger = log;
autoUpdater.checkForUpdatesAndNotify();
}
}
import rust from 'rust_native_module';
let mainWindow: BrowserWindow | null = null;
ipcMain.on('ipc-example', async (event, arg) => {
const msgTemplate = (pingPong: string) => `IPC test: ${pingPong}`;
console.log(msgTemplate(arg));
event.reply('ipc-example', msgTemplate('pong'));
});
let beat_tracker = rust.getBeatTracker();
if (process.env.NODE_ENV === 'production') {
const sourceMapSupport = require('source-map-support');
sourceMapSupport.install();
// TODO @thamma why does this not infer that beat_tracker has tap?
if (beat_tracker.type === 'success') {
console.log('Beat Tracker started.');
ipcMain.on('beat-tracking', async (_, arg) => {
if (arg === 'tap') {
// see here
(beat_tracker as any).tap();
}
});
}
const isDevelopment =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
if (isDevelopment) {
require('electron-debug')();
}
const installExtensions = async () => {
const installer = require('electron-devtools-installer');
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
const extensions = ['REACT_DEVELOPER_TOOLS'];
return installer
.default(
extensions.map((name) => installer[name]),
forceDownload
)
.catch(console.log);
};
const createWindow = async () => {
if (isDevelopment) {
await installExtensions();
}
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
@@ -81,6 +52,8 @@ const createWindow = async () => {
},
});
mainWindow.removeMenu();
mainWindow.loadURL(resolveHtmlPath('index.html'));
mainWindow.on('ready-to-show', () => {
@@ -98,18 +71,11 @@ const createWindow = async () => {
mainWindow = null;
});
const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();
// Open urls in the user's browser
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
// Remove this if your app does not use auto updates
// eslint-disable-next-line
new AppUpdater();
};
/**

View File

@@ -3,23 +3,19 @@ const rust = require('rust_native_module');
contextBridge.exposeInMainWorld('electron', {
ipcRenderer: {
myPing() {
ipcRenderer.send('ipc-example', 'ping');
send(channel, data) {
const validChannels = ['beat-tracking'];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
on(channel, func) {
const validChannels = ['ipc-example'];
const validChannels = ['tick', 'beat-tracking'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
once(channel, func) {
const validChannels = ['ipc-example'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.once(channel, (event, ...args) => func(...args));
}
},
},
rustding: rust
});