app_store: auto_update http fix

This commit is contained in:
bitful-pannul 2024-08-19 19:01:30 +03:00
parent 3f4be26e1d
commit 339b348337
5 changed files with 58 additions and 7 deletions

View File

@ -588,7 +588,7 @@ fn serve_paths(
}
// start auto-updating a downloaded app: PUT
// stop auto-updating a downloaded app: DELETE
"/downloads/:id/auto-update" => {
"/apps/:id/auto-update" => {
let package_id = get_package_id(url_params)?;
let chain_request = match method {

View File

@ -225,9 +225,21 @@ fn handle_local_request(
None,
),
LocalRequest::Uninstall(package_id) => (
match utils::uninstall(state, &package_id.to_process_lib()) {
Ok(()) => LocalResponse::UninstallResponse(UninstallResponse::Success),
Err(_) => LocalResponse::UninstallResponse(UninstallResponse::Failure),
match utils::uninstall(state, &package_id.clone().to_process_lib()) {
Ok(()) => {
println!(
"successfully uninstalled package: {:?}",
&package_id.to_process_lib()
);
LocalResponse::UninstallResponse(UninstallResponse::Success)
}
Err(e) => {
println!(
"error uninstalling package: {:?}: {e}",
&package_id.to_process_lib()
);
LocalResponse::UninstallResponse(UninstallResponse::Failure)
}
},
None,
),

View File

@ -113,7 +113,6 @@ pub fn new_package(
.send_and_await_response(5)??;
let download_resp = serde_json::from_slice::<DownloadResponses>(&resp.body())?;
println!("got download resp: {:?}", download_resp);
match download_resp {
DownloadResponses::Error(e) => {

View File

@ -413,4 +413,18 @@ td {
.progress-text {
min-width: 50px;
text-align: right;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.fa-spin {
animation: spin 1s linear infinite;
}

View File

@ -1,6 +1,6 @@
import React, { useEffect, useState, useCallback } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { FaDownload, FaCheck, FaTimes, FaPlay, FaSpinner, FaTrash } from "react-icons/fa";
import { FaDownload, FaCheck, FaTimes, FaPlay, FaSpinner, FaTrash, FaSync } from "react-icons/fa";
import useAppsStore from "../store";
import { AppListing, PackageState } from "../types/Apps";
import { compareVersions } from "../utils/compareVersions";
@ -8,7 +8,7 @@ import { compareVersions } from "../utils/compareVersions";
export default function AppPage() {
const { id } = useParams();
const navigate = useNavigate();
const { fetchListing, fetchInstalledApp, uninstallApp } = useAppsStore();
const { fetchListing, fetchInstalledApp, uninstallApp, setAutoUpdate } = useAppsStore();
const [app, setApp] = useState<AppListing | null>(null);
const [installedApp, setInstalledApp] = useState<PackageState | null>(null);
const [currentVersion, setCurrentVersion] = useState<string | null>(null);
@ -16,6 +16,7 @@ export default function AppPage() {
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [isUninstalling, setIsUninstalling] = useState(false);
const [isTogglingAutoUpdate, setIsTogglingAutoUpdate] = useState(false);
const loadData = useCallback(async () => {
@ -70,6 +71,21 @@ export default function AppPage() {
}
};
const handleToggleAutoUpdate = async () => {
if (!app || !latestVersion) return;
setIsTogglingAutoUpdate(true);
try {
const newAutoUpdateState = !app.auto_update;
await setAutoUpdate(`${app.package_id.package_name}:${app.package_id.publisher_node}`, latestVersion, newAutoUpdateState);
await loadData();
} catch (error) {
console.error('Failed to toggle auto-update:', error);
setError(`Failed to toggle auto-update: ${error instanceof Error ? error.message : String(error)}`);
} finally {
setIsTogglingAutoUpdate(false);
}
};
useEffect(() => {
loadData();
}, [loadData]);
@ -122,6 +138,12 @@ export default function AppPage() {
)}
<li><span>Publisher:</span> <span>{app.package_id.publisher_node}</span></li>
<li><span>License:</span> <span>{app.metadata?.properties?.license || "Not specified"}</span></li>
<li>
<span>Auto Update:</span>
<span className="status-icon">
{app.auto_update ? <FaCheck className="installed" /> : <FaTimes className="not-installed" />}
</span>
</li>
</ul>
</div>
@ -134,6 +156,10 @@ export default function AppPage() {
<button onClick={handleUninstall} className="secondary" disabled={isUninstalling}>
{isUninstalling ? <FaSpinner className="fa-spin" /> : <FaTrash />} Uninstall
</button>
<button onClick={handleToggleAutoUpdate} className="secondary" disabled={isTogglingAutoUpdate}>
{isTogglingAutoUpdate ? <FaSpinner className="fa-spin" /> : <FaSync />}
{app.auto_update ? " Disable" : " Enable"} Auto Update
</button>
</>
)}
<button onClick={handleDownload} className="primary">