Skip to content

Commit e58ca26

Browse files
grauxmusicclaude
andcommitted
feat(windows): IPC bridge for real-time BPM/Key from DAW to React
Expose __morphDAW.onDawState via contextBridge so React components can subscribe to DAW state pushed from main process. Send 'daw-state' IPC on every SYNC TCP message and on page load (for reconnect case). DOM injection via executeJavaScript remains as fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fbfb3aa commit e58ca26

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

CompanionWin/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ function createWindow() {
7878
setTimeout(() => win?.loadURL(`${kBaseURL}/library?companion=windows`, { userAgent: kUA }), 3000)
7979
})
8080

81+
// Send current DAW state as soon as the page is interactive
82+
win.webContents.on('did-finish-load', () => {
83+
win.webContents.send('daw-state', {
84+
connected: dawState.isConnected,
85+
bpm: dawState.bpm,
86+
key: dawState.key,
87+
})
88+
})
89+
8190
win.on('close', (e) => {
8291
// Minimize to tray on close
8392
e.preventDefault()
@@ -203,9 +212,11 @@ function handleLine(conn, line) {
203212
dawState.isConnected = false
204213
updateTrayMenu()
205214
injectPluginStatus(false, 0, '')
215+
if (win?.webContents) win.webContents.send('daw-state', { connected: false, bpm: 0, key: '' })
206216
}, 5000)
207217
updateTrayMenu()
208218
injectPluginStatus(true, bpm, key)
219+
if (win?.webContents) win.webContents.send('daw-state', { connected: true, bpm, key })
209220

210221
} else if (line.startsWith('TRANSPORT ')) {
211222
const parts = line.slice(10).split(' ')

CompanionWin/preload.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const { ipcRenderer, contextBridge } = require('electron')
77
// does NOT change with contextIsolation: true. This flag is the canonical signal.
88
contextBridge.exposeInMainWorld('__waterCompanionPlatform', 'windows')
99

10+
// Expose DAW state updates from main process to React components.
11+
// main.js sends 'daw-state' IPC when the JUCE plugin syncs BPM/Key via TCP.
12+
contextBridge.exposeInMainWorld('__morphDAW', {
13+
onDawState: (cb) => ipcRenderer.on('daw-state', (_, data) => cb(data))
14+
})
15+
1016
// Polyfill window.webkit.messageHandlers so companion-bridge.tsx works
1117
// identically to the macOS WKWebView environment.
1218
contextBridge.exposeInMainWorld('webkit', {

0 commit comments

Comments
 (0)