Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add autosync interval
  • Loading branch information
Na2CuCl4 committed Dec 23, 2025
commit de819930c47528d11b4fa6264c2db6149650562b
22 changes: 7 additions & 15 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,32 +1021,24 @@ function _Chat() {
if (!couldSync || autoSyncTriggeredRef.current) return;

const lastSync = syncStore.lastSyncTime;
const ONE_DAY_MS = 24 * 60 * 60 * 1000;
const needAutoSync = !lastSync || Date.now() - lastSync > ONE_DAY_MS;
const needAutoSync =
syncStore.autoSyncInterval > 0 &&
(!lastSync || Date.now() - lastSync > syncStore.autoSyncInterval);

if (!needAutoSync) return;

autoSyncTriggeredRef.current = true;
let cancelled = false;

(async () => {
showToast("正在同步,请勿关闭网页");
showToast(Locale.Settings.Sync.Syncing);
try {
await syncStore.sync();
if (!cancelled) {
showToast(Locale.Settings.Sync.Success);
}
showToast(Locale.Settings.Sync.Success);
} catch (e) {
if (!cancelled) {
showToast(Locale.Settings.Sync.Fail);
console.error("[AutoSync]", e);
}
showToast(Locale.Settings.Sync.Fail);
console.error("[AutoSync]", e);
}
})();

return () => {
cancelled = true;
};
}, [couldSync, syncStore.lastSyncTime, syncStore]);

