From 80e1a603b542b6252b0bb431a469baa19c9021a2 Mon Sep 17 00:00:00 2001 From: Types update Date: Tue, 17 May 2022 21:40:37 +0000 Subject: [PATCH 01/26] sync from Moosync --- index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 1e57bbf..7562789 100644 --- a/index.d.ts +++ b/index.d.ts @@ -30,7 +30,6 @@ export interface Playlist { playlist_song_count?: number playlist_path?: string icon?: string - isRemote?: boolean } export type PlayerTypes = 'LOCAL' | 'YOUTUBE' | 'SPOTIFY' | 'URL' From ff1673e88859c2de979a3e57f83ad6df4067abc7 Mon Sep 17 00:00:00 2001 From: Types update Date: Thu, 19 May 2022 07:14:57 +0000 Subject: [PATCH 02/26] sync from Moosync --- index.d.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 7562789..6f6a081 100644 --- a/index.d.ts +++ b/index.d.ts @@ -32,7 +32,7 @@ export interface Playlist { icon?: string } -export type PlayerTypes = 'LOCAL' | 'YOUTUBE' | 'SPOTIFY' | 'URL' +export type PlayerTypes = 'LOCAL' | 'YOUTUBE' | 'SPOTIFY' | 'URL' | 'DASH' export interface Song { _id: string @@ -315,6 +315,8 @@ export type ExtraExtensionEventTypes = | 'playerStateChanged' | 'songChanged' | 'preferenceChanged' + | 'playbackDetailsRequested' + | 'customRequest' export type GetPlaylistReturnType = { playlists: Playlist[] @@ -324,6 +326,16 @@ export type GetPlaylistSongsReturnType = { songs: Song[] } +export type GetPlaybackDetailsReturnType = { + duration: number + url: string +} + +export type CustomRequestReturnType = { + mimeType: string + data: Buffer +} + export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' ? [playlistID: string] : T extends 'oauthCallback' @@ -340,12 +352,20 @@ export type ExtraExtensionEventData = T exte ? [song: Song] : T extends 'preferenceChanged' ? [preference: { key: string; value: unknown }] + : T extends 'playbackDetailsRequested' + ? [song: Song] + : T extends 'customRequest' + ? [url: string] : [] export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' ? GetPlaylistReturnType : T extends 'requestedPlaylistSongs' ? GetPlaylistSongsReturnType + : T extends 'playbackDetailsRequested' + ? GetPlaybackDetailsReturnType + : T extends 'customRequest' + ? CustomRequestReturnType : void export type ExtensionContextMenuItem = { From c14d37e689db595a5b5aafb834b3dea44b2e8547 Mon Sep 17 00:00:00 2001 From: Types update Date: Fri, 20 May 2022 03:17:00 +0000 Subject: [PATCH 03/26] sync from Moosync --- index.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.d.ts b/index.d.ts index 6f6a081..bf23539 100644 --- a/index.d.ts +++ b/index.d.ts @@ -399,6 +399,17 @@ export type ExtensionContextMenuHandlerArgs = T exte : T extends 'ALBUM' ? Album : undefined + +export type AccountDetails = { + id: string + packageName: string + name: string + loggedIn: boolean + signinCallback: () => Promise | void + signoutCallback: () => Promise | void + accountName?: string +} + export interface extensionAPI { /** * Get songs from database filtered by provided options From ad992af4e94e5e3382fe50b2b94103ccac207b7d Mon Sep 17 00:00:00 2001 From: Types update Date: Fri, 20 May 2022 03:24:15 +0000 Subject: [PATCH 04/26] sync from Moosync --- index.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/index.d.ts b/index.d.ts index bf23539..0bcebca 100644 --- a/index.d.ts +++ b/index.d.ts @@ -568,6 +568,25 @@ export interface extensionAPI { */ getContextMenuItems(): ExtensionContextMenuItem[] + /** + * Add an account to show in accounts section in main app. + * The user will then be able to perform login / logout operations on this account + * and also view its details + * + * @param details details of account to be added + * @returns generated accountId + */ + registerAccount(details: Omit): Promise + + /** + * Change login status and signed in user's account name. + * + * @param id accountId to change details of. Returned from {@link registerAccount} + * @param loggedIn true if user is logged in otherwise false + * @param accountName name of user's account if logged in otherwise undefined + */ + changeAccountAuthStatus(id: string, loggedIn: boolean, accountName?: string): Promise + /** * Object containing controls for player */ From d7ab0fe167f248a64c5e4a110efd6e17645bf319 Mon Sep 17 00:00:00 2001 From: Types update Date: Fri, 20 May 2022 04:39:24 +0000 Subject: [PATCH 05/26] sync from Moosync --- index.d.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 0bcebca..75eabba 100644 --- a/index.d.ts +++ b/index.d.ts @@ -404,10 +404,12 @@ export type AccountDetails = { id: string packageName: string name: string + bgColor: string + icon: string loggedIn: boolean signinCallback: () => Promise | void signoutCallback: () => Promise | void - accountName?: string + username?: string } export interface extensionAPI { @@ -573,10 +575,20 @@ export interface extensionAPI { * The user will then be able to perform login / logout operations on this account * and also view its details * - * @param details details of account to be added + * @param name name of service provider + * @param bgColor background color to use for account card (in hex format. Eg. #000000) + * @param icon icon of account (preferably service provider's icon) + * @param signinCallback callback fired when user wishes to login + * @param signoutCallback callback fired when user wishes to logout * @returns generated accountId */ - registerAccount(details: Omit): Promise + registerAccount( + name: string, + bgColor: string, + icon: string, + signinCallback: AccountDetails['signinCallback'], + signoutCallback: AccountDetails['signoutCallback'] + ): Promise /** * Change login status and signed in user's account name. @@ -585,7 +597,7 @@ export interface extensionAPI { * @param loggedIn true if user is logged in otherwise false * @param accountName name of user's account if logged in otherwise undefined */ - changeAccountAuthStatus(id: string, loggedIn: boolean, accountName?: string): Promise + changeAccountAuthStatus(id: string, loggedIn: boolean, username?: string): Promise /** * Object containing controls for player From 18b3203a8ad426a897fbc946b65ee0b98b22c845 Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 21 May 2022 18:24:33 +0000 Subject: [PATCH 06/26] sync from Moosync --- index.d.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/index.d.ts b/index.d.ts index 75eabba..00ed62a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -317,6 +317,8 @@ export type ExtraExtensionEventTypes = | 'preferenceChanged' | 'playbackDetailsRequested' | 'customRequest' + | 'requestedSongFromURL' + | 'requestedPlaylistFromURL' export type GetPlaylistReturnType = { playlists: Playlist[] @@ -336,6 +338,15 @@ export type CustomRequestReturnType = { data: Buffer } +export type GetSongReturnType = { + song: Song +} + +export type GetPlaylistAndSongsReturnType = { + playlist: Playlist + songs: Song[] +} + export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' ? [playlistID: string] : T extends 'oauthCallback' @@ -356,6 +367,10 @@ export type ExtraExtensionEventData = T exte ? [song: Song] : T extends 'customRequest' ? [url: string] + : T extends 'requestedSongFromURL' + ? [url: string] + : T extends 'requestedPlaylistFromURL' + ? [url: string] : [] export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' @@ -366,6 +381,10 @@ export type ExtraExtensionEventReturnType = ? GetPlaybackDetailsReturnType : T extends 'customRequest' ? CustomRequestReturnType + : T extends 'requestedSongFromURL' + ? GetSongReturnType + : T extends 'requestedPlaylistFromURL' + ? GetPlaylistAndSongsReturnType : void export type ExtensionContextMenuItem = { @@ -412,6 +431,22 @@ export type AccountDetails = { username?: string } +export type LoginModalData = { + providerName: string + providerColor: string + text?: string + url?: string +} & ( + | { + manualClick: true + oauthPath: string + } + | { + manualClick?: false + oauthPath?: string + } +) + export interface extensionAPI { /** * Get songs from database filtered by provided options @@ -599,6 +634,9 @@ export interface extensionAPI { */ changeAccountAuthStatus(id: string, loggedIn: boolean, username?: string): Promise + openLoginModal(data: LoginModalData): Promise + closeLoginModal(): Promise + /** * Object containing controls for player */ From e01043a0741d94bc587f77729ef3ab1f4720e372 Mon Sep 17 00:00:00 2001 From: Types update Date: Sun, 22 May 2022 07:00:17 +0000 Subject: [PATCH 07/26] sync from Moosync --- index.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.d.ts b/index.d.ts index 00ed62a..23e2751 100644 --- a/index.d.ts +++ b/index.d.ts @@ -319,6 +319,7 @@ export type ExtraExtensionEventTypes = | 'customRequest' | 'requestedSongFromURL' | 'requestedPlaylistFromURL' + | 'requestSearchResult' export type GetPlaylistReturnType = { playlists: Playlist[] @@ -347,6 +348,11 @@ export type GetPlaylistAndSongsReturnType = { songs: Song[] } +export type GetSearchReturnType = { + providerName: string + songs: Song[] +} + export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' ? [playlistID: string] : T extends 'oauthCallback' @@ -371,6 +377,8 @@ export type ExtraExtensionEventData = T exte ? [url: string] : T extends 'requestedPlaylistFromURL' ? [url: string] + : T extends 'requestSearchResult' + ? [term: string] : [] export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' @@ -385,6 +393,8 @@ export type ExtraExtensionEventReturnType = ? GetSongReturnType : T extends 'requestedPlaylistFromURL' ? GetPlaylistAndSongsReturnType + : T extends 'requestSearchResult' + ? GetSearchReturnType : void export type ExtensionContextMenuItem = { From a1217bfdd9a0ed3f2c7ab6314a0da9ae3b9d5ff5 Mon Sep 17 00:00:00 2001 From: Types update Date: Mon, 23 May 2022 13:57:13 +0000 Subject: [PATCH 08/26] sync from Moosync --- index.d.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 23e2751..e4da55f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -320,6 +320,7 @@ export type ExtraExtensionEventTypes = | 'requestedSongFromURL' | 'requestedPlaylistFromURL' | 'requestSearchResult' + | 'requestedRecommendations' export type GetPlaylistReturnType = { playlists: Playlist[] @@ -341,20 +342,27 @@ export type CustomRequestReturnType = { export type GetSongReturnType = { song: Song -} +} | void export type GetPlaylistAndSongsReturnType = { playlist: Playlist songs: Song[] -} +} | void export type GetSearchReturnType = { providerName: string songs: Song[] } +export type GetRecommendationsReturnType = { + providerName: string + songs: Song[] +} + export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' - ? [playlistID: string] + ? [playlistID: string, invalidateCache: boolean] + : T extends 'requestedPlaylists' + ? [invalidateCache: boolean] : T extends 'oauthCallback' ? [url: string] : T extends 'songQueueChanged' @@ -395,6 +403,8 @@ export type ExtraExtensionEventReturnType = ? GetPlaylistAndSongsReturnType : T extends 'requestSearchResult' ? GetSearchReturnType + : T extends 'requestedRecommendations' + ? GetRecommendationsReturnType : void export type ExtensionContextMenuItem = { From b35714614cee66be22035e3cf9bbf97af6115493 Mon Sep 17 00:00:00 2001 From: Types update Date: Mon, 23 May 2022 19:55:32 +0000 Subject: [PATCH 09/26] sync from Moosync --- index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.d.ts b/index.d.ts index e4da55f..94551a0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -321,6 +321,7 @@ export type ExtraExtensionEventTypes = | 'requestedPlaylistFromURL' | 'requestSearchResult' | 'requestedRecommendations' + | 'requestedLyrics' export type GetPlaylistReturnType = { playlists: Playlist[] @@ -387,6 +388,8 @@ export type ExtraExtensionEventData = T exte ? [url: string] : T extends 'requestSearchResult' ? [term: string] + : T extends 'requestedLyrics' + ? [song: Song] : [] export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' @@ -405,6 +408,8 @@ export type ExtraExtensionEventReturnType = ? GetSearchReturnType : T extends 'requestedRecommendations' ? GetRecommendationsReturnType + : T extends 'requestedLyrics' + ? string | void : void export type ExtensionContextMenuItem = { From e302c7af95dfa9d8e4b5421bbd1baf375a15664b Mon Sep 17 00:00:00 2001 From: Sahil Gupte Date: Thu, 26 May 2022 17:50:38 +0530 Subject: [PATCH 10/26] add @types/node as dependency Signed-off-by: Sahil Gupte --- package.json | 5 ++++- yarn.lock | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2116f2a..d1bdb71 100644 --- a/package.json +++ b/package.json @@ -25,5 +25,8 @@ "loglevel": "^1.7.1", "typedoc": "^0.22.5", "typescript": "^4.4.3" + }, + "dependencies": { + "@types/node": "^17.0.35" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 287d503..11fa96c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@types/node@^17.0.35": + version "17.0.35" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.35.tgz#635b7586086d51fb40de0a2ec9d1014a5283ba4a" + integrity sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg== + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" From 6574f9ce2422ad7cb8baa254f7fe2013fe2f4aba Mon Sep 17 00:00:00 2001 From: Types update Date: Thu, 26 May 2022 14:15:57 +0000 Subject: [PATCH 11/26] sync from Moosync --- index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 94551a0..b3adac1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -343,12 +343,12 @@ export type CustomRequestReturnType = { export type GetSongReturnType = { song: Song -} | void +} export type GetPlaylistAndSongsReturnType = { playlist: Playlist songs: Song[] -} | void +} export type GetSearchReturnType = { providerName: string @@ -393,21 +393,21 @@ export type ExtraExtensionEventData = T exte : [] export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' - ? GetPlaylistReturnType + ? GetPlaylistReturnType | void : T extends 'requestedPlaylistSongs' - ? GetPlaylistSongsReturnType + ? GetPlaylistSongsReturnType | void : T extends 'playbackDetailsRequested' - ? GetPlaybackDetailsReturnType + ? GetPlaybackDetailsReturnType | void : T extends 'customRequest' - ? CustomRequestReturnType + ? CustomRequestReturnType | void : T extends 'requestedSongFromURL' - ? GetSongReturnType + ? GetSongReturnType | void : T extends 'requestedPlaylistFromURL' - ? GetPlaylistAndSongsReturnType + ? GetPlaylistAndSongsReturnType | void : T extends 'requestSearchResult' - ? GetSearchReturnType + ? GetSearchReturnType | void : T extends 'requestedRecommendations' - ? GetRecommendationsReturnType + ? GetRecommendationsReturnType | void : T extends 'requestedLyrics' ? string | void : void From 9db3d2f5272dfba68ec8e3ed0236fb3f462ac0d2 Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 28 May 2022 20:14:30 +0000 Subject: [PATCH 12/26] sync from Moosync --- index.d.ts | 242 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 167 insertions(+), 75 deletions(-) diff --git a/index.d.ts b/index.d.ts index b3adac1..87543b6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -323,6 +323,58 @@ export type ExtraExtensionEventTypes = | 'requestedRecommendations' | 'requestedLyrics' +export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' + ? GetPlaylistReturnType | void + : T extends 'requestedPlaylistSongs' + ? GetPlaylistSongsReturnType | void + : T extends 'playbackDetailsRequested' + ? GetPlaybackDetailsReturnType | void + : T extends 'customRequest' + ? CustomRequestReturnType | void + : T extends 'requestedSongFromURL' + ? GetSongReturnType | void + : T extends 'requestedPlaylistFromURL' + ? GetPlaylistAndSongsReturnType | void + : T extends 'requestSearchResult' + ? GetSearchReturnType | void + : T extends 'requestedRecommendations' + ? GetRecommendationsReturnType | void + : T extends 'requestedLyrics' + ? string | void + : void + +export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' + ? [playlistID: string, invalidateCache: boolean] + : T extends 'requestedPlaylists' + ? [invalidateCache: boolean] + : T extends 'oauthCallback' + ? [url: string] + : T extends 'songQueueChanged' + ? [songQueue: SongQueue] + : T extends 'seeked' + ? [newTime: number] + : T extends 'volumeChanged' + ? [newVolume: number] + : T extends 'playerStateChanged' + ? [newState: PlayerState] + : T extends 'songChanged' + ? [song: Song] + : T extends 'preferenceChanged' + ? [preference: { key: string; value: unknown }] + : T extends 'playbackDetailsRequested' + ? [song: Song] + : T extends 'customRequest' + ? [url: string] + : T extends 'requestedSongFromURL' + ? [url: string] + : T extends 'requestedPlaylistFromURL' + ? [url: string] + : T extends 'requestSearchResult' + ? [term: string] + : T extends 'requestedLyrics' + ? [song: Song] + : [] + export type GetPlaylistReturnType = { playlists: Playlist[] } @@ -360,58 +412,6 @@ export type GetRecommendationsReturnType = { songs: Song[] } -export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' - ? [playlistID: string, invalidateCache: boolean] - : T extends 'requestedPlaylists' - ? [invalidateCache: boolean] - : T extends 'oauthCallback' - ? [url: string] - : T extends 'songQueueChanged' - ? [songQueue: SongQueue] - : T extends 'seeked' - ? [newTime: number] - : T extends 'volumeChanged' - ? [newVolume: number] - : T extends 'playerStateChanged' - ? [newState: PlayerState] - : T extends 'songChanged' - ? [song: Song] - : T extends 'preferenceChanged' - ? [preference: { key: string; value: unknown }] - : T extends 'playbackDetailsRequested' - ? [song: Song] - : T extends 'customRequest' - ? [url: string] - : T extends 'requestedSongFromURL' - ? [url: string] - : T extends 'requestedPlaylistFromURL' - ? [url: string] - : T extends 'requestSearchResult' - ? [term: string] - : T extends 'requestedLyrics' - ? [song: Song] - : [] - -export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' - ? GetPlaylistReturnType | void - : T extends 'requestedPlaylistSongs' - ? GetPlaylistSongsReturnType | void - : T extends 'playbackDetailsRequested' - ? GetPlaybackDetailsReturnType | void - : T extends 'customRequest' - ? CustomRequestReturnType | void - : T extends 'requestedSongFromURL' - ? GetSongReturnType | void - : T extends 'requestedPlaylistFromURL' - ? GetPlaylistAndSongsReturnType | void - : T extends 'requestSearchResult' - ? GetSearchReturnType | void - : T extends 'requestedRecommendations' - ? GetRecommendationsReturnType | void - : T extends 'requestedLyrics' - ? string | void - : void - export type ExtensionContextMenuItem = { type: T label: string @@ -576,36 +576,128 @@ export interface extensionAPI { openExternalURL(url: string): Promise /** - * Register extra events callbacks. At any time only one callback can be assigned to one event - * - * Event-callback map: - * - * "requestedPlaylists": () => Promise<{@link GetPlaylistReturnType}> - * - * "requestedPlaylistSongs": (playlist_id: string) => Promise<{@link GetPlaylistSongsReturnType}> - * - * "oauthCallback": (url: string}) => void - * - * "songQueueChanged": (queue: {@link SongQueue}) => void - * - * "seeked": (time: number) => void - * - * "volumeChanged": (volume: number) => void - * - * "playerStateChanged": (state: {@link PlayerState}) => void + * Event fired when playlists are requested by the user + * The callback should return and result playlists or undefined + */ + on( + eventName: 'requestedPlaylists', + callback: (invalidateCache: boolean) => Promise + ): void + + /** + * Event fired when songs of a single playlist are requested by the user + * The callback should return result songs or undefined + */ + on( + eventName: 'requestedPlaylistSongs', + callback: (playlistID: string, invalidateCache: boolean) => Promise + ): void + + /** + * Event fired when moosync is passed url containing registered oauth channel name + * Oauth channel should be registered using {@link registerOAuth} + */ + on(eventName: 'oauthCallback', callback: (url: string) => Promise): void + + /** + * Event fired when song queue changes order or new song is added or removed + */ + on(eventName: 'songQueueChanged', callback: (songQueue: SongQueue) => Promise): void + + /** + * Event fired when user seeks player manually + */ + on(eventName: 'seeked', callback: (newTime: number) => Promise): void + + /** + * Event fired when user changes volume + */ + on(eventName: 'volumeChanged', callback: (newVolume: number) => Promise): void + + /** + * Event fired when player changes state to / from paused, stopped, playing, loading + */ + on(eventName: 'playerStateChanged', callback: (newState: PlayerState) => Promise): void + + /** + * Event fired when new song is loaded into player + */ + on(eventName: 'songChanged', callback: (song: Song) => Promise): void + + /** + * Event fired when preferences corresponding to the extension are changed + */ + on(eventName: 'preferenceChanged', callback: (preference: { key: string; value: unknown }) => Promise): void + + /** + * Event fired when song provided by the extension lacks {@link Song.playbackUrl} or {@link Song.duration} + * Callback should return both playbackUrl and duration even if only either is missing or undefined. * - * "songChanged": (song: {@link Song}) => void + * Can be used to dynamically provide playbackUrl and/or duration + */ + on( + eventName: 'playbackDetailsRequested', + callback: (song: Song) => Promise + ): void + + /** + * Event fired when custom url corresponding to the extension is called + * Callback should return data as buffer and mimetype for the same or undefined * - * "preferenceChanged": (preference: {key: string, value: unknown}) => void + * if an url ```extension://moosync.extension.packageName/testData``` is provided to Moosync. When the url is fetched, + * this event will be triggered and custom data can be provided at runtime * + * @example + * const song: Song = { + * ..., + * song_coverPath_high: 'extension://moosync.extension.packageName/coverPathUrl', + * ... + * playbackUrl: 'extension://moosync.extension.packageName/testData' + * } + */ + on(eventName: 'customRequest', callback: (url: string) => Promise): void + + /** + * Event fired when user enters url in 'Add song from URL' modal + * Callback should return parsed song or undefined + */ + on(eventName: 'requestedSongFromURL', callback: (url: string) => Promise): void + + /** + * Event fired when user enters url in 'Add playlist from URL' modal + * Callback should return a playlist and parsed songs in that playlist or undefined + */ + on( + eventName: 'requestedPlaylistFromURL', + callback: (url: string) => Promise + ): void + + /** + * Event fired when user searches a term in search page + * Callback should return a providerName and result songs or undefined + */ + on(eventName: 'requestSearchResult', callback: (term: string) => Promise): void + + /** + * Event fired when user opens Explore page + * Callback should return a providerName and result songs or undefined + */ + on(eventName: 'requestedRecommendations', callback: () => Promise): void + + /** + * Event fired when lyrics are requested for a song + * Callback should return a string (HTML formatting) with lyrics or undefined + */ + on(eventName: 'requestedLyrics', callback: (song: Song) => Promise): void + + /** + * Register extra events callbacks. At any time only one callback can be assigned to one event * * @param eventName Name of event * @param callback Callback fired when event is emitted */ - on( - eventName: T, - callback: (...args: ExtraExtensionEventData) => Promise> - ): void + // eslint-disable-next-line @typescript-eslint/ban-types + on(eventName: string, callback: Function): void /** * Remove callbacks from extra events From 78e367248c1982aaf8a07dc356342a5adc6a7119 Mon Sep 17 00:00:00 2001 From: Types update Date: Tue, 31 May 2022 13:01:58 +0000 Subject: [PATCH 13/26] sync from Moosync --- index.d.ts | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/index.d.ts b/index.d.ts index 87543b6..1acf9bd 100644 --- a/index.d.ts +++ b/index.d.ts @@ -456,7 +456,7 @@ export type AccountDetails = { username?: string } -export type LoginModalData = { +export type LoginModalOptions = { providerName: string providerColor: string text?: string @@ -690,15 +690,6 @@ export interface extensionAPI { */ on(eventName: 'requestedLyrics', callback: (song: Song) => Promise): void - /** - * Register extra events callbacks. At any time only one callback can be assigned to one event - * - * @param eventName Name of event - * @param callback Callback fired when event is emitted - */ - // eslint-disable-next-line @typescript-eslint/ban-types - on(eventName: string, callback: Function): void - /** * Remove callbacks from extra events * @param eventName name of event whose callback is to be removed @@ -751,9 +742,30 @@ export interface extensionAPI { */ changeAccountAuthStatus(id: string, loggedIn: boolean, username?: string): Promise - openLoginModal(data: LoginModalData): Promise + /** + * Open login modal. Show the modal if the extension demands the user to open a linux + * to fulfill OAuth requirements. + * + * The modal also allows the user to manually enter a token or manually click a button when + * the task is fulfilled + * + * @param options options to control the oauth modal + */ + openLoginModal(options: LoginModalOptions): Promise + + /** + * Close login modal if its open + */ closeLoginModal(): Promise + /** + * Show toast on top-right of screen + * @param message message to show in toast + * @param duration duration of toast in milliseconds. Maximum 5000ms + * @param type type of toast. Usually denotes color + */ + showToast(message: string, duration?: number, type?: 'success' | 'info' | 'error' | 'default') + /** * Object containing controls for player */ From a67f444dc53aac0cc7ac7f32b6cc00a344e43583 Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 11 Jun 2022 11:11:59 +0000 Subject: [PATCH 14/26] sync from Moosync --- index.d.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1acf9bd..874f039 100644 --- a/index.d.ts +++ b/index.d.ts @@ -14,6 +14,15 @@ export interface Artists { artist_mbid?: string artist_coverPath?: string artist_song_count?: number + artist_extra_info?: { + youtube?: { + channel_id?: string + } + spotify?: { + artist_id?: string + } + extensions?: Record> + } } export interface Genre { @@ -246,7 +255,7 @@ export interface SongAPIOptions { * Options for searching entities like Albums, Artists, Playlists or Genre * */ -export type EntityApiOptions = { +export type EntityApiOptions = { /** * If false, then the exact match of all options will be provided. * If true, then even if an entity matches one of the options, it will be returned. @@ -260,20 +269,23 @@ export type EntityApiOptions = { * If inclusive is false then albums having album_name as 'aaa' OR album_id as 'bbb' will be returned */ inclusive?: boolean -} & ( - | { - album: Partial | boolean - } - | { +} & (T extends Artists + ? { artist: Partial | boolean } - | { + : T extends Album + ? { + album: Partial | boolean + } + : T extends Genre + ? { genre: Partial | boolean } - | { + : T extends Playlist + ? { playlist: Partial | boolean } -) + : Record) /** * Methods to control the audio player in Moosync From af493b7a845c0bafd9b57e66ec7bf45844b84e07 Mon Sep 17 00:00:00 2001 From: Types update Date: Mon, 13 Jun 2022 12:30:47 +0000 Subject: [PATCH 15/26] sync from Moosync --- index.d.ts | 84 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/index.d.ts b/index.d.ts index 874f039..f6e3755 100644 --- a/index.d.ts +++ b/index.d.ts @@ -334,25 +334,28 @@ export type ExtraExtensionEventTypes = | 'requestSearchResult' | 'requestedRecommendations' | 'requestedLyrics' + | 'requestedArtistSongs' export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' - ? GetPlaylistReturnType | void + ? PlaylistReturnType | void : T extends 'requestedPlaylistSongs' - ? GetPlaylistSongsReturnType | void + ? SongsReturnType | void : T extends 'playbackDetailsRequested' - ? GetPlaybackDetailsReturnType | void + ? PlaybackDetailsReturnType | void : T extends 'customRequest' ? CustomRequestReturnType | void : T extends 'requestedSongFromURL' - ? GetSongReturnType | void + ? SongReturnType | void : T extends 'requestedPlaylistFromURL' - ? GetPlaylistAndSongsReturnType | void + ? PlaylistAndSongsReturnType | void : T extends 'requestSearchResult' - ? GetSearchReturnType | void + ? SongsReturnType | void : T extends 'requestedRecommendations' ? GetRecommendationsReturnType | void : T extends 'requestedLyrics' ? string | void + : T extends 'requestedArtistSongs' + ? SongsReturnType : void export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' @@ -385,17 +388,19 @@ export type ExtraExtensionEventData = T exte ? [term: string] : T extends 'requestedLyrics' ? [song: Song] + : T extends 'requestedArtistSongs' + ? [artist: Artists] : [] -export type GetPlaylistReturnType = { +export type PlaylistReturnType = { playlists: Playlist[] } -export type GetPlaylistSongsReturnType = { +export type SongsReturnType = { songs: Song[] } -export type GetPlaybackDetailsReturnType = { +export type PlaybackDetailsReturnType = { duration: number url: string } @@ -405,21 +410,16 @@ export type CustomRequestReturnType = { data: Buffer } -export type GetSongReturnType = { +export type SongReturnType = { song: Song } -export type GetPlaylistAndSongsReturnType = { +export type PlaylistAndSongsReturnType = { playlist: Playlist songs: Song[] } -export type GetSearchReturnType = { - providerName: string - songs: Song[] -} - -export type GetRecommendationsReturnType = { +export type RecommendationsReturnType = { providerName: string songs: Song[] } @@ -591,10 +591,7 @@ export interface extensionAPI { * Event fired when playlists are requested by the user * The callback should return and result playlists or undefined */ - on( - eventName: 'requestedPlaylists', - callback: (invalidateCache: boolean) => Promise - ): void + on(eventName: 'requestedPlaylists', callback: (invalidateCache: boolean) => Promise): void /** * Event fired when songs of a single playlist are requested by the user @@ -602,7 +599,7 @@ export interface extensionAPI { */ on( eventName: 'requestedPlaylistSongs', - callback: (playlistID: string, invalidateCache: boolean) => Promise + callback: (playlistID: string, invalidateCache: boolean) => Promise ): void /** @@ -647,10 +644,7 @@ export interface extensionAPI { * * Can be used to dynamically provide playbackUrl and/or duration */ - on( - eventName: 'playbackDetailsRequested', - callback: (song: Song) => Promise - ): void + on(eventName: 'playbackDetailsRequested', callback: (song: Song) => Promise): void /** * Event fired when custom url corresponding to the extension is called @@ -673,28 +667,28 @@ export interface extensionAPI { * Event fired when user enters url in 'Add song from URL' modal * Callback should return parsed song or undefined */ - on(eventName: 'requestedSongFromURL', callback: (url: string) => Promise): void + on(eventName: 'requestedSongFromURL', callback: (url: string) => Promise): void /** * Event fired when user enters url in 'Add playlist from URL' modal * Callback should return a playlist and parsed songs in that playlist or undefined */ - on( - eventName: 'requestedPlaylistFromURL', - callback: (url: string) => Promise - ): void + on(eventName: 'requestedPlaylistFromURL', callback: (url: string) => Promise): void /** * Event fired when user searches a term in search page * Callback should return a providerName and result songs or undefined + * + * Requires extension to be registered as a provider using {@link registerSearchProvider} + */ - on(eventName: 'requestSearchResult', callback: (term: string) => Promise): void + on(eventName: 'requestSearchResult', callback: (term: string) => Promise): void /** * Event fired when user opens Explore page * Callback should return a providerName and result songs or undefined */ - on(eventName: 'requestedRecommendations', callback: () => Promise): void + on(eventName: 'requestedRecommendations', callback: () => Promise): void /** * Event fired when lyrics are requested for a song @@ -702,6 +696,14 @@ export interface extensionAPI { */ on(eventName: 'requestedLyrics', callback: (song: Song) => Promise): void + /** + * Event fired when songs by a particular artist are requested + * Callback should return parsed songs or undefined + * + * Requires extension to be registered as a provider using {@link registerArtistSongProvider} + */ + on(eventName: 'requestedArtistSongs', callback: (artist: Artists) => Promise) + /** * Remove callbacks from extra events * @param eventName name of event whose callback is to be removed @@ -778,6 +780,22 @@ export interface extensionAPI { */ showToast(message: string, duration?: number, type?: 'success' | 'info' | 'error' | 'default') + /** + * Register extension as provider of search results. 'requestSearchResult' can be + * listened after calling this method. + * + * @param title Title to show in search page + */ + registerSearchProvider(title: string): void + + /** + * Register extension as provider of artist songs. 'requestedArtistSongs' can be + * listened after calling this method + * + * @param title Title to show in artists page + */ + registerArtistSongProvider(title: string): void + /** * Object containing controls for player */ From ffaa57dad56fa1cc857cd6cb438cc6d856c9fbb8 Mon Sep 17 00:00:00 2001 From: Types update Date: Mon, 13 Jun 2022 16:39:38 +0000 Subject: [PATCH 16/26] sync from Moosync --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index f6e3755..1281f23 100644 --- a/index.d.ts +++ b/index.d.ts @@ -551,7 +551,7 @@ export interface extensionAPI { * @param songs 1 or more songs that are to be added to library * @returns array of booleans with same index as song. True means song has been added successfully */ - addSongs(...songs: Song[]): Promise + addSongs(...songs: Song[]): Promise<(Song | undefined)[] | undefined> /** * Remove song from library From 8372f86c0781f34adc2ada7577428cc5536159b7 Mon Sep 17 00:00:00 2001 From: Types update Date: Thu, 23 Jun 2022 19:52:14 +0000 Subject: [PATCH 17/26] sync from Moosync --- index.d.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1281f23..b3652f3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,7 +21,7 @@ export interface Artists { spotify?: { artist_id?: string } - extensions?: Record> + extensions?: Record | undefined> } } @@ -331,7 +331,7 @@ export type ExtraExtensionEventTypes = | 'customRequest' | 'requestedSongFromURL' | 'requestedPlaylistFromURL' - | 'requestSearchResult' + | 'requestedSearchResult' | 'requestedRecommendations' | 'requestedLyrics' | 'requestedArtistSongs' @@ -348,7 +348,7 @@ export type ExtraExtensionEventReturnType = ? SongReturnType | void : T extends 'requestedPlaylistFromURL' ? PlaylistAndSongsReturnType | void - : T extends 'requestSearchResult' + : T extends 'requestedSearchResult' ? SongsReturnType | void : T extends 'requestedRecommendations' ? GetRecommendationsReturnType | void @@ -384,7 +384,7 @@ export type ExtraExtensionEventData = T exte ? [url: string] : T extends 'requestedPlaylistFromURL' ? [url: string] - : T extends 'requestSearchResult' + : T extends 'requestedSearchResult' ? [term: string] : T extends 'requestedLyrics' ? [song: Song] @@ -400,6 +400,13 @@ export type SongsReturnType = { songs: Song[] } +export type SearchReturnType = { + songs: Song[] + playlists: Playlist[] + artists: Artists[] + albums: Album[] +} + export type PlaybackDetailsReturnType = { duration: number url: string @@ -682,7 +689,7 @@ export interface extensionAPI { * Requires extension to be registered as a provider using {@link registerSearchProvider} */ - on(eventName: 'requestSearchResult', callback: (term: string) => Promise): void + on(eventName: 'requestedSearchResult', callback: (term: string) => Promise): void /** * Event fired when user opens Explore page @@ -781,7 +788,7 @@ export interface extensionAPI { showToast(message: string, duration?: number, type?: 'success' | 'info' | 'error' | 'default') /** - * Register extension as provider of search results. 'requestSearchResult' can be + * Register extension as provider of search results. 'requestedSearchResult' can be * listened after calling this method. * * @param title Title to show in search page From 9083e6ec4eadd21d07a7d596edeec396699f728b Mon Sep 17 00:00:00 2001 From: Types update Date: Fri, 24 Jun 2022 17:20:59 +0000 Subject: [PATCH 18/26] sync from Moosync --- index.d.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.d.ts b/index.d.ts index b3652f3..94b0519 100644 --- a/index.d.ts +++ b/index.d.ts @@ -491,7 +491,16 @@ export type LoginModalOptions = { } ) +export interface utils { + /** + * Helper function that returns extra info stored by this extension only + */ + getArtistExtraInfo(artist: Artists): Record | undefined +} + export interface extensionAPI { + utils: utils + /** * Get songs from database filtered by provided options * @param options filter the results @@ -803,6 +812,13 @@ export interface extensionAPI { */ registerArtistSongProvider(title: string): void + /** + * Set extra info for an artist. This info is editable by the user using "Show info" context menu + * option on artist + * @param object Key-value pairs of editable info + */ + setArtistEditableInfo(artist_id: string, object: Record): Promise + /** * Object containing controls for player */ From 83670ffbf3eab0fb4774df5fcb9788d2dd1ef7c0 Mon Sep 17 00:00:00 2001 From: Types update Date: Fri, 24 Jun 2022 17:59:27 +0000 Subject: [PATCH 19/26] sync from Moosync --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 94b0519..b01257e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -349,7 +349,7 @@ export type ExtraExtensionEventReturnType = : T extends 'requestedPlaylistFromURL' ? PlaylistAndSongsReturnType | void : T extends 'requestedSearchResult' - ? SongsReturnType | void + ? SearchReturnType | void : T extends 'requestedRecommendations' ? GetRecommendationsReturnType | void : T extends 'requestedLyrics' @@ -500,6 +500,7 @@ export interface utils { export interface extensionAPI { utils: utils + packageName: string /** * Get songs from database filtered by provided options From 44cec02027319b9db53c5f327b21431835693cde Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 25 Jun 2022 12:36:51 +0000 Subject: [PATCH 20/26] sync from Moosync --- index.d.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.d.ts b/index.d.ts index b01257e..2e035d1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,6 +5,9 @@ export interface Album { album_coverPath_low?: string album_song_count?: number album_artist?: string + album_extra_info?: { + extensions?: Record | undefined> + } year?: number } @@ -335,6 +338,7 @@ export type ExtraExtensionEventTypes = | 'requestedRecommendations' | 'requestedLyrics' | 'requestedArtistSongs' + | 'requestedAlbumSongs' export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' ? PlaylistReturnType | void @@ -356,6 +360,8 @@ export type ExtraExtensionEventReturnType = ? string | void : T extends 'requestedArtistSongs' ? SongsReturnType + : T extends 'requestedAlbumSongs' + ? SongsReturnType : void export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' @@ -390,6 +396,8 @@ export type ExtraExtensionEventData = T exte ? [song: Song] : T extends 'requestedArtistSongs' ? [artist: Artists] + : T extends 'requestedAlbumSongs' + ? [album: Album] : [] export type PlaylistReturnType = { @@ -721,6 +729,14 @@ export interface extensionAPI { */ on(eventName: 'requestedArtistSongs', callback: (artist: Artists) => Promise) + /** + * Event fired when songs by a particular album are requested + * Callback should return parsed songs or undefined + * + * Requires extension to be registered as a provider using {@link registerAlbumSongProvider} + */ + on(eventName: 'requestedAlbumSongs', callback: (album: Album) => Promise) + /** * Remove callbacks from extra events * @param eventName name of event whose callback is to be removed @@ -813,6 +829,14 @@ export interface extensionAPI { */ registerArtistSongProvider(title: string): void + /** + * Register extension as provider of album songs. 'requestedAlbumSongs' can be + * listened after calling this method + * + * @param title Title to show in albums page + */ + registerAlbumSongProvider(title: string): void + /** * Set extra info for an artist. This info is editable by the user using "Show info" context menu * option on artist @@ -820,6 +844,13 @@ export interface extensionAPI { */ setArtistEditableInfo(artist_id: string, object: Record): Promise + /** + * Set extra info for an album. This info is editable by the user using "Show info" context menu + * option on album + * @param object Key-value pairs of editable info + */ + setAlbumEditableInfo(artist_id: string, object: Record): Promise + /** * Object containing controls for player */ From d06f329dcc2157fbf8428b4e79071c06690e1c55 Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 25 Jun 2022 13:40:52 +0000 Subject: [PATCH 21/26] sync from Moosync --- index.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.d.ts b/index.d.ts index 2e035d1..cdfb6a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,6 +6,9 @@ export interface Album { album_song_count?: number album_artist?: string album_extra_info?: { + spotify?: { + album_id?: string + } extensions?: Record | undefined> } year?: number @@ -504,6 +507,11 @@ export interface utils { * Helper function that returns extra info stored by this extension only */ getArtistExtraInfo(artist: Artists): Record | undefined + + /** + * Helper function that returns extra info stored by this extension only + */ + getAlbumExtraInfo(album: Album): Record | undefined } export interface extensionAPI { From 820cc8c1db88da37a047c76b9b4d4a7c96880fcf Mon Sep 17 00:00:00 2001 From: Types update Date: Tue, 28 Jun 2022 06:06:07 +0000 Subject: [PATCH 22/26] sync from Moosync --- index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index cdfb6a7..15ead4e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -424,8 +424,9 @@ export type PlaybackDetailsReturnType = { } export type CustomRequestReturnType = { - mimeType: string - data: Buffer + mimeType?: string + data?: Buffer + redirectUrl?: string } export type SongReturnType = { From de63d2e4ef3a29b2ee61ab021f5d08b97c6f500c Mon Sep 17 00:00:00 2001 From: Types update Date: Sun, 28 May 2023 17:23:28 +0000 Subject: [PATCH 23/26] sync from Moosync --- index.d.ts | 294 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 212 insertions(+), 82 deletions(-) diff --git a/index.d.ts b/index.d.ts index 15ead4e..d89cc09 100644 --- a/index.d.ts +++ b/index.d.ts @@ -9,6 +9,9 @@ export interface Album { spotify?: { album_id?: string } + youtube?: { + album_id?: string + } extensions?: Record | undefined> } year?: number @@ -41,13 +44,14 @@ export interface Playlist { playlist_id: string playlist_name: string playlist_desc?: string - playlist_coverPath: string | undefined + playlist_coverPath?: string | undefined playlist_song_count?: number playlist_path?: string icon?: string + extension?: string } -export type PlayerTypes = 'LOCAL' | 'YOUTUBE' | 'SPOTIFY' | 'URL' | 'DASH' +export type PlayerTypes = 'LOCAL' | 'YOUTUBE' | 'SPOTIFY' | 'URL' | 'DASH' | 'HLS' export interface Song { _id: string @@ -59,7 +63,8 @@ export interface Song { album?: Album artists?: Artists[] date?: string - year?: number + year?: number | string + genre?: string[] lyrics?: string releaseType?: string[] @@ -77,6 +82,9 @@ export interface Song { providerExtension?: string icon?: string type: PlayerTypes + playCount?: number + showInLibrary?: boolean + track_no?: number } export interface SearchableSong { @@ -89,10 +97,16 @@ export interface SearchableSong { // MD5 hash hash?: string + size?: number + inode?: string + deviceno?: string + type?: PlayerTypes // Will return all songs provided by this extension extension?: boolean | string + + showInLibrary?: boolean } export type PlayerState = 'PLAYING' | 'PAUSED' | 'STOPPED' | 'LOADING' @@ -141,8 +155,9 @@ export interface Buttons { export type ExtensionPreferenceGroup = { key: string - title: string - description: string + title?: string + description?: string + index?: number } & ( | { type: 'CheckboxGroup' @@ -172,12 +187,25 @@ export type ExtensionPreferenceGroup = { type: 'ProgressBar' default: number } + | { + type: 'TextField' + default: string + } + | { + type: 'InfoField' + default: string + } ) export interface ExtensionFactory { - // Return an instance of the plugin + /** + * @deprecated + * */ registerPreferences?(): Promise + // Return an instance of the plugin + registerUserPreferences?(): Promise + /** * This method is necessary for the extension to be loaded into moosync */ @@ -240,7 +268,7 @@ export interface SongAPIOptions { /** * To sort the results, specify this property */ - sortBy?: SongSortOptions + sortBy?: SongSortOptions | SongSortOptions[] /** * If false, then the exact match of all options will be provided. @@ -249,12 +277,22 @@ export interface SongAPIOptions { * * Eg. If song.title is 'aaa' and album.album_name is 'bbb' * - * In this scenario if inclusive is false, then all tracks having title as 'aaa' + * In this scenario if inclusive is true, then all tracks having title as 'aaa' * AND album_name as 'bbb' will be returned * * If inclusive is false then songs having title as 'aaa' OR album_name as 'bbb' will be returned + * + * False by default */ inclusive?: boolean + + /** + * If true, then inverts the query. It will return all records which don't match the search criteria + * If false, then it will return all records which match the search criteria + * + * false by default + */ + invert?: boolean } /** @@ -275,6 +313,14 @@ export type EntityApiOptions = { * If inclusive is false then albums having album_name as 'aaa' OR album_id as 'bbb' will be returned */ inclusive?: boolean + + /** + * If true, then inverts the query. It will return all records which don't match the search criteria + * If false, then it will return all records which match the search criteria + * + * false by default + */ + invert?: boolean } & (T extends Artists ? { artist: Partial | boolean @@ -342,33 +388,37 @@ export type ExtraExtensionEventTypes = | 'requestedLyrics' | 'requestedArtistSongs' | 'requestedAlbumSongs' - -export type ExtraExtensionEventReturnType = T extends 'requestedPlaylists' - ? PlaylistReturnType | void - : T extends 'requestedPlaylistSongs' - ? SongsReturnType | void - : T extends 'playbackDetailsRequested' - ? PlaybackDetailsReturnType | void - : T extends 'customRequest' - ? CustomRequestReturnType | void - : T extends 'requestedSongFromURL' - ? SongReturnType | void - : T extends 'requestedPlaylistFromURL' - ? PlaylistAndSongsReturnType | void - : T extends 'requestedSearchResult' - ? SearchReturnType | void - : T extends 'requestedRecommendations' - ? GetRecommendationsReturnType | void - : T extends 'requestedLyrics' - ? string | void - : T extends 'requestedArtistSongs' - ? SongsReturnType - : T extends 'requestedAlbumSongs' - ? SongsReturnType - : void - -export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' - ? [playlistID: string, invalidateCache: boolean] + | 'songAdded' + | 'songRemoved' + | 'playlistAdded' + | 'playlistRemoved' + | 'requestedSongFromId' + | 'getRemoteURL' + +export type ExtraExtensionEventReturnType = + | (T extends 'requestedPlaylists' + ? PlaylistReturnType + : T extends 'requestedPlaylistSongs' | 'requestedArtistSongs' | 'requestedAlbumSongs' + ? SongsWithPageTokenReturnType | ForwardRequestReturnType + : T extends 'playbackDetailsRequested' + ? PlaybackDetailsReturnType | ForwardRequestReturnType + : T extends 'customRequest' + ? CustomRequestReturnType + : T extends 'requestedSongFromURL' | 'requestedSongFromId' + ? SongReturnType | ForwardRequestReturnType + : T extends 'requestedPlaylistFromURL' + ? PlaylistAndSongsReturnType | ForwardRequestReturnType + : T extends 'requestedSearchResult' + ? SearchReturnType | ForwardRequestReturnType + : T extends 'requestedRecommendations' + ? RecommendationsReturnType | ForwardRequestReturnType + : T extends 'requestedLyrics' | 'getRemoteURL' + ? string | ForwardRequestReturnType + : void) + | void + +export type ExtraExtensionEventData = T extends 'requestedPlaylistSongs' + ? [playlistID: string, invalidateCache: boolean, nextPageToken: unknown | undefined] : T extends 'requestedPlaylists' ? [invalidateCache: boolean] : T extends 'oauthCallback' @@ -390,18 +440,26 @@ export type ExtraExtensionEventData = T exte : T extends 'customRequest' ? [url: string] : T extends 'requestedSongFromURL' - ? [url: string] + ? [url: string, invalidateCache: boolean] : T extends 'requestedPlaylistFromURL' - ? [url: string] + ? [url: string, invalidateCache: boolean] : T extends 'requestedSearchResult' ? [term: string] : T extends 'requestedLyrics' ? [song: Song] : T extends 'requestedArtistSongs' - ? [artist: Artists] + ? [artist: Artists, nextPageToken: unknown | undefined] : T extends 'requestedAlbumSongs' - ? [album: Album] - : [] + ? [album: Album, nextPageToken: unknown | undefined] + : T extends 'songAdded' | 'songRemoved' + ? [songs: Song[]] + : T extends 'playlistAdded' | 'playlistRemoved' + ? [playlists: Playlist[]] + : T extends 'requestedSongFromId' + ? [id: string] + : T extends 'getRemoteURL' + ? [song: Song] + : never[] export type PlaylistReturnType = { playlists: Playlist[] @@ -411,6 +469,11 @@ export type SongsReturnType = { songs: Song[] } +export type SongsWithPageTokenReturnType = { + songs: Song[] + nextPageToken?: unknown +} + export type SearchReturnType = { songs: Song[] playlists: Playlist[] @@ -439,7 +502,6 @@ export type PlaylistAndSongsReturnType = { } export type RecommendationsReturnType = { - providerName: string songs: Song[] } @@ -451,6 +513,11 @@ export type ExtensionContextMenuItem = { handler?: (arg: ExtensionContextMenuHandlerArgs) => void } +export type ForwardRequestReturnType = { + forwardTo: 'youtube' | 'spotify' | string + transformedData?: ExtraExtensionEventData +} + export type ContextMenuTypes = | 'SONGS' | 'GENERAL_SONGS' @@ -513,11 +580,13 @@ export interface utils { * Helper function that returns extra info stored by this extension only */ getAlbumExtraInfo(album: Album): Record | undefined + + readonly packageName: string + readonly customRequestBaseUrl: string } export interface extensionAPI { utils: utils - packageName: string /** * Get songs from database filtered by provided options @@ -525,6 +594,12 @@ export interface extensionAPI { */ getSongs(options: SongAPIOptions): Promise + /** + * Get entities such as playlists, artists, albums, genres from database by provided options + * @param options filter the results + */ + getEntity(options: EntityApiOptions): Promise + /** * Get the current playing track. Undefined if no track is playing */ @@ -588,11 +663,18 @@ export interface extensionAPI { addSongs(...songs: Song[]): Promise<(Song | undefined)[] | undefined> /** + * @deprecated pass song instead of song_id * Remove song from library * @param song_id id of song to remove */ removeSong(song_id: string): Promise + /** + * Remove song from library + * @param song song to remove + */ + removeSong(song: Song): Promise + /** * Add playlist to library * @param playlist details of playlist which is to be added to library @@ -633,7 +715,11 @@ export interface extensionAPI { */ on( eventName: 'requestedPlaylistSongs', - callback: (playlistID: string, invalidateCache: boolean) => Promise + callback: ( + playlistID: string, + invalidateCache: boolean, + nextPageToken?: unknown + ) => Promise | void> ): void /** @@ -678,7 +764,12 @@ export interface extensionAPI { * * Can be used to dynamically provide playbackUrl and/or duration */ - on(eventName: 'playbackDetailsRequested', callback: (song: Song) => Promise): void + on( + eventName: 'playbackDetailsRequested', + callback: ( + song: Song + ) => Promise | void> + ): void /** * Event fired when custom url corresponding to the extension is called @@ -701,50 +792,101 @@ export interface extensionAPI { * Event fired when user enters url in 'Add song from URL' modal * Callback should return parsed song or undefined */ - on(eventName: 'requestedSongFromURL', callback: (url: string) => Promise): void + on( + eventName: 'requestedSongFromURL', + callback: (url: string) => Promise | void> + ): void /** * Event fired when user enters url in 'Add playlist from URL' modal * Callback should return a playlist and parsed songs in that playlist or undefined */ - on(eventName: 'requestedPlaylistFromURL', callback: (url: string) => Promise): void + on( + eventName: 'requestedPlaylistFromURL', + callback: ( + url: string + ) => Promise | void> + ): void /** * Event fired when user searches a term in search page * Callback should return a providerName and result songs or undefined - * - * Requires extension to be registered as a provider using {@link registerSearchProvider} - */ - on(eventName: 'requestedSearchResult', callback: (term: string) => Promise): void + on( + eventName: 'requestedSearchResult', + callback: (term: string) => Promise | void> + ): void /** * Event fired when user opens Explore page * Callback should return a providerName and result songs or undefined */ - on(eventName: 'requestedRecommendations', callback: () => Promise): void + on( + eventName: 'requestedRecommendations', + callback: () => Promise | void> + ): void /** * Event fired when lyrics are requested for a song * Callback should return a string (HTML formatting) with lyrics or undefined */ - on(eventName: 'requestedLyrics', callback: (song: Song) => Promise): void + on( + eventName: 'requestedLyrics', + callback: (song: Song) => Promise | void> + ): void /** * Event fired when songs by a particular artist are requested * Callback should return parsed songs or undefined - * - * Requires extension to be registered as a provider using {@link registerArtistSongProvider} */ - on(eventName: 'requestedArtistSongs', callback: (artist: Artists) => Promise) + on( + eventName: 'requestedArtistSongs', + callback: ( + artist: Artists, + nextPageToken?: unknown + ) => Promise | void> + ): void /** * Event fired when songs by a particular album are requested * Callback should return parsed songs or undefined - * - * Requires extension to be registered as a provider using {@link registerAlbumSongProvider} */ - on(eventName: 'requestedAlbumSongs', callback: (album: Album) => Promise) + on( + eventName: 'requestedAlbumSongs', + callback: ( + album: Album, + nextPageToken?: unknown + ) => Promise | void> + ): void + + /** + * Event fired when the app only has id for the song but requires complete details + * Callback should return parsed song or undefined + */ + on( + eventName: 'requestedSongFromId', + callback: (url: string) => Promise | void> + ): void + + /** + * Event fired when songs are added to library + */ + on(eventName: 'songAdded', callback: (songs: Song[]) => Promise): void + + /** + * Event fired when songs are removed from library + */ + on(eventName: 'songRemoved', callback: (songs: Song[]) => Promise): void + + /** + * Event fired when playlist is added to library + */ + on(eventName: 'playlistAdded', callback: (playlist: Playlist[]) => Promise): void + + /** + * Event fired when playlist is removed from library + */ + on(eventName: 'playlistRemoved', callback: (songs: Playlist[]) => Promise): void /** * Remove callbacks from extra events @@ -822,30 +964,6 @@ export interface extensionAPI { */ showToast(message: string, duration?: number, type?: 'success' | 'info' | 'error' | 'default') - /** - * Register extension as provider of search results. 'requestedSearchResult' can be - * listened after calling this method. - * - * @param title Title to show in search page - */ - registerSearchProvider(title: string): void - - /** - * Register extension as provider of artist songs. 'requestedArtistSongs' can be - * listened after calling this method - * - * @param title Title to show in artists page - */ - registerArtistSongProvider(title: string): void - - /** - * Register extension as provider of album songs. 'requestedAlbumSongs' can be - * listened after calling this method - * - * @param title Title to show in albums page - */ - registerAlbumSongProvider(title: string): void - /** * Set extra info for an artist. This info is editable by the user using "Show info" context menu * option on artist @@ -860,8 +978,20 @@ export interface extensionAPI { */ setAlbumEditableInfo(artist_id: string, object: Record): Promise + /** + * Returns a list of package names of all installed extensions + */ + getInstalledExtensions(): string[] + + addUserPreference(pref: ExtensionPreferenceGroup): void + removeUserPreference(key: string): void + /** * Object containing controls for player */ player: playerControls } + +declare global { + const api: extensionAPI +} From 080281a172cd5fafa9114ab62c0fbf49482a2076 Mon Sep 17 00:00:00 2001 From: Types update Date: Sat, 29 Jul 2023 12:49:15 +0000 Subject: [PATCH 24/26] sync from Moosync --- index.d.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.d.ts b/index.d.ts index d89cc09..ef3f3b5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -718,8 +718,8 @@ export interface extensionAPI { callback: ( playlistID: string, invalidateCache: boolean, - nextPageToken?: unknown - ) => Promise | void> + nextPageToken?: unknown, + ) => Promise | void>, ): void /** @@ -767,8 +767,8 @@ export interface extensionAPI { on( eventName: 'playbackDetailsRequested', callback: ( - song: Song - ) => Promise | void> + song: Song, + ) => Promise | void>, ): void /** @@ -794,7 +794,7 @@ export interface extensionAPI { */ on( eventName: 'requestedSongFromURL', - callback: (url: string) => Promise | void> + callback: (url: string) => Promise | void>, ): void /** @@ -804,8 +804,8 @@ export interface extensionAPI { on( eventName: 'requestedPlaylistFromURL', callback: ( - url: string - ) => Promise | void> + url: string, + ) => Promise | void>, ): void /** @@ -814,7 +814,7 @@ export interface extensionAPI { */ on( eventName: 'requestedSearchResult', - callback: (term: string) => Promise | void> + callback: (term: string) => Promise | void>, ): void /** @@ -823,7 +823,7 @@ export interface extensionAPI { */ on( eventName: 'requestedRecommendations', - callback: () => Promise | void> + callback: () => Promise | void>, ): void /** @@ -832,7 +832,7 @@ export interface extensionAPI { */ on( eventName: 'requestedLyrics', - callback: (song: Song) => Promise | void> + callback: (song: Song) => Promise | void>, ): void /** @@ -843,8 +843,8 @@ export interface extensionAPI { eventName: 'requestedArtistSongs', callback: ( artist: Artists, - nextPageToken?: unknown - ) => Promise | void> + nextPageToken?: unknown, + ) => Promise | void>, ): void /** @@ -855,8 +855,8 @@ export interface extensionAPI { eventName: 'requestedAlbumSongs', callback: ( album: Album, - nextPageToken?: unknown - ) => Promise | void> + nextPageToken?: unknown, + ) => Promise | void>, ): void /** @@ -865,7 +865,7 @@ export interface extensionAPI { */ on( eventName: 'requestedSongFromId', - callback: (url: string) => Promise | void> + callback: (url: string) => Promise | void>, ): void /** @@ -928,7 +928,7 @@ export interface extensionAPI { bgColor: string, icon: string, signinCallback: AccountDetails['signinCallback'], - signoutCallback: AccountDetails['signoutCallback'] + signoutCallback: AccountDetails['signoutCallback'], ): Promise /** From 380f2ccc20bbd9fe3b272bcddfb9bad9012d028e Mon Sep 17 00:00:00 2001 From: Types update Date: Sun, 13 Aug 2023 22:34:32 +0000 Subject: [PATCH 25/26] sync from Moosync --- index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.d.ts b/index.d.ts index ef3f3b5..5041ea9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -527,6 +527,7 @@ export type ContextMenuTypes = | 'QUEUE_ITEM' | 'ARTIST' | 'ALBUM' + | 'CURRENT_SONG' export type ExtensionContextMenuHandlerArgs = T extends 'SONGS' ? Song[] @@ -540,6 +541,8 @@ export type ExtensionContextMenuHandlerArgs = T exte ? Artists : T extends 'ALBUM' ? Album + : T extends 'CURRENT_SONG' + ? Song : undefined export type AccountDetails = { From 479fce1f0b68d361a8653c16a6fd7b6443745364 Mon Sep 17 00:00:00 2001 From: Types update Date: Wed, 1 Nov 2023 01:15:54 +0000 Subject: [PATCH 26/26] sync from Moosync --- index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.d.ts b/index.d.ts index 5041ea9..b236013 100644 --- a/index.d.ts +++ b/index.d.ts @@ -665,6 +665,12 @@ export interface extensionAPI { */ addSongs(...songs: Song[]): Promise<(Song | undefined)[] | undefined> + /** + * Update song in library by ID + * @param song song to update + */ + updateSong(song: Song): Promise + /** * @deprecated pass song instead of song_id * Remove song from library