Skip to content

Commit

Permalink
Apps are notified of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsRiprod committed Oct 31, 2024
1 parent 7140c0c commit cae145b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DeskThingServer/src/main/handlers/dataHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppDataInterface } from '@shared/types'
import { readFromFile, writeToFile } from '../utils/fileHandler'
import { sendMessageToApp } from '../services/apps'

interface Data {
[appName: string]: AppDataInterface
Expand Down Expand Up @@ -39,6 +40,8 @@ const writeData = (data: Data): void => {
const setData = (key: string, value: AppDataInterface): void => {
const data = readData()
data[key] = value
// Notify the app
sendMessageToApp(key, { type: 'data', payload: value })
writeData(data)
}
// Set data function
Expand Down
5 changes: 4 additions & 1 deletion DeskThingServer/src/main/services/apps/appCommunication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ export async function requestUserInput(appName: string, scope: AuthScopes): Prom
export async function sendMessageToApp(appName: string, data: IncomingData): Promise<void> {
const { AppHandler } = await import('./appState')
const appHandler = AppHandler.getInstance()

dataListener.asyncEmit(
MESSAGE_TYPES.LOGGING,
`[sendMessageToApp] Sending message to ${appName} with ${data.type}`
)
try {
const app = appHandler.get(appName)
if (app && typeof app.func.toClient === 'function') {
Expand Down

0 comments on commit cae145b

Please sign in to comment.