const inputRef = useRef<HTMLTextAreaElement>(null);
Expand Down
22 changes: 20 additions & 2 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function SyncConfigModal(props: { onClose?: () => void }) {
title={Locale.Settings.Sync.Config.SyncType.Title}
subTitle={Locale.Settings.Sync.Config.SyncType.SubTitle}
>
<select
<Select
value={syncStore.provider}
onChange={(e) => {
syncStore.update(
Expand All @@ -360,7 +360,7 @@ function SyncConfigModal(props: { onClose?: () => void }) {
{k}
</option>
))}
</select>
</Select>
</ListItem>

<ListItem
Expand Down Expand Up @@ -569,6 +569,24 @@ function SyncItems() {
/>
</div>
</ListItem>

<ListItem title={Locale.Settings.Sync.Interval.Title}>
<Select
aria-label={Locale.Settings.Sync.Interval.Title}
value={syncStore.getSyncInterval()}
onChange={(e) => {
syncStore.setSyncInterval(e.target.value);
}}
>
{Object.entries(Locale.Settings.Sync.Interval.Selection).map(
([k, v]) => (
<option value={v} key={k}>
{v}
</option>
),
)}
</Select>
</ListItem>
</List>

{showSyncConfigModal && (
Expand Down
12 changes: 12 additions & 0 deletions app/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const ar: PartialLocaleType = {
Sync: {
CloudState: "بيانات السحابة",
NotSyncYet: "لم يتم التزامن بعد",
Syncing: "جاري التزامن، يرجى عدم إغلاق الصفحة",
Success: "تم التزامن بنجاح",
Fail: "فشل التزامن",

Expand Down Expand Up @@ -229,6 +230,17 @@ const ar: PartialLocaleType = {
return `${overview.chat} دردشة، ${overview.message} رسالة، ${overview.prompt} إشعار، ${overview.mask} قناع`;
},
ImportFailed: "فشل الاستيراد",

Interval: {
Title: "فترة التزامن التلقائي",
Selection: {
Hourly: "كل ساعة",
Daily: "يومياً",
Weekly: "أسبوعياً",
Monthly: "شهرياً",
Never: "أبداً",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const bn: PartialLocaleType = {
Sync: {
CloudState: "ক্লাউড ডেটা",
NotSyncYet: "এখনো সিঙ্ক করা হয়নি",
Syncing: "সিঙ্ক চলছে, পৃষ্ঠা বন্ধ করবেন না",
Success: "সিঙ্ক সফল",
Fail: "সিঙ্ক ব্যর্থ",

Expand Down Expand Up @@ -232,6 +233,17 @@ const bn: PartialLocaleType = {
return `${overview.chat} বার চ্যাট, ${overview.message} বার্তা, ${overview.prompt} প্রম্পট, ${overview.mask} মাস্ক`;
},
ImportFailed: "আমদানি ব্যর্থ",

Interval: {
Title: "স্বয়ংক্রিয় সিঙ্ক ইন্টারভ্যাল",
Selection: {
Hourly: "প্রতি ঘণ্টায়",
Daily: "দৈনিক",
Weekly: "সাপ্তাহিক",
Monthly: "মাসিক",
Never: "কখনো না",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const cn = {
Sync: {
CloudState: "云端数据",
NotSyncYet: "还没有进行过同步",
Syncing: "正在同步,请勿关闭网页",
Success: "同步成功",
Fail: "同步失败",

Expand Down Expand Up @@ -249,6 +250,17 @@ const cn = {
return `${overview.chat} 次对话,${overview.message} 条消息,${overview.prompt} 条提示词,${overview.mask} 个面具`;
},
ImportFailed: "导入失败",

Interval: {
Title: "自动同步间隔",
Selection: {
Hourly: "每小时",
Daily: "每天",
Weekly: "每周",
Monthly: "每月",
Never: "从不",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const cs: PartialLocaleType = {
Sync: {
CloudState: "Data na cloudu",
NotSyncYet: "Ještě nebylo synchronizováno",
Syncing: "Synchronizace probíhá, prosím neuzavírejte stránku",
Success: "Synchronizace úspěšná",
Fail: "Synchronizace selhala",

Expand Down Expand Up @@ -231,6 +232,17 @@ const cs: PartialLocaleType = {
return `${overview.chat} konverzací, ${overview.message} zpráv, ${overview.prompt} promptů, ${overview.mask} masek`;
},
ImportFailed: "Import selhal",

Interval: {
Title: "Interval automatické synchronizace",
Selection: {
Hourly: "Každou hodinu",
Daily: "Denně",
Weekly: "Týdně",
Monthly: "Měsíčně",
Never: "Nikdy",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const da: PartialLocaleType = {
Sync: {
CloudState: "Seneste opdatering",
NotSyncYet: "Endnu ikke synkroniseret",
Syncing: "Synkroniserer, luk ikke siden",
Success: "Synkronisering lykkedes",
Fail: "Synkronisering mislykkedes",
Config: {
Expand Down Expand Up @@ -246,6 +247,17 @@ const da: PartialLocaleType = {
Overview: (overview: any) =>
`${overview.chat} chats, ${overview.message} beskeder, ${overview.prompt} prompts, ${overview.mask} personaer`,
ImportFailed: "Import mislykkedes",

Interval: {
Title: "Interval for automatisk synkronisering",
Selection: {
Hourly: "Hver time",
Daily: "Dagligt",
Weekly: "Ugentlig",
Monthly: "Månedlig",
Never: "Aldrig",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const de: PartialLocaleType = {
Sync: {
CloudState: "Cloud-Daten",
NotSyncYet: "Noch nicht synchronisiert",
Syncing: "Synchronisierung läuft, bitte schließen Sie die Seite nicht",
Success: "Synchronisation erfolgreich",
Fail: "Synchronisation fehlgeschlagen",

Expand Down Expand Up @@ -235,6 +236,17 @@ const de: PartialLocaleType = {
return `${overview.chat} Chats, ${overview.message} Nachrichten, ${overview.prompt} Eingabeaufforderungen, ${overview.mask} Masken`;
},
ImportFailed: "Import fehlgeschlagen",

Interval: {
Title: "Automatisches Synchronisierungsintervall",
Selection: {
Hourly: "Stündlich",
Daily: "Täglich",
Weekly: "Wöchentlich",
Monthly: "Monatlich",
Never: "Nie",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ const en: PartialLocaleType = {
Sync: {
CloudState: "Last Update",
NotSyncYet: "Not sync yet",
Syncing: "Syncing, please don't close the page",
Success: "Sync Success",
Fail: "Sync Fail",

Expand Down Expand Up @@ -252,6 +253,17 @@ const en: PartialLocaleType = {
return `${overview.chat} chats,${overview.message} messages,${overview.prompt} prompts,${overview.mask} masks`;
},
ImportFailed: "Failed to import from file",

Interval: {
Title: "Auto Sync Interval",
Selection: {
Hourly: "Hourly",
Daily: "Daily",
Weekly: "Weekly",
Monthly: "Monthly",
Never: "Never",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ const es: PartialLocaleType = {
Sync: {
CloudState: "Datos en la nube",
NotSyncYet: "Aún no se ha sincronizado",
Syncing: "Sincronizando, por favor no cierres la página",
Success: "Sincronización exitosa",
Fail: "Sincronización fallida",

Expand Down Expand Up @@ -238,6 +239,17 @@ const es: PartialLocaleType = {
return `${overview.chat} conversaciones, ${overview.message} mensajes, ${overview.prompt} prompts, ${overview.mask} máscaras`;
},
ImportFailed: "Importación fallida",

Interval: {
Title: "Intervalo de sincronización automática",
Selection: {
Hourly: "Cada hora",
Daily: "Diariamente",
Weekly: "Semanalmente",
Monthly: "Mensualmente",
Never: "Nunca",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const fr: PartialLocaleType = {
Sync: {
CloudState: "Données cloud",
NotSyncYet: "Pas encore synchronisé",
Syncing: "Synchronisation en cours, veuillez ne pas fermer la page",
Success: "Synchronisation réussie",
Fail: "Échec de la synchronisation",

Expand Down Expand Up @@ -238,6 +239,17 @@ const fr: PartialLocaleType = {
return `${overview.chat} discussions, ${overview.message} messages, ${overview.prompt} invites, ${overview.mask} masques`;
},
ImportFailed: "Échec de l'importation",

Interval: {
Title: "Intervalle de synchronisation automatique",
Selection: {
Hourly: "Horaire",
Daily: "Quotidien",
Weekly: "Hebdomadaire",
Monthly: "Mensuel",
Never: "Jamais",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const id: PartialLocaleType = {
Sync: {
CloudState: "Data Cloud",
NotSyncYet: "Belum disinkronkan",
Syncing: "Sedang disinkronkan, jangan tutup halaman",
Success: "Sinkronisasi Berhasil",
Fail: "Sinkronisasi Gagal",

Expand Down Expand Up @@ -232,6 +233,17 @@ const id: PartialLocaleType = {
return `${overview.chat} percakapan, ${overview.message} pesan, ${overview.prompt} prompt, ${overview.mask} masker`;
},
ImportFailed: "Impor Gagal",

Interval: {
Title: "Interval Sinkronisasi Otomatis",
Selection: {
Hourly: "Per Jam",
Daily: "Harian",
Weekly: "Mingguan",
Monthly: "Bulanan",
Never: "Tidak Pernah",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const it: PartialLocaleType = {
Sync: {
CloudState: "Dati cloud",
NotSyncYet: "Non è ancora avvenuta alcuna sincronizzazione",
Syncing: "Sincronizzazione in corso, non chiudere la pagina",
Success: "Sincronizzazione riuscita",
Fail: "Sincronizzazione fallita",

Expand Down Expand Up @@ -239,6 +240,17 @@ const it: PartialLocaleType = {
return `${overview.chat} chat, ${overview.message} messaggi, ${overview.prompt} suggerimenti, ${overview.mask} maschere`;
},
ImportFailed: "Importazione fallita",

Interval: {
Title: "Intervallo di sincronizzazione automatica",
Selection: {
Hourly: "Ogni ora",
Daily: "Giornalmente",
Weekly: "Settimanalmente",
Monthly: "Mensilmente",
Never: "Mai",
},
},
},
Mask: {
Splash: {
Expand Down
12 changes: 12 additions & 0 deletions app/locales/jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const jp: PartialLocaleType = {
Sync: {
CloudState: "クラウドデータ",
NotSyncYet: "まだ同期されていません",
Syncing: "同期中です。ページを閉じないでください",
Success: "同期に成功しました",
Fail: "同期に失敗しました",

Expand Down Expand Up @@ -231,6 +232,17 @@ const jp: PartialLocaleType = {
return `${overview.chat} 回の対話、${overview.message} 件のメッセージ、${overview.prompt} 件のプロンプト、${overview.mask} 件のマスク`;
},
ImportFailed: "インポートに失敗しました",

Interval: {
Title: "自動同期間隔",
Selection: {
Hourly: "毎時",
Daily: "毎日",
Weekly: "毎週",
Monthly: "毎月",
Never: "なし",
},
},
},
Mask: {
Splash: {
Expand Down
Loading