Update
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
33
boilerbloat/src/patterns/chaser.ts
Normal file
33
boilerbloat/src/patterns/chaser.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { MovingHeadState } from 'rust_native_module';
|
||||
import { Pattern, Time } from './proto';
|
||||
|
||||
export class ChaserPattern implements Pattern {
|
||||
render(time: Time): Array<MovingHeadState> {
|
||||
let head_number = Math.ceil(time.beat_relative) % 4;
|
||||
|
||||
let template: MovingHeadState = {
|
||||
startAddress: 0,
|
||||
pan: 0,
|
||||
tilt: 0,
|
||||
brightness: {
|
||||
type: 'dimmer',
|
||||
value: 0.2,
|
||||
},
|
||||
rgbw: [255, 0, 0, 0],
|
||||
speed: 0
|
||||
}
|
||||
|
||||
let result = [];
|
||||
|
||||
for (let [i, startAddress] of [1, 15, 29, 43].entries()) {
|
||||
result[i] = template;
|
||||
result[i].startAddress = startAddress;
|
||||
|
||||
if (i === head_number) {
|
||||
result[i].brightness = { type: 'dimmer', value: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
10
boilerbloat/src/patterns/proto.ts
Normal file
10
boilerbloat/src/patterns/proto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { MovingHeadState } from "rust_native_module";
|
||||
|
||||
export type Time = {
|
||||
absolute: number,
|
||||
beat_relative: number,
|
||||
};
|
||||
|
||||
export interface Pattern {
|
||||
render(time: Time): Array<MovingHeadState>;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* @NOTE: Prepend a `~` to css file paths that are in your node_modules
|
||||
* See https://github.com/webpack-contrib/sass-loader#imports
|
||||
*/
|
||||
body {
|
||||
position: relative;
|
||||
color: white;
|
||||
height: 100vh;
|
||||
background: linear-gradient(
|
||||
200.96deg,
|
||||
#fedc2a -29.09%,
|
||||
#dd5789 51.77%,
|
||||
#7a2c9e 129.35%
|
||||
);
|
||||
font-family: sans-serif;
|
||||
overflow-y: hidden;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 10px;
|
||||
border: none;
|
||||
appearance: none;
|
||||
font-size: 1.3rem;
|
||||
box-shadow: 0px 8px 28px -6px rgba(24, 39, 75, 0.12),
|
||||
0px 18px 88px -4px rgba(24, 39, 75, 0.14);
|
||||
transition: all ease-in 0.1s;
|
||||
cursor: pointer;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
transform: scale(1.05);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
opacity: 1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.Hello {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
import { MemoryRouter as Router, Switch, Route } from 'react-router-dom';
|
||||
import icon from '../../assets/icon.svg';
|
||||
import { IpcRenderer } from 'electron/renderer';
|
||||
|
||||
import './App.css';
|
||||
|
||||
import rust from 'rust_native_module';
|
||||
const deinelib = ((window as any).electron.rustding) as (typeof rust);
|
||||
const ipcRenderer = (window as any).electron.ipcRenderer as IpcRenderer;
|
||||
|
||||
function tap() {
|
||||
ipcRenderer.send("beat-tracking", "tap");
|
||||
}
|
||||
|
||||
const Hello = () => {
|
||||
const {hello} = deinelib;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="Hello">
|
||||
<img width="200px" alt="icon" src={icon} />
|
||||
</div>
|
||||
<h1>electron-react-boilerplate</h1>
|
||||
<div className="Hello">
|
||||
<p>Rust says {hello()}</p>
|
||||
</div>
|
||||
<button onClick={tap}>Tap</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,17 +2,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Hello Electron React!</title>
|
||||
<title>Abnormal krass episch wylde Lightshow</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
<script>
|
||||
window.electron.ipcRenderer.once('ipc-example', (arg) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(arg);
|
||||
});
|
||||
|
||||
window.electron.ipcRenderer.myPing();
|
||||
</script>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user