Skip to content

Commit

Permalink
feat: add library action
Browse files Browse the repository at this point in the history
This commit adds an "add library" action which adds a track to the library

resolves #50
  • Loading branch information
XeroxDev committed Nov 25, 2022
1 parent 4fb5627 commit 574cb55
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 17 deletions.
Binary file modified YTMD-Connector-Icons.psd
Binary file not shown.
Binary file added icons/library-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/library-off@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/library-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/library-on@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@
"SupportedInMultiActions": true,
"Tooltip": "Repeat",
"UUID": "fun.shiro.ytmdc.repeat"
},
{
"Icon": "icons/library-on",
"Name": "Library",
"States": [
{
"Image": "icons/library-off",
"TitleAlignment": "middle",
"FontSize": "16"
},
{
"Image": "icons/library-on",
"TitleAlignment": "middle",
"FontSize": "16"
}
],
"SupportedInMultiActions": true,
"Tooltip": "Library",
"UUID": "fun.shiro.ytmdc.library"
}
],
"CodePath": "action.html",
Expand Down
38 changes: 38 additions & 0 deletions src/actions/library.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {KeyUpEvent, SDOnActionEvent, StateType, WillAppearEvent, WillDisappearEvent} from 'streamdeck-typescript';
import {ActionTypes} from '../interfaces/enums';
import {YTMD} from '../ytmd';
import {DefaultAction} from './default.action';
import {distinctUntilChanged, map, takeUntil} from "rxjs/operators";

export class LibraryAction extends DefaultAction<LibraryAction> {
private inLibrary: boolean = false;

constructor(private plugin: YTMD, actionName: ActionTypes) {
super(plugin, actionName)
}

@SDOnActionEvent('willAppear')
onContextAppear(event: WillAppearEvent<any>): void {
console.log("Started");
this.socket.onTick$
.pipe(map(value => value.track.inLibrary), distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe((inLibrary) => {
this.inLibrary = inLibrary;
this.plugin.setState(inLibrary ? StateType.OFF : StateType.ON, event.context);
});
}

@SDOnActionEvent('keyUp')
onKeypressUp(event: KeyUpEvent<any>): void {
if (!this.inLibrary) {
this.socket.playerAddLibrary();
}
this.plugin.setState(this.inLibrary ? StateType.OFF : StateType.ON, event.context);
}

@SDOnActionEvent('willDisappear')
onContextDisappear(event: WillDisappearEvent): void {
this.destroy$.next();
}

}
3 changes: 2 additions & 1 deletion src/interfaces/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export enum ActionTypes {
DISLIKE_TRACK = 'fun.shiro.ytmdc.dislike',
SONG_INFO = 'fun.shiro.ytmdc.song-info',
SHUFFLE = 'fun.shiro.ytmdc.shuffle',
REPEAT = 'fun.shiro.ytmdc.repeat'
REPEAT = 'fun.shiro.ytmdc.repeat',
LIBRARY = 'fun.shiro.ytmdc.library'
}
30 changes: 14 additions & 16 deletions src/ytmd.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {
DidReceiveGlobalSettingsEvent,
SDOnActionEvent,
StreamDeckPluginHandler,
} from 'streamdeck-typescript';
import { LikeDislikeAction } from './actions/like-dislike.action';
import { MuteAction } from './actions/mute.action';
import { NextPrevAction } from './actions/next-prev-action';
import { PlayPauseAction } from './actions/play-pause.action';
import { RepeatAction } from './actions/repeat.action';
import { ShuffleAction } from './actions/shuffle.action';
import { SongInfoAction } from './actions/song-info.action';
import { VolChangeAction } from './actions/vol-change.action';
import { YtmdSocketHelper } from './helper/ytmd-socket.helper';
import { ActionTypes } from './interfaces/enums';
import { GlobalSettingsInterface } from './interfaces/global-settings.interface';
import {DidReceiveGlobalSettingsEvent, SDOnActionEvent, StreamDeckPluginHandler,} from 'streamdeck-typescript';
import {LikeDislikeAction} from './actions/like-dislike.action';
import {MuteAction} from './actions/mute.action';
import {NextPrevAction} from './actions/next-prev-action';
import {PlayPauseAction} from './actions/play-pause.action';
import {RepeatAction} from './actions/repeat.action';
import {ShuffleAction} from './actions/shuffle.action';
import {SongInfoAction} from './actions/song-info.action';
import {VolChangeAction} from './actions/vol-change.action';
import {YtmdSocketHelper} from './helper/ytmd-socket.helper';
import {ActionTypes} from './interfaces/enums';
import {GlobalSettingsInterface} from './interfaces/global-settings.interface';
import {LibraryAction} from "./actions/library.action";

export class YTMD extends StreamDeckPluginHandler {
constructor() {
Expand All @@ -29,6 +26,7 @@ export class YTMD extends StreamDeckPluginHandler {
new SongInfoAction(this, ActionTypes.SONG_INFO);
new ShuffleAction(this, ActionTypes.SHUFFLE);
new RepeatAction(this, ActionTypes.REPEAT);
new LibraryAction(this, ActionTypes.LIBRARY);
}

@SDOnActionEvent('didReceiveGlobalSettings')
Expand Down

0 comments on commit 574cb55

Please sign in to comment.