When Docker isn't detected on startup, surface a dialog offering a one-click install (pkexec + get.docker.com on Linux, brew cask on macOS, winget on Windows) with a graceful fallback to manual steps and a link to official documentation. Install output streams back to the UI via a tauri event. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
36 lines
939 B
TypeScript
36 lines
939 B
TypeScript
import { useCallback, useState } from "react";
|
|
import { listen } from "@tauri-apps/api/event";
|
|
import * as commands from "../lib/tauri-commands";
|
|
import type { InstallOptions } from "../lib/types";
|
|
|
|
export function useInstallHelper() {
|
|
const [options, setOptions] = useState<InstallOptions | null>(null);
|
|
|
|
const loadOptions = useCallback(async () => {
|
|
try {
|
|
const opts = await commands.detectInstallOptions();
|
|
setOptions(opts);
|
|
return opts;
|
|
} catch {
|
|
setOptions(null);
|
|
return null;
|
|
}
|
|
}, []);
|
|
|
|
const runInstall = useCallback(
|
|
async (onProgress?: (line: string) => void) => {
|
|
const unlisten = onProgress
|
|
? await listen<string>("docker-install-progress", (e) => onProgress(e.payload))
|
|
: null;
|
|
try {
|
|
await commands.runDockerInstall();
|
|
} finally {
|
|
unlisten?.();
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
|
|
return { options, loadOptions, runInstall };
|
|
}
|