mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
web: change offline mode api
This commit is contained in:
committed by
Abdullah Atta
parent
a4c0e8412b
commit
1b71edef45
@@ -22,6 +22,7 @@ import { useStore } from "./stores/app-store";
|
||||
import { useStore as useUserStore } from "./stores/user-store";
|
||||
import { useEditorStore } from "./stores/editor-store";
|
||||
import { useStore as useAnnouncementStore } from "./stores/announcement-store";
|
||||
import { useStore as useSettingStore } from "./stores/setting-store";
|
||||
import {
|
||||
resetNotices,
|
||||
scheduleBackups,
|
||||
@@ -44,6 +45,7 @@ import { desktop } from "./common/desktop-bridge";
|
||||
import { BuyDialog } from "./dialogs/buy-dialog";
|
||||
import { FeatureDialog } from "./dialogs/feature-dialog";
|
||||
import { AnnouncementDialog } from "./dialogs/announcement-dialog";
|
||||
import { logger } from "./utils/logger";
|
||||
|
||||
type AppEffectsProps = {
|
||||
setShow: (show: boolean) => void;
|
||||
@@ -95,6 +97,9 @@ export default function AppEffects({ setShow }: AppEffectsProps) {
|
||||
await FeatureDialog.show({ featureName: "highlights" });
|
||||
await scheduleBackups();
|
||||
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 () => {
|
||||
|
||||
@@ -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 = {
|
||||
key: SerializedKey;
|
||||
iv: string;
|
||||
@@ -666,7 +672,8 @@ export const FileStorage: IFileStorage = {
|
||||
exists,
|
||||
clearFileStorage,
|
||||
hashBase64,
|
||||
getUploadedFileSize
|
||||
getUploadedFileSize,
|
||||
bulkExists
|
||||
};
|
||||
|
||||
function isSuccessStatusCode(statusCode: number) {
|
||||
|
||||
@@ -284,6 +284,7 @@ class AppStore extends BaseStore<AppStore> {
|
||||
|
||||
this.updateSyncStatus("syncing");
|
||||
try {
|
||||
options.offlineMode = settingStore.get().isFullOfflineMode;
|
||||
const result = await db.sync(options);
|
||||
|
||||
if (!result) return this.updateSyncStatus("failed");
|
||||
|
||||
@@ -40,7 +40,7 @@ class SettingStore extends BaseStore<SettingStore> {
|
||||
doubleSpacedParagraphs = Config.get("doubleSpacedLines", true);
|
||||
markdownShortcuts = Config.get("markdownShortcuts", true);
|
||||
notificationsSettings = Config.get("notifications", { reminder: true });
|
||||
isFullOfflineMode = false;
|
||||
isFullOfflineMode = Config.get("fullOfflineMode", false);
|
||||
|
||||
zoomFactor = 1.0;
|
||||
privacyMode = false;
|
||||
@@ -73,8 +73,7 @@ class SettingStore extends BaseStore<SettingStore> {
|
||||
customDns: await desktop?.integration.customDns.query(),
|
||||
zoomFactor: await desktop?.integration.zoomFactor.query(),
|
||||
autoUpdates: await desktop?.updater.autoUpdates.query(),
|
||||
proxyRules: await desktop?.integration.proxyRules.query(),
|
||||
isFullOfflineMode: await db.kv().read("fullOfflineMode")
|
||||
proxyRules: await desktop?.integration.proxyRules.query()
|
||||
});
|
||||
};
|
||||
|
||||
@@ -213,7 +212,7 @@ class SettingStore extends BaseStore<SettingStore> {
|
||||
toggleFullOfflineMode = async () => {
|
||||
const isFullOfflineMode = this.get().isFullOfflineMode;
|
||||
this.set({ isFullOfflineMode: !isFullOfflineMode });
|
||||
await db.kv().write("fullOfflineMode", !isFullOfflineMode);
|
||||
Config.set("fullOfflineMode", !isFullOfflineMode);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user