Skip to content

Commit 1f9cb09

Browse files
committed
feat(matting): hide enable on unsupported platforms
Query matting_supported and show 'not available on this platform' instead of an Enable button when there is no official prebuilt runtime, so the user can't start a download that would only fail.
1 parent e80ccfe commit 1f9cb09

6 files changed

Lines changed: 22 additions & 1 deletion

File tree

app/src-tauri/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,12 @@ async fn put_image_bytes(
13081308
.map_err(|e| e.to_string())
13091309
}
13101310

1311+
/// 当前平台 / 架构是否支持 AI 抠图(有官方预编译运行时可下载)。
1312+
#[tauri::command]
1313+
fn matting_supported(state: State<'_, App>) -> bool {
1314+
state.matting_supported()
1315+
}
1316+
13111317
/// AI 抠图插件是否已安装。
13121318
#[tauri::command]
13131319
fn matting_installed(state: State<'_, App>) -> bool {
@@ -1545,6 +1551,7 @@ pub fn run() {
15451551
image_edit_full,
15461552
put_image_bytes,
15471553
save_image_bytes_local,
1554+
matting_supported,
15481555
matting_installed,
15491556
install_matting_plugin,
15501557
uninstall_matting_plugin,

app/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ export const setPref = (key: string, value: string) =>
422422
invoke<void>("set_pref", { key, value });
423423

424424
// AI 抠图插件(去背景)
425+
export const mattingSupported = () => invoke<boolean>("matting_supported");
426+
425427
export const mattingInstalled = () => invoke<boolean>("matting_installed");
426428

427429
export const installMattingPlugin = () =>

app/src/components/MattingPluginCard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useI18n } from "../i18n";
1010
*/
1111
export function MattingPluginCard() {
1212
const { t } = useI18n();
13+
const [supported, setSupported] = useState(true);
1314
const [installed, setInstalled] = useState<boolean | null>(null);
1415
const [busy, setBusy] = useState(false);
1516
const [progress, setProgress] = useState<{ done: number; total: number } | null>(
@@ -20,6 +21,7 @@ export function MattingPluginCard() {
2021
const unlisten = useRef<(() => void) | null>(null);
2122

2223
useEffect(() => {
24+
api.mattingSupported().then(setSupported).catch(() => setSupported(true));
2325
api.mattingInstalled().then(setInstalled).catch(() => setInstalled(false));
2426
return () => unlisten.current?.();
2527
}, []);
@@ -72,7 +74,10 @@ export function MattingPluginCard() {
7274
{t("下载本地模型,一键去掉图片背景。约 20 MB,首次需下载。")}
7375
</div>
7476
</div>
75-
{installed === false && !busy && (
77+
{!supported && (
78+
<span className="plugin-card__state">{t("本平台暂不支持")}</span>
79+
)}
80+
{supported && installed === false && !busy && (
7681
<button className="btn btn--primary" onClick={install}>
7782
{t("启用")}
7883
</button>

app/src/translations/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export const EN: Record<string, string> = {
254254
"Download a local model to cut out backgrounds. ~20 MB, downloaded once.",
255255
启用: "Enable",
256256
卸载: "Uninstall",
257+
本平台暂不支持: "Not available on this platform",
257258
"安装完成,重启应用后生效。": "Installed — restart the app to take effect.",
258259
立即重启: "Restart now",
259260

app/src/translations/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const JA: Record<string, string> = {
9494
"ローカルモデルをダウンロードして背景をワンクリックで除去。約 20 MB、初回のみダウンロード。",
9595
启用: "有効化",
9696
卸载: "アンインストール",
97+
本平台暂不支持: "このプラットフォームでは利用できません",
9798
"安装完成,重启应用后生效。": "インストール完了 — アプリを再起動すると有効になります。",
9899
立即重启: "今すぐ再起動",
99100
};

crates/app-core/src/matting_plugin.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ impl App {
106106
self.matting_dir().map(|d| d.join(dylib_name()))
107107
}
108108

109+
/// 当前平台 / 架构是否有官方预编译运行时可下载(决定是否显示「启用」)。
110+
pub fn matting_supported(&self) -> bool {
111+
runtime_archive().is_some()
112+
}
113+
109114
/// 插件是否已安装(模型 + 运行时库都在)。
110115
pub fn matting_installed(&self) -> bool {
111116
matches!(

0 commit comments

Comments
 (0)