diff --git a/build.config.mts b/build.config.mts index a190b96..019b371 100644 --- a/build.config.mts +++ b/build.config.mts @@ -5,7 +5,14 @@ export default defineBuildConfig({ entries: [ // default "./src/index", - { + "./src/mDNS", + { + builder: "copy", + input: "./src/api/ciderapi-types/", + outDir: "./build/api/ciderapi-types/", + // loaders: ['vue'], + }, + { builder: "copy", input: "./src/vue/", outDir: "./build/vue", diff --git a/build/api/ciderapi-types/CiderApp.d.ts b/build/api/ciderapi-types/CiderApp.d.ts new file mode 100644 index 0000000..83fd60e --- /dev/null +++ b/build/api/ciderapi-types/CiderApp.d.ts @@ -0,0 +1,114 @@ +/** + * This is the global CiderApp object, for debugging and plugin purposes. + */ +declare namespace CiderApp { + /** + * AppFS file system. + */ + const AppFS: { + /** + * Read a file from the AppFS. + */ + readFile(fileName: string): Promise, + /** + * Write a file to the AppFS. + */ + writeFile(fileName: string, contents: string): Promise, + }, + /** + * CiderFirebase class + */ + CiderFirebase: any, + /** + * CiderCompose class + */ + CiderCompose: any, + /** + * CiderPlaylists class + */ + CiderPlaylists: any, + /** + * CiderStripe class + */ + CiderStripe: any, + /** + * ClientDB + */ + DexieDB: any, + /** + * PouchDB object + */ + PouchDb: any, + /** + * Apple Music URL functions + */ + amURL: { + /** + * Open an Apple Music URL in the app. + * @param url + */ + openAppleMusicURL(url: string): void + } + /** + * Quasar + */ + const quasar: typeof import("quasar") + /** + * Vue app instance + */ + const app: import("vue").App + /** + * Pinia App state + */ + const appState: any + /** + * Cider config + */ + const config: any + /** + * Dialogs + */ + const dialogs: { + /** + * Immersive modal + */ + immersive(): void + /** + * Settings Modal + */ + settings(): void + } + /** + * Force the platform to a specific value. + * @param platform + */ + function forcePlatform(platform: undefined | null | "win32" | "linux" | "darwin"): void + /** + * Handle a protocol URL. + * @param url + */ + function handleProtocolURL(url: string): void + /** + * MusicKit Store + */ + const musicKitStore: any + /** + * Vue router instance + */ + const router: import("vue-router").Router + /** + * Pinia store + */ + const store: import("pinia").Pinia + /** + * URI handler + */ + const uriHandler: { + /** + * Call all functions that have been added to the onUri event. + * This is called by the main process when the app receives a URI. + */ + onUri(uri: string): void + } + } + \ No newline at end of file diff --git a/build/api/ciderapi-types/CiderPluginSystem.d.ts b/build/api/ciderapi-types/CiderPluginSystem.d.ts new file mode 100644 index 0000000..a54bc93 --- /dev/null +++ b/build/api/ciderapi-types/CiderPluginSystem.d.ts @@ -0,0 +1,82 @@ +interface RenderComponentOptions { + component: import('../ComponentNames').ComponentNames; + props?: Record; + // @ts-ignore + element: Element; +} + + +declare namespace __PLUGINSYS__ { + const Components: { + MainMenu: { + addMenuItem(item: import("../MenuEntry").MenuItem): import("../MenuEntry").MenuItem + removeMenuItem(item: import("../MenuEntry").MenuItem): void + items: import("../MenuEntry").MenuItem[] + }, + ImmersiveMenu: { + addMenuItem(item: import("../MenuEntry").MenuItem): import("../MenuEntry").MenuItem + removeMenuItem(item: import("../MenuEntry").MenuItem): void + items: import("../MenuEntry").MenuItem[] + }, + ImmersiveLayouts: { + addLayout(layout: import("../ImmersiveLayout.ts").CustomImmersiveLayout): void + removeLayout(layout: import("../ImmersiveLayout.ts").CustomImmersiveLayout): void + layouts: import("../ImmersiveLayout.ts").CustomImmersiveLayout[] + }, + MediaItemContextMenu: { + addMenuItem(item: import("../MenuEntry").MenuItem): import("../MenuEntry").MenuItem + removeMenuItem(item: import("../MenuEntry").MenuItem): void + removeLayoutByIdentifier(identifier: string): void + items: import("../MenuEntry").MenuItem[] + }, + CustomButtons: { + addCustomButton(opts: import("../CustomButton").CustomButtonOptions): void + removeCustomButton(opts: import("../CustomButton").CustomButtonOptions): void + buttons: import("../CustomButton").CustomButtonOptions[] + } + } + + const ExternalMessages: { + addEventListener(event: string, cb: (e: any) => void, opts?: Partial<{ once: boolean, passive: boolean, capture: boolean }>): void + removeEventListener(event: string, cb: (e: any) => void): void + dispatchEvent(event: string, data: any): void + } + + const Quasar: { + Dialog: any; + } + + const IZAPI: { + mDNS: { + createBrowser(tcp_service: string, timeout: number): { + addresses: string[] + fullname: string + host: string + interfaceIndex: number + port: number + query: string[] + txt: string[] + type: { + name: string + protocol: string + subtypes: string[] + }[] + }[] + } + } + + const PAPIInstance: { + addEventListener(event: import('./PAPIEvents').PAPIEvents, cb: (e: any) => void, opts?: Partial<{ once: boolean, passive: boolean, capture: boolean }>): void + removeEventListener(event: import('./PAPIEvents').PAPIEvents, cb: (e: any) => void): void + } + + const App: { + Components: import('../ComponentNames').ComponentNames[] + RenderComponent: (opts: RenderComponentOptions) => void + vue: { + // @ts-ignore + render: (component: any, element: Element) => void + h: (component: any, props: Record, children: any) => void + } + } +} diff --git a/build/api/ciderapi-types/ICiderApp.d.ts b/build/api/ciderapi-types/ICiderApp.d.ts new file mode 100644 index 0000000..f862094 --- /dev/null +++ b/build/api/ciderapi-types/ICiderApp.d.ts @@ -0,0 +1,111 @@ +import {App} from "vue" +/** + * This is the global CiderApp object, for debugging and plugin purposes. + */ +interface ICiderApp { + /** + * AppFS file system. + */ + AppFS: { + /** + * Read a file from the AppFS. + */ + readFile(fileName: string): Promise, + /** + * Write a file to the AppFS. + */ + writeFile(fileName: string, contents: string): Promise, + }, + /** + * CiderFirebase class + */ + CiderFirebase: any, + /** + * CiderCompose class + */ + CiderCompose: any, + /** + * CiderPlaylists class + */ + CiderPlaylists: any, + /** + * CiderStripe class + */ + CiderStripe: any, + /** + * ClientDB + */ + DexieDB: any, + /** + * PouchDB object + */ + PouchDb: any, + /** + * Apple Music URL functions + */ + amURL: { + /** + * Open an Apple Music URL in the app. + * @param url + */ + openAppleMusicURL(url: string): void, + }, + /** + * Vue app instance + */ + app: App, + /** + * Pinia App state + */ + appState: any, + /** + * Cider config + */ + config: any, + /** + * Dialogs + */ + dialogs: { + /** + * Immersive modal + */ + immersive(): void, + /** + * Settings Modal + */ + settings(): void, + }, + /** + * Force the platform to a specific value. + * @param platform + */ + forcePlatform(platform: undefined | null | "win32" | "linux" | "darwin"): void, + /** + * Handle a protocol URL. + * @param url + */ + handleProtocolURL(url: string): void, + /** + * MusicKit Store + */ + musicKitStore: any, + /** + * Vue router instance + */ + router: any, + /** + * Pinia store + */ + store: any, + /** + * URI handler + */ + uriHandler: { + /** + * Call all functions that have been added to the onUri event. + * This is called by the main process when the app receives a URI. + */ + onUri(uri: string): void, + }, + } + \ No newline at end of file diff --git a/build/api/ciderapi-types/PAPIEvents.ts b/build/api/ciderapi-types/PAPIEvents.ts new file mode 100644 index 0000000..1d1ce91 --- /dev/null +++ b/build/api/ciderapi-types/PAPIEvents.ts @@ -0,0 +1,8 @@ +export type PAPIEvents = + 'app:ready' | + 'shell:layout_type_changed' | + 'immersive:opened' | + 'immersive:closed' | + 'miniplayer:opened' | + 'miniplayer:closed' | + 'browser:page_changed' diff --git a/build/api/ciderapi-types/PAPITypes.d.ts b/build/api/ciderapi-types/PAPITypes.d.ts new file mode 100644 index 0000000..993dc31 --- /dev/null +++ b/build/api/ciderapi-types/PAPITypes.d.ts @@ -0,0 +1,14 @@ +declare namespace PAPITypes { + declare namespace App { + type Ready = {} + } + declare namespace Shell { + type LayoutTypeChanged = { + type: 'immersive' | 'miniplayer' | 'browser' + } + type ImmersiveOpened = {} + type ImmersiveClosed = {} + type MiniplayerOpened = {} + type MiniplayerClosed = {} + } +} diff --git a/build/api/ciderapi-types/index.d.ts b/build/api/ciderapi-types/index.d.ts new file mode 100644 index 0000000..cdd1099 --- /dev/null +++ b/build/api/ciderapi-types/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for musickit-js 1.0 +// Project: https://developer.apple.com/documentation/musickitjs +// Definitions by: Devid Farinelli +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// \ No newline at end of file diff --git a/build/api/ciderapi-types/tsconfig.json b/build/api/ciderapi-types/tsconfig.json new file mode 100644 index 0000000..a193eaf --- /dev/null +++ b/build/api/ciderapi-types/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + ] +} diff --git a/build/api/ciderapi-types/window.d.ts b/build/api/ciderapi-types/window.d.ts new file mode 100644 index 0000000..ac33f9e --- /dev/null +++ b/build/api/ciderapi-types/window.d.ts @@ -0,0 +1,51 @@ +interface Window { + /** + * Global object for the Cider app. + * + * Intended for debugging and plugin purposes. + */ + // CiderApp: ICiderApp + /** + * .NET Bindings + * @suspended + */ + chrome: { + webview: any + } + /** + * @deprecated + */ + go: any, + /** + * @deprecated + */ + runtime: any, + /** + * The build info of the app. + */ + __BUILDINFO__: BUILD_INFO + /** + * Tauri global object + */ + __TAURI__: any, + /** + * The version of the app. + */ + APP_VERSION: string, + + MusicKit: any, + +} + +/** + * MusicKit JS API + * + * Learn more at https://developer.apple.com/documentation/musickitjs + */ +declare const MusicKit: any; + +interface BUILD_INFO { + BUILD_DATE: string, + APP_VERSION: string, + GIT_COMMIT: string, +} \ No newline at end of file diff --git a/build/mDNS.d.mts b/build/mDNS.d.mts new file mode 100644 index 0000000..b0efe3f --- /dev/null +++ b/build/mDNS.d.mts @@ -0,0 +1,33 @@ +type mDNSDiscoverProps = { + /** + * The TCP service to discover by name + */ + tcp_service: string; + /** + * How long to wait for responses in milliseconds + * @default 5000 + */ + timeout?: number; +}; +/** + * Creates an new mDNS browser to discover services and devices on the network + * + * @param options - The options to use when discovering services + * @returns An array of objects representing the discovered services + */ +declare function mDNSDiscover(options: mDNSDiscoverProps): Promise<{ + addresses: string[]; + fullname: string; + host: string; + interfaceIndex: number; + port: number; + query: string[]; + txt: string[]; + type: { + name: string; + protocol: string; + subtypes: string[]; + }[]; +}[]>; + +export { mDNSDiscover }; diff --git a/build/mDNS.d.ts b/build/mDNS.d.ts new file mode 100644 index 0000000..b0efe3f --- /dev/null +++ b/build/mDNS.d.ts @@ -0,0 +1,33 @@ +type mDNSDiscoverProps = { + /** + * The TCP service to discover by name + */ + tcp_service: string; + /** + * How long to wait for responses in milliseconds + * @default 5000 + */ + timeout?: number; +}; +/** + * Creates an new mDNS browser to discover services and devices on the network + * + * @param options - The options to use when discovering services + * @returns An array of objects representing the discovered services + */ +declare function mDNSDiscover(options: mDNSDiscoverProps): Promise<{ + addresses: string[]; + fullname: string; + host: string; + interfaceIndex: number; + port: number; + query: string[]; + txt: string[]; + type: { + name: string; + protocol: string; + subtypes: string[]; + }[]; +}[]>; + +export { mDNSDiscover }; diff --git a/build/mDNS.mjs b/build/mDNS.mjs new file mode 100644 index 0000000..d6ba739 --- /dev/null +++ b/build/mDNS.mjs @@ -0,0 +1,6 @@ +async function mDNSDiscover(options) { + const { tcp_service, timeout = 5e3 } = options; + return __PLUGINSYS__.IZAPI.mDNS.createBrowser(tcp_service, timeout); +} + +export { mDNSDiscover }; diff --git a/package.json b/package.json index f829300..1466136 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ciderapp/pluginkit", - "version": "0.0.4", + "version": "0.0.5", "description": "", "repository": "ciderapp/pluginkit", "license": "MIT", diff --git a/playground/index.ts b/playground/index.ts index 1591703..d028ed7 100644 --- a/playground/index.ts +++ b/playground/index.ts @@ -1,4 +1,10 @@ import { definePluginContext } from "../build/index.mjs"; +import {mDNSDiscover} from '../build/mDNS' + +const services = await mDNSDiscover({ + tcp_service: "cider._tcp.local", + timeout: 5000 +}) export default definePluginContext({ author: "Cider", diff --git a/src/api/ciderapi-types/CiderPluginSystem.d.ts b/src/api/ciderapi-types/CiderPluginSystem.d.ts index 1b2b5ae..a54bc93 100644 --- a/src/api/ciderapi-types/CiderPluginSystem.d.ts +++ b/src/api/ciderapi-types/CiderPluginSystem.d.ts @@ -1,6 +1,7 @@ interface RenderComponentOptions { component: import('../ComponentNames').ComponentNames; props?: Record; + // @ts-ignore element: Element; } @@ -45,6 +46,25 @@ declare namespace __PLUGINSYS__ { Dialog: any; } + const IZAPI: { + mDNS: { + createBrowser(tcp_service: string, timeout: number): { + addresses: string[] + fullname: string + host: string + interfaceIndex: number + port: number + query: string[] + txt: string[] + type: { + name: string + protocol: string + subtypes: string[] + }[] + }[] + } + } + const PAPIInstance: { addEventListener(event: import('./PAPIEvents').PAPIEvents, cb: (e: any) => void, opts?: Partial<{ once: boolean, passive: boolean, capture: boolean }>): void removeEventListener(event: import('./PAPIEvents').PAPIEvents, cb: (e: any) => void): void @@ -54,8 +74,9 @@ declare namespace __PLUGINSYS__ { Components: import('../ComponentNames').ComponentNames[] RenderComponent: (opts: RenderComponentOptions) => void vue: { + // @ts-ignore render: (component: any, element: Element) => void h: (component: any, props: Record, children: any) => void } } -} \ No newline at end of file +} diff --git a/src/api/mDNS.ts b/src/api/mDNS.ts new file mode 100644 index 0000000..ef4d719 --- /dev/null +++ b/src/api/mDNS.ts @@ -0,0 +1,23 @@ + +type mDNSDiscoverProps = { + /** + * The TCP service to discover by name + */ + tcp_service: string; + /** + * How long to wait for responses in milliseconds + * @default 5000 + */ + timeout?: number; +}; + +/** + * Creates an new mDNS browser to discover services and devices on the network + * + * @param options - The options to use when discovering services + * @returns An array of objects representing the discovered services + */ +export async function mDNSDiscover(options: mDNSDiscoverProps) { + const { tcp_service, timeout = 5000 } = options; + return __PLUGINSYS__.IZAPI.mDNS.createBrowser(tcp_service, timeout); +} diff --git a/src/mDNS.ts b/src/mDNS.ts new file mode 100644 index 0000000..f5810dc --- /dev/null +++ b/src/mDNS.ts @@ -0,0 +1 @@ +export { mDNSDiscover } from "./api/mDNS";