Skip to content

Commit

Permalink
feat: update status on focus #4
Browse files Browse the repository at this point in the history
  • Loading branch information
seravifer committed Mar 18, 2021
1 parent c57fd81 commit 844dff8
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 292 deletions.
6 changes: 6 additions & 0 deletions electron/control-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export default function startDevicesManager(app: any) {
return state;
});

events.handle('state', async (_, device) => {
const light = devices.find(d => d.id === device.id);
const state = await light?.getState()
return state;
});

events.on('disconnect', (_, device) => {
devices.splice(devices.findIndex(d => d.id === device.id), 1);
console.log('Device disconnected');
Expand Down
2 changes: 2 additions & 0 deletions electron/devices/device.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export abstract class Device {
abstract static discovery(): Promise<DeviceInfo>;
// @ts-ignore
abstract static connect(): Promise<State>;
// @ts-ignore
abstract getState(): Promise<State>;
// abstract getState(): Promise<State>;
abstract setColor(color: {
r: number;
Expand Down
1 change: 0 additions & 1 deletion electron/devices/flux.device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Flux extends Device {
}

setColor(color: { r: number, g: number, b: number }) {
// TODO: check power
this.controller.setColor(color.r, color.g, color.b);
}

Expand Down
5 changes: 5 additions & 0 deletions electron/devices/yeelight.device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class Yeelight extends Device {
});
}

async getState(): Promise<State> {
// TODO
return Promise.resolve({} as State)
}

setColor(color: { r: number, g: number, b: number }) {
this.controller.sendCommand({
id: -1,
Expand Down
5 changes: 2 additions & 3 deletions electron/preload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { contextBridge, ipcRenderer } = require("electron")
import { contextBridge, ipcRenderer } from "electron";

contextBridge.exposeInMainWorld("ipcRenderer", {
contextBridge.exposeInMainWorld("ipc", {
send: (channel, data) => {
ipcRenderer.send(channel, data);
},
Expand All @@ -10,7 +10,6 @@ contextBridge.exposeInMainWorld("ipcRenderer", {
on: (channel, listener) => {
const subscription = (event, ...args) => listener(...args);
ipcRenderer.on(channel, subscription);

return () => {
ipcRenderer.removeListener(channel, subscription);
}
Expand Down
Loading

0 comments on commit 844dff8

Please sign in to comment.