web: change offline mode api

This commit is contained in:
Abdullah Atta
2024-08-02 15:14:52 +05:00
committed by Abdullah Atta
parent a4c0e8412b
commit 1b71edef45
4 changed files with 17 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ import { useStore } from "./stores/app-store";
import { useStore as useUserStore } from "./stores/user-store"; import { useStore as useUserStore } from "./stores/user-store";
import { useEditorStore } from "./stores/editor-store"; import { useEditorStore } from "./stores/editor-store";
import { useStore as useAnnouncementStore } from "./stores/announcement-store"; import { useStore as useAnnouncementStore } from "./stores/announcement-store";
import { useStore as useSettingStore } from "./stores/setting-store";
import { import {
resetNotices, resetNotices,
scheduleBackups, scheduleBackups,
@@ -44,6 +45,7 @@ import { desktop } from "./common/desktop-bridge";
import { BuyDialog } from "./dialogs/buy-dialog"; import { BuyDialog } from "./dialogs/buy-dialog";
import { FeatureDialog } from "./dialogs/feature-dialog"; import { FeatureDialog } from "./dialogs/feature-dialog";
import { AnnouncementDialog } from "./dialogs/announcement-dialog"; import { AnnouncementDialog } from "./dialogs/announcement-dialog";
import { logger } from "./utils/logger";
type AppEffectsProps = { type AppEffectsProps = {
setShow: (show: boolean) => void; setShow: (show: boolean) => void;
@@ -95,6 +97,9 @@ export default function AppEffects({ setShow }: AppEffectsProps) {
await FeatureDialog.show({ featureName: "highlights" }); await FeatureDialog.show({ featureName: "highlights" });
await scheduleBackups(); await scheduleBackups();
await scheduleFullBackups(); await scheduleFullBackups();
if (useSettingStore.getState().isFullOfflineMode)
// NOTE: we deliberately don't await here because we don't want to pause execution.
db.attachments.cacheAttachments().catch(logger.error);
})(); })();
return () => { return () => {

View File

@@ -564,6 +564,12 @@ async function exists(filename: string | FileHandle) {
); );
} }
async function bulkExists(filenames: string[]) {
return Array.from(
new Set(filenames).difference(new Set(await streamablefs.list())).values()
);
}
type FileMetadata = { type FileMetadata = {
key: SerializedKey; key: SerializedKey;
iv: string; iv: string;
@@ -666,7 +672,8 @@ export const FileStorage: IFileStorage = {
exists, exists,
clearFileStorage, clearFileStorage,
hashBase64, hashBase64,
getUploadedFileSize getUploadedFileSize,
bulkExists
}; };
function isSuccessStatusCode(statusCode: number) { function isSuccessStatusCode(statusCode: number) {

View File

@@ -284,6 +284,7 @@ class AppStore extends BaseStore<AppStore> {
this.updateSyncStatus("syncing"); this.updateSyncStatus("syncing");
try { try {
options.offlineMode = settingStore.get().isFullOfflineMode;
const result = await db.sync(options); const result = await db.sync(options);
if (!result) return this.updateSyncStatus("failed"); if (!result) return this.updateSyncStatus("failed");

View File

@@ -40,7 +40,7 @@ class SettingStore extends BaseStore<SettingStore> {
doubleSpacedParagraphs = Config.get("doubleSpacedLines", true); doubleSpacedParagraphs = Config.get("doubleSpacedLines", true);
markdownShortcuts = Config.get("markdownShortcuts", true); markdownShortcuts = Config.get("markdownShortcuts", true);
notificationsSettings = Config.get("notifications", { reminder: true }); notificationsSettings = Config.get("notifications", { reminder: true });
isFullOfflineMode = false; isFullOfflineMode = Config.get("fullOfflineMode", false);
zoomFactor = 1.0; zoomFactor = 1.0;
privacyMode = false; privacyMode = false;
@@ -73,8 +73,7 @@ class SettingStore extends BaseStore<SettingStore> {
customDns: await desktop?.integration.customDns.query(), customDns: await desktop?.integration.customDns.query(),
zoomFactor: await desktop?.integration.zoomFactor.query(), zoomFactor: await desktop?.integration.zoomFactor.query(),
autoUpdates: await desktop?.updater.autoUpdates.query(), autoUpdates: await desktop?.updater.autoUpdates.query(),
proxyRules: await desktop?.integration.proxyRules.query(), proxyRules: await desktop?.integration.proxyRules.query()
isFullOfflineMode: await db.kv().read("fullOfflineMode")
}); });
}; };
@@ -213,7 +212,7 @@ class SettingStore extends BaseStore<SettingStore> {
toggleFullOfflineMode = async () => { toggleFullOfflineMode = async () => {
const isFullOfflineMode = this.get().isFullOfflineMode; const isFullOfflineMode = this.get().isFullOfflineMode;
this.set({ isFullOfflineMode: !isFullOfflineMode }); this.set({ isFullOfflineMode: !isFullOfflineMode });
await db.kv().write("fullOfflineMode", !isFullOfflineMode); Config.set("fullOfflineMode", !isFullOfflineMode);
}; };
} }