forked from Blendman974/faceclaw
Add an iOS Spotify integration
This commit is contained in:
1 parent
e36fb14a34
commit
c9cf29e5c0
32 files changed
+3176
-50
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { readUpcomingEventsAsync, type CalendarEvent } from "../native/calendar";
|
||||
import { hasCalendarPermission } from "../native/calendar-permissions";
|
||||
import { mediaControllerBridge } from "../native/media-controller";
|
||||
import { spotifyService } from "../native/spotify";
|
||||
import { dismissNotification, readActiveNotifications } from "../native/notification-icons";
|
||||
import { shell } from "../ui/shell/shell";
|
||||
import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry";
|
||||
@@ -93,7 +94,11 @@ export function registerSystemTools(registry: ToolRegistry = toolRegistry): void
|
||||
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
||||
proactive: true,
|
||||
},
|
||||
() => ok(describeNowPlaying()),
|
||||
async () => {
|
||||
// Spotify's state is polled only while something shows it.
|
||||
await mediaControllerBridge.refresh?.();
|
||||
return ok(describeNowPlaying());
|
||||
},
|
||||
);
|
||||
|
||||
registry.registerSystemTool(
|
||||
@@ -103,6 +108,7 @@ export function registerSystemTools(registry: ToolRegistry = toolRegistry): void
|
||||
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
||||
},
|
||||
async () => {
|
||||
await mediaControllerBridge.refresh?.();
|
||||
const state = mediaControllerBridge.snapshot();
|
||||
if (!state.canPlayPause) return err("No media session can be controlled right now.");
|
||||
await mediaControllerBridge.playPause();
|
||||
@@ -117,6 +123,7 @@ export function registerSystemTools(registry: ToolRegistry = toolRegistry): void
|
||||
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
||||
},
|
||||
async () => {
|
||||
await mediaControllerBridge.refresh?.();
|
||||
const state = mediaControllerBridge.snapshot();
|
||||
if (!state.canSkipNext) return err("The current media session can't skip to the next track.");
|
||||
await mediaControllerBridge.skipNext();
|
||||
@@ -124,6 +131,45 @@ export function registerSystemTools(registry: ToolRegistry = toolRegistry): void
|
||||
},
|
||||
);
|
||||
|
||||
const spotify = spotifyService();
|
||||
if (spotify) {
|
||||
registry.register({
|
||||
spec: {
|
||||
name: "media.spotify_play",
|
||||
description:
|
||||
"Search Spotify and start playing the best match on the user's Spotify (this phone or another of their Spotify devices). Use for requests like \"play Daft Punk\" (artist), \"play the album Discovery\" (album) or \"play Harder Better Faster Stronger\" (track).",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
query: { type: "string", description: "What to search for, e.g. an artist, album, song or playlist name." },
|
||||
kind: {
|
||||
type: "string",
|
||||
enum: ["track", "album", "artist", "playlist"],
|
||||
description: "What kind of thing to play (default track).",
|
||||
},
|
||||
},
|
||||
required: ["query"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
availability: "always",
|
||||
// Search, then play (with a device lookup when none is active).
|
||||
timeoutMs: 20_000,
|
||||
},
|
||||
handler: async (args) => {
|
||||
const query = String(args?.query ?? "").trim();
|
||||
if (!query) return err("media.spotify_play requires a query");
|
||||
const kind = ["track", "album", "artist", "playlist"].includes(args?.kind) ? args.kind : "track";
|
||||
try {
|
||||
return ok(`Playing ${await spotify.playSearch(query, kind)} on Spotify.`);
|
||||
} catch (error) {
|
||||
return err(String((error as Error)?.message ?? error));
|
||||
}
|
||||
},
|
||||
// Offered once signed in from the Music app menu.
|
||||
isAvailable: () => spotify.account() !== null,
|
||||
});
|
||||
}
|
||||
|
||||
// Android notification tools are still platform-specific.
|
||||
if (global.isIOS) return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user