desktop support to modify selected files

This commit is contained in:
Igor Katson 2024-03-30 20:28:47 +00:00
parent dd53eda662
commit c6d3a972c4
2 changed files with 22 additions and 4 deletions

View file

@ -293,6 +293,17 @@ async fn torrent_action_start(
state.api()?.api_torrent_action_start(id)
}
#[tauri::command]
async fn torrent_action_configure(
state: tauri::State<'_, State>,
id: usize,
only_files: Vec<usize>,
) -> Result<EmptyJsonResponse, ApiError> {
state
.api()?
.api_torrent_action_update_only_files(id, &only_files.into_iter().collect())
}
#[tauri::command]
fn get_version() -> &'static str {
env!("CARGO_PKG_VERSION")
@ -325,6 +336,7 @@ async fn start() {
torrent_action_pause,
torrent_action_forget,
torrent_action_start,
torrent_action_configure,
torrent_create_from_base64_file,
get_version,
config_default,

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;
@ -96,7 +96,7 @@ export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
{
contents,
opts: opts ?? {},
}
},
);
}
return await invokeAPI<AddTorrentResponse>("torrent_create_from_url", {
@ -104,6 +104,12 @@ export const makeAPI = (configuration: RqbitDesktopConfig): RqbitAPI => {
opts: opts ?? {},
});
},
updateOnlyFiles: function (id, files): Promise<void> {
return invokeAPI<void>("torrent_action_configure", {
id: id,
onlyFiles: files,
});
},
pause: function (id: number): Promise<void> {
return invokeAPI<void>("torrent_action_pause", { id });
},