Copy playlist to clipboard, native UI (not alert)

This commit is contained in:
Igor Katson 2024-08-08 09:56:16 +01:00
parent e485844d86
commit 65e4f1b0a6
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
9 changed files with 135 additions and 24 deletions

View file

@ -18,7 +18,7 @@ interface InvokeErrorResponse {
}
function errorToUIError(
path: string,
path: string
): (e: InvokeErrorResponse) => Promise<never> {
return (e: InvokeErrorResponse) => {
console.log(e);
@ -35,11 +35,11 @@ function errorToUIError(
export async function invokeAPI<Response>(
name: string,
params?: InvokeArgs,
params?: InvokeArgs
): Promise<Response> {
console.log("invoking", name, params);
const result = await invoke<Response>(name, params).catch(
errorToUIError(name),
errorToUIError(name)
);
console.log(result);
return result;
@ -68,16 +68,26 @@ async function readFileAsBase64(file: File): Promise<string> {
}
export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
const getHttpBase = () => {
if (!configuration.http_api.listen_addr) {
return null;
}
let port = configuration.http_api.listen_addr.split(":")[1];
if (!port) {
return null;
}
return `http://127.0.0.1:${port}`;
};
let httpBase = getHttpBase();
return {
getStreamLogsUrl: () => {
if (!configuration.http_api.listen_addr) {
if (!httpBase) {
return null;
}
let port = configuration.http_api.listen_addr.split(":")[1];
if (!port) {
return null;
}
return `http://127.0.0.1:${port}/stream_logs`;
return `${httpBase}/stream_logs`;
},
listTorrents: async function (): Promise<ListTorrentsResponse> {
return await invokeAPI<ListTorrentsResponse>("torrents_list");
@ -96,7 +106,7 @@ export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
{
contents,
opts: opts ?? {},
},
}
);
}
return await invokeAPI<AddTorrentResponse>("torrent_create_from_url", {
@ -125,5 +135,11 @@ export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
getTorrentStreamUrl: () => {
return "";
},
getPlaylistUrl: (index: number) => {
if (!httpBase) {
return null;
}
return `${httpBase}/torrents/${index}/playlist`;
},
};
};