diff --git a/apps/desktop/changelog/next.md b/apps/desktop/changelog/next.md index 8f5eac449..2f6b4e0f1 100644 --- a/apps/desktop/changelog/next.md +++ b/apps/desktop/changelog/next.md @@ -4,6 +4,8 @@ ## Improvements +- Redesign integration settings page for better user experience and support integration settings export and import. + ## No longer broken ## Thanks diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/integration.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/integration.tsx index 9df2222cb..de1026009 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/integration.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/integration.tsx @@ -1,3 +1,4 @@ +import { Button } from "@follow/components/ui/button/index.js" import { Collapse, CollapseGroup } from "@follow/components/ui/collapse/index.js" import { Divider } from "@follow/components/ui/divider/index.js" import { InputV2 } from "@follow/components/ui/input/index.js" @@ -13,8 +14,14 @@ import { } from "@follow/components/ui/platform-icon/icons.js" import { useEffect, useMemo, useState } from "react" import { useTranslation } from "react-i18next" +import { toast } from "sonner" -import { setIntegrationSetting, useIntegrationSettingValue } from "~/atoms/settings/integration" +import { + getIntegrationSettings, + setIntegrationSetting, + useIntegrationSettingValue, +} from "~/atoms/settings/integration" +import { downloadJsonFile, selectJsonFile } from "~/lib/export" import { createSetting } from "../helper/builder" import { useSetSettingCanSync } from "../modal/hooks" @@ -380,7 +387,7 @@ export const SettingIntegration = () => { {category.icon} {category.title as string} - + {category.integrations.filter((i) => i.configured).length}/ {category.integrations.length} @@ -431,12 +438,89 @@ export const SettingIntegration = () => { const BottomTip = () => { const { t } = useTranslation("settings") + + const handleExport = () => { + try { + const settings = getIntegrationSettings() + const jsonData = JSON.stringify(settings, null, 2) + const filename = `follow-integration-settings-${new Date().toISOString().split("T")[0]}.json` + downloadJsonFile(jsonData, filename) + toast.success(t("integration.export.success")) + } catch (error) { + console.error("Failed to export integration settings:", error) + toast.error(t("integration.export.error")) + } + } + + const handleImport = async () => { + try { + const jsonData = await selectJsonFile() + const settings = JSON.parse(jsonData) + + // Validate the imported settings structure + if (typeof settings !== "object" || settings === null) { + throw new Error("Invalid settings format") + } + + // Get current settings to use as a base for validation + const currentSettings = getIntegrationSettings() + + // Only apply settings that exist in the current schema + let importCount = 0 + Object.entries(settings).forEach(([key, value]) => { + if (key in currentSettings) { + setIntegrationSetting(key as any, value) + importCount++ + } + }) + + if (importCount === 0) { + throw new Error("No valid settings found in the imported file") + } + + toast.success(t("integration.import.success")) + } catch (error) { + if (error instanceof Error && error.message === "No file selected") { + // User cancelled file selection, don't show error + return + } + console.error("Failed to import integration settings:", error) + if (error instanceof SyntaxError) { + toast.error(t("integration.import.invalid")) + } else { + toast.error(t("integration.import.error")) + } + } + } + return ( -
+
-

- {t("integration.tip")} -

+
+

+ {t("integration.tip")} +

+
+ + +
+
) } diff --git a/locales/settings/en.json b/locales/settings/en.json index 3435ded83..a43b85dda 100644 --- a/locales/settings/en.json +++ b/locales/settings/en.json @@ -332,7 +332,14 @@ "integration.eagle.enable.description": "Display 'Save media to Eagle' button when available.", "integration.eagle.enable.label": "Enable", "integration.eagle.title": "Eagle", + "integration.export.button": "Export Settings", + "integration.export.error": "Failed to export integration settings", + "integration.export.success": "Integration settings exported successfully", "integration.general": "General", + "integration.import.button": "Import Settings", + "integration.import.error": "Failed to import integration settings", + "integration.import.invalid": "Invalid integration settings file", + "integration.import.success": "Integration settings imported successfully", "integration.instapaper.enable.description": "Display 'Save to Instapaper' button when available.", "integration.instapaper.enable.label": "Enable", "integration.instapaper.password.label": "Instapaper Password", diff --git a/locales/settings/ja.json b/locales/settings/ja.json index d7bfe1580..e4fe6df97 100644 --- a/locales/settings/ja.json +++ b/locales/settings/ja.json @@ -328,7 +328,14 @@ "integration.eagle.enable.description": "利用可能な場合、'Eagle にメディアを保存' ボタンを表示します。", "integration.eagle.enable.label": "有効化", "integration.eagle.title": "Eagle", + "integration.export.button": "設定をエクスポート", + "integration.export.error": "統合設定のエクスポートに失敗しました", + "integration.export.success": "統合設定のエクスポートが成功しました", "integration.general": "一般", + "integration.import.button": "設定をインポート", + "integration.import.error": "統合設定のインポートに失敗しました", + "integration.import.invalid": "無効な統合設定ファイルです", + "integration.import.success": "統合設定のインポートが成功しました", "integration.instapaper.enable.description": "利用可能な場合、'Instapaper に保存' ボタンを表示します。", "integration.instapaper.enable.label": "有効化", "integration.instapaper.password.label": "Instapaper パスワード", diff --git a/locales/settings/zh-CN.json b/locales/settings/zh-CN.json index 768a45d3c..450b438b7 100644 --- a/locales/settings/zh-CN.json +++ b/locales/settings/zh-CN.json @@ -323,7 +323,14 @@ "integration.eagle.enable.description": "显示「保存到 Eagle」按钮(如果可用)。", "integration.eagle.enable.label": "启用", "integration.eagle.title": "Eagle", + "integration.export.button": "导出设置", + "integration.export.error": "导出集成设置失败", + "integration.export.success": "集成设置导出成功", "integration.general": "通用", + "integration.import.button": "导入设置", + "integration.import.error": "导入集成设置失败", + "integration.import.invalid": "无效的集成设置文件", + "integration.import.success": "集成设置导入成功", "integration.instapaper.enable.description": "显示「保存到 Instapaper」按钮(如果可用)。", "integration.instapaper.enable.label": "启用", "integration.instapaper.password.label": "密码",