monoidentity 0.12.4 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { storageClient, STORAGE_EVENT } from "./storageclient.svelte.js";
3
3
  const CLOUD_CACHE_KEY = "monoidentity-x/cloud-cache";
4
4
  const isJunk = (key) => key.includes(".obsidian/") || key.includes(".cache/");
5
5
  const keepAnyway = (key) => key.includes(".cache/");
6
+ let unmount;
6
7
  const loadFromCloud = async (base, client) => {
7
8
  const listResp = await client.fetch(base);
8
9
  if (!listResp.ok)
@@ -59,14 +60,15 @@ const syncFromCloud = async (bucket, client) => {
59
60
  }
60
61
  };
61
62
  export const backupCloud = async (bucket) => {
63
+ unmount?.();
62
64
  const client = new AwsClient({
63
65
  accessKeyId: bucket.accessKeyId,
64
66
  secretAccessKey: bucket.secretAccessKey,
65
67
  });
66
68
  await syncFromCloud(bucket, client);
67
- setInterval(() => syncFromCloud(bucket, client), 15 * 60 * 1000);
69
+ const syncIntervalId = setInterval(() => syncFromCloud(bucket, client), 15 * 60 * 1000);
68
70
  // Continuous sync: mirror local changes to cloud
69
- addEventListener(STORAGE_EVENT, async (event) => {
71
+ const listener = async (event) => {
70
72
  let key = event.detail.key;
71
73
  if (!key.startsWith("monoidentity/"))
72
74
  return;
@@ -106,5 +108,15 @@ export const backupCloud = async (bucket) => {
106
108
  catch (err) {
107
109
  console.warn("[monoidentity cloud] sync failed", key, err);
108
110
  }
109
- });
111
+ };
112
+ addEventListener(STORAGE_EVENT, listener);
113
+ unmount = () => {
114
+ clearInterval(syncIntervalId);
115
+ removeEventListener(STORAGE_EVENT, listener);
116
+ };
110
117
  };
118
+ if (import.meta.hot) {
119
+ import.meta.hot.dispose(() => {
120
+ unmount?.();
121
+ });
122
+ }
@@ -1,6 +1,7 @@
1
1
  import { createStore, get, set } from "idb-keyval";
2
2
  import { STORAGE_EVENT, storageClient } from "./storageclient.svelte.js";
3
3
  import { canBackup } from "../utils-transport.js";
4
+ let unmount;
4
5
  const saveToDir = (dir) => {
5
6
  let dirCache = {};
6
7
  const getDirCached = async (route) => {
@@ -16,7 +17,7 @@ const saveToDir = (dir) => {
16
17
  }
17
18
  return parent;
18
19
  };
19
- addEventListener(STORAGE_EVENT, async (event) => {
20
+ const listener = async (event) => {
20
21
  let key = event.detail.key;
21
22
  if (!key.startsWith("monoidentity/"))
22
23
  return;
@@ -35,19 +36,24 @@ const saveToDir = (dir) => {
35
36
  else {
36
37
  await parent.removeEntry(name);
37
38
  }
38
- });
39
+ };
40
+ addEventListener(STORAGE_EVENT, listener);
41
+ return () => {
42
+ removeEventListener(STORAGE_EVENT, listener);
43
+ };
39
44
  };
40
45
  export const backupLocally = async (requestBackup) => {
41
46
  if (!canBackup)
42
47
  return;
43
48
  if (localStorage["monoidentity-x/backup"] == "off")
44
49
  return;
50
+ unmount?.();
45
51
  const handles = createStore("monoidentity-x", "handles");
46
52
  if (localStorage["monoidentity-x/backup"] == "on") {
47
53
  const dir = await get("backup", handles);
48
54
  if (!dir)
49
55
  throw new Error("No backup handle found");
50
- saveToDir(dir);
56
+ unmount = saveToDir(dir);
51
57
  }
52
58
  else {
53
59
  localStorage["monoidentity-x/backup"] = "off";
@@ -79,7 +85,12 @@ export const backupLocally = async (requestBackup) => {
79
85
  location.reload();
80
86
  return;
81
87
  }
82
- saveToDir(dir);
88
+ unmount = saveToDir(dir);
83
89
  });
84
90
  }
85
91
  };
92
+ if (import.meta.hot) {
93
+ import.meta.hot.dispose(() => {
94
+ unmount?.();
95
+ });
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.12.4",
3
+ "version": "0.12.5",
4
4
  "repository": "KTibow/monoidentity",
5
5
  "author": {
6
6
  "name": "KTibow"