-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
561 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import dataListener, { MESSAGE_TYPES } from '../utils/events' | ||
import settingsStore from '../stores/settingsStore' | ||
import { Settings, SocketData } from '@shared/types' | ||
import { sendMessageToApp } from '../services/apps' | ||
import { getAppByName } from './configHandler' | ||
|
||
export class MusicHandler { | ||
private static instance: MusicHandler | ||
private refreshInterval: NodeJS.Timeout | null = null | ||
private currentApp: string | null = null | ||
|
||
private constructor() { | ||
this.initializeRefreshInterval() | ||
} | ||
|
||
public static getInstance(): MusicHandler { | ||
if (!MusicHandler.instance) { | ||
MusicHandler.instance = new MusicHandler() | ||
} | ||
return MusicHandler.instance | ||
} | ||
|
||
private async initializeRefreshInterval(): Promise<void> { | ||
const settings = await settingsStore.getSettings() // Get from your settings store | ||
this.updateRefreshInterval(settings.refreshInterval) | ||
dataListener.on(MESSAGE_TYPES.SETTINGS, this.handleSettingsUpdate) | ||
} | ||
|
||
private handleSettingsUpdate = (settings: Settings): void => { | ||
this.updateRefreshInterval(settings.refreshInterval) | ||
|
||
if (settings.playbackLocation && settings.playbackLocation !== this.currentApp) { | ||
this.currentApp = settings.playbackLocation | ||
} | ||
} | ||
|
||
public updateRefreshInterval(refreshRate: number): void { | ||
if (this.refreshInterval) { | ||
clearInterval(this.refreshInterval) | ||
} | ||
|
||
if (refreshRate < 0) { | ||
dataListener.asyncEmit(MESSAGE_TYPES.LOGGING, `[MusicHandler]: Cancelling Refresh Interval!`) | ||
return | ||
} | ||
|
||
this.refreshInterval = setInterval(() => { | ||
this.refreshMusicData() | ||
}, refreshRate) | ||
} | ||
|
||
private async refreshMusicData(): Promise<void> { | ||
if (!this.currentApp || this.currentApp.length == 0) { | ||
dataListener.asyncEmit(MESSAGE_TYPES.ERROR, `[MusicHandler]: No current app set!`) | ||
return | ||
} | ||
|
||
const app = await getAppByName(this.currentApp) | ||
|
||
if (!app || app.running == false) { | ||
dataListener.asyncEmit( | ||
MESSAGE_TYPES.ERROR, | ||
`[MusicHandler]: App ${this.currentApp} not found or not running!!` | ||
) | ||
} | ||
|
||
try { | ||
await sendMessageToApp(this.currentApp, { type: 'get', request: 'refresh', payload: '' }) | ||
dataListener.asyncEmit(MESSAGE_TYPES.LOGGING, `[MusicHandler]: Refreshing Music Data!`) | ||
} catch (error) { | ||
dataListener.asyncEmit(MESSAGE_TYPES.ERROR, `[MusicHandler]: Music refresh failed: ${error}`) | ||
} | ||
} | ||
|
||
public async handleClientRequest(request: SocketData): Promise<void> { | ||
if (!this.currentApp) return | ||
if (request.app != 'music' && request.app != 'utility') return | ||
|
||
if (request.app == 'utility') { | ||
dataListener.asyncEmit( | ||
MESSAGE_TYPES.LOGGING, | ||
`[MusicHandler]: Legacy Name called! Support for this will be dropped in future updates. Migrate your app to use 'music' instead!` | ||
) | ||
} | ||
|
||
dataListener.asyncEmit( | ||
MESSAGE_TYPES.LOGGING, | ||
`[MusicHandler]: ${request.type} ${request.request}` | ||
) | ||
|
||
sendMessageToApp(this.currentApp, { | ||
type: request.type, | ||
request: request.request, | ||
payload: request.payload | ||
}) | ||
} | ||
} | ||
|
||
export default MusicHandler.getInstance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
DeskThingServer/src/renderer/src/assets/icons/icon/IconMusic.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Icon } from '.' | ||
|
||
function IconMusic(props): JSX.Element { | ||
return ( | ||
<Icon {...props}> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
> | ||
<circle cx="8" cy="18" r="4" /> | ||
<path d="M12 18V2l7 4" /> | ||
</svg> | ||
</Icon> | ||
) | ||
} | ||
|
||
export default IconMusic |
18 changes: 18 additions & 0 deletions
18
DeskThingServer/src/renderer/src/assets/icons/icon/IconStop.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Icon, IconProps } from '.' | ||
|
||
function IconStop(props: IconProps): JSX.Element { | ||
return ( | ||
<Icon {...props}> | ||
<svg viewBox="0 0 16 16" fill={props.fill || 'none'}> | ||
<path | ||
d="M3.28683 3.28634L12.7135 12.713M14.6668 7.99967C14.6668 11.6816 11.6821 14.6663 8.00016 14.6663C4.31826 14.6663 1.3335 11.6816 1.3335 7.99967C1.3335 4.31778 4.31826 1.33301 8.00016 1.33301C11.6821 1.33301 14.6668 4.31778 14.6668 7.99967Z" | ||
stroke="white" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</svg> | ||
</Icon> | ||
) | ||
} | ||
|
||
export default IconStop |
25 changes: 25 additions & 0 deletions
25
DeskThingServer/src/renderer/src/assets/icons/icon/IconTrash.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Icon } from '.' | ||
|
||
function IconTrash(props): JSX.Element { | ||
return ( | ||
<Icon {...props}> | ||
<svg viewBox="0 0 17 16" fill="none"> | ||
<g clipPath="url(#clip0_268_267)"> | ||
<path | ||
d="M2.16699 3.99967H3.50033M3.50033 3.99967H14.167M3.50033 3.99967V13.333C3.50033 13.6866 3.6408 14.0258 3.89085 14.2758C4.1409 14.5259 4.48004 14.6663 4.83366 14.6663H11.5003C11.8539 14.6663 12.1931 14.5259 12.4431 14.2758C12.6932 14.0258 12.8337 13.6866 12.8337 13.333V3.99967M5.50033 3.99967V2.66634C5.50033 2.31272 5.6408 1.97358 5.89085 1.72353C6.1409 1.47348 6.48004 1.33301 6.83366 1.33301H9.50033C9.85395 1.33301 10.1931 1.47348 10.4431 1.72353C10.6932 1.97358 10.8337 2.31272 10.8337 2.66634V3.99967M6.83366 7.33301V11.333M9.50033 7.33301V11.333" | ||
stroke={'white'} | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_268_267"> | ||
<rect width="16" height="16" fill="white" transform="translate(0.166992)" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
</Icon> | ||
) | ||
} | ||
|
||
export default IconTrash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 59 additions & 10 deletions
69
DeskThingServer/src/renderer/src/overlays/apps/AppActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.