@lemonriver/core 0.7.0 → 0.8.0
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.
- package/dist/{build-CKwrex8y.js → build-Bdagm0FU.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-B1_gk0sy.js → config-Begts3gq.js} +5921 -3971
- package/dist/{dev-DZ2Yzl2p.js → dev-DjjzmT28.js} +2 -2
- package/dist/{preview-hMDcuHfP.js → preview-C9y9MTY1.js} +1 -1
- package/dist/{update-CMRxtTc9.js → update-b1dSg_FW.js} +17 -17
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/lemonriver/backup/client.ts +177 -0
- package/src/app/lemonriver/backup/guide.test.ts +45 -0
- package/src/app/lemonriver/backup/guide.ts +138 -0
- package/src/app/lemonriver/backup/model.test.ts +96 -0
- package/src/app/lemonriver/backup/model.ts +255 -0
- package/src/app/lemonriver/backup/places.test.ts +154 -0
- package/src/app/lemonriver/backup/places.ts +74 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +10 -2
- package/src/app/lemonriver/board/self-check-runner.tsx +60 -15
- package/src/app/lemonriver/features.test.ts +5 -0
- package/src/app/lemonriver/features.ts +11 -1
- package/src/app/lemonriver/help/help-page.tsx +262 -0
- package/src/app/lemonriver/help/model.test.ts +107 -0
- package/src/app/lemonriver/help/model.ts +96 -0
- package/src/app/lemonriver/routes.test.tsx +4 -2
- package/src/app/lemonriver/routes.tsx +2 -0
- package/src/app/lemonriver/settings/backup-restore-dialog.tsx +525 -0
- package/src/app/lemonriver/settings/backup-section.tsx +489 -0
- package/src/app/lemonriver/settings/settings-page.tsx +22 -0
- package/src/app/lemonriver/share/client.ts +6 -0
- package/src/app/lemonriver/share/import-dialog.tsx +14 -0
- package/src/app/lemonriver/share/paths.test.ts +41 -0
- package/src/app/lemonriver/share/paths.ts +45 -11
- package/src/app/lemonriver/share/share-dialog.tsx +54 -1
- package/src/app/lemonriver/text/en.ts +521 -0
- package/src/app/lemonriver/text/es.ts +79 -0
- package/src/app/lemonriver/text/ja.ts +76 -0
- package/src/app/lemonriver/text/types.ts +90 -0
- package/src/app/lemonriver/text/zh-cn.ts +497 -0
- package/src/app/lemonriver/text/zh-tw.ts +497 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/** What both ends of a backup package agree on: settings, limits, prefs. */
|
|
2
|
+
|
|
3
|
+
import type { ShareDeckEntry } from '../share/model.ts';
|
|
4
|
+
|
|
5
|
+
export const BACKUP_FOLDER_NAME = 'LemonRiver 备份';
|
|
6
|
+
export const BACKUP_SETTINGS_FILE = 'backup.json';
|
|
7
|
+
export const BACKUP_PARTIAL_SUFFIX = '.partial';
|
|
8
|
+
|
|
9
|
+
export const KEEP_CHOICES = [3, 7, 14, 30] as const;
|
|
10
|
+
export const DEFAULT_KEEP = 7;
|
|
11
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
12
|
+
const MIN_RETRY_MS = 60 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
/** What a backup cannot carry stays under the 4GB a zip holds without ZIP64. */
|
|
15
|
+
export const BACKUP_TOO_LARGE = 'workspace-too-large';
|
|
16
|
+
|
|
17
|
+
export const BACKUP_LIMITS = {
|
|
18
|
+
totalBytes: Math.floor(3.9 * 1024 * 1024 * 1024),
|
|
19
|
+
fileBytes: Math.floor(3.9 * 1024 * 1024 * 1024),
|
|
20
|
+
files: 200_000,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Formats that are already compressed; storing them beats deflating them again. */
|
|
24
|
+
const ALREADY_COMPRESSED = new Set([
|
|
25
|
+
'png',
|
|
26
|
+
'jpg',
|
|
27
|
+
'jpeg',
|
|
28
|
+
'gif',
|
|
29
|
+
'webp',
|
|
30
|
+
'avif',
|
|
31
|
+
'mp4',
|
|
32
|
+
'webm',
|
|
33
|
+
'mov',
|
|
34
|
+
'mp3',
|
|
35
|
+
'm4a',
|
|
36
|
+
'ogg',
|
|
37
|
+
'woff',
|
|
38
|
+
'woff2',
|
|
39
|
+
'pdf',
|
|
40
|
+
'zip',
|
|
41
|
+
'pptx',
|
|
42
|
+
'docx',
|
|
43
|
+
'xlsx',
|
|
44
|
+
'key',
|
|
45
|
+
'numbers',
|
|
46
|
+
'pages',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export function isCompressedFile(name: string): boolean {
|
|
50
|
+
const dot = name.lastIndexOf('.');
|
|
51
|
+
if (dot <= 0) return false;
|
|
52
|
+
return ALREADY_COMPRESSED.has(name.slice(dot + 1).toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type BackupLast = {
|
|
56
|
+
at: number;
|
|
57
|
+
path: string;
|
|
58
|
+
size: number;
|
|
59
|
+
ok: boolean;
|
|
60
|
+
error: string | null;
|
|
61
|
+
warnings: string[];
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type BackupSettings = {
|
|
65
|
+
folder: string | null;
|
|
66
|
+
auto: boolean;
|
|
67
|
+
keep: number;
|
|
68
|
+
last: BackupLast | null;
|
|
69
|
+
written: string[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type BackupPlaceKind =
|
|
73
|
+
| 'icloud'
|
|
74
|
+
| 'dropbox'
|
|
75
|
+
| 'onedrive'
|
|
76
|
+
| 'google'
|
|
77
|
+
| 'baidu'
|
|
78
|
+
| 'nutstore'
|
|
79
|
+
| 'local'
|
|
80
|
+
| 'other';
|
|
81
|
+
|
|
82
|
+
export type BackupPlace = {
|
|
83
|
+
id: string;
|
|
84
|
+
label: string;
|
|
85
|
+
path: string;
|
|
86
|
+
kind: BackupPlaceKind;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type BackupJob = {
|
|
90
|
+
id: string;
|
|
91
|
+
state: 'running' | 'done' | 'failed';
|
|
92
|
+
done: number;
|
|
93
|
+
total: number;
|
|
94
|
+
path?: string;
|
|
95
|
+
size?: number;
|
|
96
|
+
error?: string;
|
|
97
|
+
warnings?: string[];
|
|
98
|
+
restored?: string[];
|
|
99
|
+
assetsKept?: number;
|
|
100
|
+
themesKept?: number;
|
|
101
|
+
prefs?: PrefsSnapshot;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type BackupDeckPreview = {
|
|
105
|
+
slideId: string;
|
|
106
|
+
title: string;
|
|
107
|
+
pages: number | null;
|
|
108
|
+
local: boolean;
|
|
109
|
+
localTitle: string | null;
|
|
110
|
+
folderId: string | null;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type BackupPreview = {
|
|
114
|
+
createdAt: number;
|
|
115
|
+
app: { name: string; version: string };
|
|
116
|
+
decks: BackupDeckPreview[];
|
|
117
|
+
assets: { count: number; size: number };
|
|
118
|
+
themes: number;
|
|
119
|
+
folders: number;
|
|
120
|
+
prefs: boolean;
|
|
121
|
+
size: number;
|
|
122
|
+
executables: string[];
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type BackupListItem = {
|
|
126
|
+
name: string;
|
|
127
|
+
path: string;
|
|
128
|
+
size: number;
|
|
129
|
+
at: number;
|
|
130
|
+
written: boolean;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const EMPTY_SETTINGS: BackupSettings = {
|
|
134
|
+
folder: null,
|
|
135
|
+
auto: false,
|
|
136
|
+
keep: DEFAULT_KEEP,
|
|
137
|
+
last: null,
|
|
138
|
+
written: [],
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
142
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isAbsolutePath(value: string): boolean {
|
|
146
|
+
return value.startsWith('/') || /^[a-z]:[\\/]/i.test(value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function readWarnings(raw: unknown): string[] {
|
|
150
|
+
if (!Array.isArray(raw)) return [];
|
|
151
|
+
return raw.filter((item): item is string => typeof item === 'string' && item !== '');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function readLast(raw: unknown): BackupLast | null {
|
|
155
|
+
if (!isRecord(raw)) return null;
|
|
156
|
+
if (typeof raw.at !== 'number' || !Number.isFinite(raw.at)) return null;
|
|
157
|
+
return {
|
|
158
|
+
at: raw.at,
|
|
159
|
+
path: typeof raw.path === 'string' ? raw.path : '',
|
|
160
|
+
size: typeof raw.size === 'number' && raw.size >= 0 ? raw.size : 0,
|
|
161
|
+
ok: raw.ok === true,
|
|
162
|
+
error: typeof raw.error === 'string' && raw.error !== '' ? raw.error : null,
|
|
163
|
+
warnings: readWarnings(raw.warnings),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function sanitizeSettings(raw: unknown): BackupSettings {
|
|
168
|
+
if (!isRecord(raw)) return { ...EMPTY_SETTINGS };
|
|
169
|
+
const folder =
|
|
170
|
+
typeof raw.folder === 'string' && isAbsolutePath(raw.folder)
|
|
171
|
+
? raw.folder.replace(/\/+$/, '')
|
|
172
|
+
: null;
|
|
173
|
+
const keep =
|
|
174
|
+
typeof raw.keep === 'number' && (KEEP_CHOICES as readonly number[]).includes(raw.keep)
|
|
175
|
+
? raw.keep
|
|
176
|
+
: DEFAULT_KEEP;
|
|
177
|
+
const written = Array.isArray(raw.written)
|
|
178
|
+
? raw.written.filter(
|
|
179
|
+
(name): name is string => typeof name === 'string' && name !== '' && !name.includes('/'),
|
|
180
|
+
)
|
|
181
|
+
: [];
|
|
182
|
+
return {
|
|
183
|
+
folder,
|
|
184
|
+
auto: raw.auto === true,
|
|
185
|
+
keep,
|
|
186
|
+
last: readLast(raw.last),
|
|
187
|
+
written: [...new Set(written)],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Once a day while the app is open. A failed attempt waits an hour before the
|
|
193
|
+
* timer tries again, so an unwritable folder does not turn into a loop.
|
|
194
|
+
*/
|
|
195
|
+
export function backupDue(settings: BackupSettings, now: number): boolean {
|
|
196
|
+
if (!settings.auto || !settings.folder) return false;
|
|
197
|
+
const last = settings.last;
|
|
198
|
+
if (last) {
|
|
199
|
+
if (!last.ok && now - last.at < MIN_RETRY_MS) return false;
|
|
200
|
+
if (last.ok && now - last.at < DAY_MS) return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function pad(value: number): string {
|
|
206
|
+
return String(value).padStart(2, '0');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** `LemonRiver 备份 2026-11-01 2130`, in local time. */
|
|
210
|
+
export function backupFileStem(at: number): string {
|
|
211
|
+
const date = new Date(at);
|
|
212
|
+
const day = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
213
|
+
return `${BACKUP_FOLDER_NAME} ${day} ${pad(date.getHours())}${pad(date.getMinutes())}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Names the user put there themselves, as opposed to ones we wrote. */
|
|
217
|
+
export function looksLikeBackupName(name: string): boolean {
|
|
218
|
+
return name.startsWith(`${BACKUP_FOLDER_NAME} `) && name.toLowerCase().endsWith('.zip');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Everything under a backup package a browser may need back: nothing here
|
|
223
|
+
* decides whether a deck may run, and nothing secret rides along.
|
|
224
|
+
*/
|
|
225
|
+
export const PREFS_KEYS = [
|
|
226
|
+
'theme',
|
|
227
|
+
'open-slide:locale',
|
|
228
|
+
'lemonriver:agent-prefs',
|
|
229
|
+
'lemonriver:reduce-motion',
|
|
230
|
+
'lemonriver:onboarded',
|
|
231
|
+
'open-slide:home-sort',
|
|
232
|
+
'open-slide:agent-provider',
|
|
233
|
+
'open-slide:agent-model',
|
|
234
|
+
'open-slide:board-card-size',
|
|
235
|
+
'open-slide:board-blocks-visible',
|
|
236
|
+
'open-slide:board-links-visible',
|
|
237
|
+
'open-slide:asset-view-mode',
|
|
238
|
+
'open-slide:agent-panel-width',
|
|
239
|
+
'open-slide:agent-dock',
|
|
240
|
+
] as const;
|
|
241
|
+
|
|
242
|
+
export type PrefsSnapshot = Record<string, string>;
|
|
243
|
+
|
|
244
|
+
/** Keeps the whitelist's keys only: auto-approve and sessions never travel. */
|
|
245
|
+
export function sanitizePrefs(raw: unknown): PrefsSnapshot {
|
|
246
|
+
if (!isRecord(raw)) return {};
|
|
247
|
+
const out: PrefsSnapshot = {};
|
|
248
|
+
for (const key of PREFS_KEYS) {
|
|
249
|
+
const value = raw[key];
|
|
250
|
+
if (typeof value === 'string') out[key] = value;
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export type BackupManifestDeck = ShareDeckEntry;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { helpSectionText } from '../help/model';
|
|
3
|
+
import { lrTextFor } from '../text/all';
|
|
4
|
+
import type { BackupPlace, BackupPlaceKind } from './model.ts';
|
|
5
|
+
import { findBackupPlaces, placeLabel } from './places.ts';
|
|
6
|
+
|
|
7
|
+
function io(files: Record<string, string[]>) {
|
|
8
|
+
return {
|
|
9
|
+
exists: (path: string) => files[path] !== undefined,
|
|
10
|
+
list: (path: string) => files[path] ?? [],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const HOME = '/Users/me';
|
|
15
|
+
|
|
16
|
+
describe('backup places', () => {
|
|
17
|
+
it('lists the cloud folders this Mac syncs, and the local default last', () => {
|
|
18
|
+
const places = findBackupPlaces(
|
|
19
|
+
HOME,
|
|
20
|
+
io({
|
|
21
|
+
[`${HOME}/Library/Mobile Documents/com~apple~CloudDocs`]: [],
|
|
22
|
+
[`${HOME}/Library/CloudStorage`]: ['Dropbox-个人', 'OneDrive - Work'],
|
|
23
|
+
[`${HOME}/Library/CloudStorage/Dropbox-个人`]: [],
|
|
24
|
+
[`${HOME}/Library/CloudStorage/OneDrive - Work`]: [],
|
|
25
|
+
[`${HOME}/BaiduSyncdisk`]: [],
|
|
26
|
+
[`${HOME}/Nutstore Files`]: ['我的坚果云'],
|
|
27
|
+
[`${HOME}/Nutstore Files/我的坚果云`]: [],
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
expect(places.map((place) => [place.kind, place.path])).toEqual([
|
|
31
|
+
['icloud', `${HOME}/Library/Mobile Documents/com~apple~CloudDocs`],
|
|
32
|
+
['dropbox', `${HOME}/Library/CloudStorage/Dropbox-个人`],
|
|
33
|
+
['onedrive', `${HOME}/Library/CloudStorage/OneDrive - Work`],
|
|
34
|
+
['baidu', `${HOME}/BaiduSyncdisk`],
|
|
35
|
+
['nutstore', `${HOME}/Nutstore Files/我的坚果云`],
|
|
36
|
+
['local', `${HOME}/LemonRiver 备份`],
|
|
37
|
+
]);
|
|
38
|
+
expect(places[0]?.label).toBe('iCloud Drive');
|
|
39
|
+
expect(places[5]?.label).toBe('LemonRiver 备份');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('finds the older Dropbox and OneDrive folders too', () => {
|
|
43
|
+
const places = findBackupPlaces(
|
|
44
|
+
HOME,
|
|
45
|
+
io({
|
|
46
|
+
[HOME]: ['OneDrive - Contoso'],
|
|
47
|
+
[`${HOME}/Dropbox`]: [],
|
|
48
|
+
[`${HOME}/OneDrive`]: [],
|
|
49
|
+
[`${HOME}/OneDrive - Contoso`]: [],
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
const paths = places.map((place) => place.path);
|
|
53
|
+
expect(paths).toContain(`${HOME}/Dropbox`);
|
|
54
|
+
expect(paths).toContain(`${HOME}/OneDrive`);
|
|
55
|
+
expect(paths).toContain(`${HOME}/OneDrive - Contoso`);
|
|
56
|
+
expect(paths.at(-1)).toBe(`${HOME}/LemonRiver 备份`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('offers the local default even before it exists', () => {
|
|
60
|
+
const places = findBackupPlaces(HOME, io({}));
|
|
61
|
+
expect(places).toEqual([
|
|
62
|
+
{
|
|
63
|
+
id: `${HOME}/LemonRiver 备份`,
|
|
64
|
+
label: 'LemonRiver 备份',
|
|
65
|
+
path: `${HOME}/LemonRiver 备份`,
|
|
66
|
+
kind: 'local',
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function place(kind: BackupPlaceKind, label: string): BackupPlace {
|
|
73
|
+
const path = `/places/${kind}`;
|
|
74
|
+
return { id: path, label, path, kind };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
describe('backup place names', () => {
|
|
78
|
+
const named = [
|
|
79
|
+
['icloud', 'iCloud Drive', 'iCloud 云盘', 'iCloud 雲碟'],
|
|
80
|
+
['baidu', 'Baidu Netdisk Sync Space', '百度网盘同步空间', '百度網盤同步空間'],
|
|
81
|
+
['local', 'LemonRiver 备份', 'LemonRiver 备份', 'LemonRiver 备份'],
|
|
82
|
+
] as const;
|
|
83
|
+
|
|
84
|
+
for (const [kind, en, zhCN, zhTW] of named) {
|
|
85
|
+
it(`names ${kind} in each language`, () => {
|
|
86
|
+
expect(placeLabel(place(kind, 'the folder'), lrTextFor('en'))).toBe(en);
|
|
87
|
+
expect(placeLabel(place(kind, 'the folder'), lrTextFor('zh-CN'))).toBe(zhCN);
|
|
88
|
+
expect(placeLabel(place(kind, 'the folder'), lrTextFor('zh-TW'))).toBe(zhTW);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
it('names nutstore by its sync folder in each language', () => {
|
|
93
|
+
expect(placeLabel(place('nutstore', 'My Nutstore'), lrTextFor('en'))).toBe(
|
|
94
|
+
'Nutstore · My Nutstore',
|
|
95
|
+
);
|
|
96
|
+
expect(placeLabel(place('nutstore', '我的坚果云'), lrTextFor('zh-CN'))).toBe(
|
|
97
|
+
'坚果云 · 我的坚果云',
|
|
98
|
+
);
|
|
99
|
+
expect(placeLabel(place('nutstore', '我的堅果雲'), lrTextFor('zh-TW'))).toBe(
|
|
100
|
+
'堅果雲 · 我的堅果雲',
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('keeps the name another drive gave its folder', () => {
|
|
105
|
+
for (const kind of ['dropbox', 'onedrive', 'google', 'other'] as const) {
|
|
106
|
+
expect(placeLabel(place(kind, 'Drive Name'), lrTextFor('zh-CN'))).toBe('Drive Name');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('backup place names match the help page', () => {
|
|
112
|
+
type HelpLocale = 'en' | 'zh-CN' | 'zh-TW';
|
|
113
|
+
|
|
114
|
+
function chosenInHelp(locale: HelpLocale, sectionId: string): string {
|
|
115
|
+
const section = lrTextFor(locale).help.sections.find((item) => item.id === sectionId);
|
|
116
|
+
if (!section) throw new Error(`the help page has no ${sectionId}`);
|
|
117
|
+
const body = helpSectionText(section);
|
|
118
|
+
const match = locale === 'en' ? /choose “([^”]+)”/.exec(body) : /[选選]「([^」]+)」/.exec(body);
|
|
119
|
+
if (!match?.[1]) throw new Error(`“${sectionId}” does not say which one to choose`);
|
|
120
|
+
return match[1];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
it('uses the same names as the picker', () => {
|
|
124
|
+
expect(chosenInHelp('zh-CN', 'cloud-icloud')).toBe(
|
|
125
|
+
placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('zh-CN')),
|
|
126
|
+
);
|
|
127
|
+
expect(chosenInHelp('zh-CN', 'cloud-baidu')).toBe(
|
|
128
|
+
placeLabel(place('baidu', '百度网盘同步空间'), lrTextFor('zh-CN')),
|
|
129
|
+
);
|
|
130
|
+
expect(chosenInHelp('zh-CN', 'cloud-nutstore')).toBe(
|
|
131
|
+
placeLabel(place('nutstore', '我的坚果云'), lrTextFor('zh-CN')),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(chosenInHelp('zh-TW', 'cloud-icloud')).toBe(
|
|
135
|
+
placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('zh-TW')),
|
|
136
|
+
);
|
|
137
|
+
expect(chosenInHelp('zh-TW', 'cloud-baidu')).toBe(
|
|
138
|
+
placeLabel(place('baidu', '百度網盤同步空間'), lrTextFor('zh-TW')),
|
|
139
|
+
);
|
|
140
|
+
expect(chosenInHelp('zh-TW', 'cloud-nutstore')).toBe(
|
|
141
|
+
placeLabel(place('nutstore', '我的堅果雲'), lrTextFor('zh-TW')),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(chosenInHelp('en', 'cloud-icloud')).toBe(
|
|
145
|
+
placeLabel(place('icloud', 'iCloud Drive'), lrTextFor('en')),
|
|
146
|
+
);
|
|
147
|
+
expect(chosenInHelp('en', 'cloud-baidu')).toBe(
|
|
148
|
+
placeLabel(place('baidu', 'Baidu Netdisk Sync Space'), lrTextFor('en')),
|
|
149
|
+
);
|
|
150
|
+
expect(chosenInHelp('en', 'cloud-nutstore')).toBe(
|
|
151
|
+
placeLabel(place('nutstore', 'My Nutstore'), lrTextFor('en')),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Finds the cloud-drive folders this Mac already syncs, plus the local default. */
|
|
2
|
+
|
|
3
|
+
import { format } from '../../../locale/format';
|
|
4
|
+
import type { LrText } from '../text/types';
|
|
5
|
+
import { BACKUP_FOLDER_NAME, type BackupPlace, type BackupPlaceKind } from './model.ts';
|
|
6
|
+
|
|
7
|
+
export type PlaceIo = {
|
|
8
|
+
exists(path: string): boolean;
|
|
9
|
+
list(path: string): string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function kindFor(name: string): BackupPlaceKind {
|
|
13
|
+
const lower = name.toLowerCase();
|
|
14
|
+
if (lower.includes('dropbox')) return 'dropbox';
|
|
15
|
+
if (lower.includes('onedrive')) return 'onedrive';
|
|
16
|
+
if (lower.includes('google')) return 'google';
|
|
17
|
+
if (lower.includes('baidu') || name.includes('百度')) return 'baidu';
|
|
18
|
+
if (lower.includes('nutstore') || name.includes('坚果')) return 'nutstore';
|
|
19
|
+
return 'other';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function findBackupPlaces(home: string, io: PlaceIo): BackupPlace[] {
|
|
23
|
+
const out: BackupPlace[] = [];
|
|
24
|
+
const seen = new Set<string>();
|
|
25
|
+
const add = (path: string, label: string, kind: BackupPlaceKind) => {
|
|
26
|
+
if (seen.has(path) || !io.exists(path)) return;
|
|
27
|
+
seen.add(path);
|
|
28
|
+
out.push({ id: path, label, path, kind });
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
add(`${home}/Library/Mobile Documents/com~apple~CloudDocs`, 'iCloud Drive', 'icloud');
|
|
32
|
+
|
|
33
|
+
const cloudStorage = `${home}/Library/CloudStorage`;
|
|
34
|
+
for (const name of io.list(cloudStorage)) add(`${cloudStorage}/${name}`, name, kindFor(name));
|
|
35
|
+
|
|
36
|
+
add(`${home}/Dropbox`, 'Dropbox', 'dropbox');
|
|
37
|
+
add(`${home}/OneDrive`, 'OneDrive', 'onedrive');
|
|
38
|
+
for (const name of io.list(home)) {
|
|
39
|
+
if (name.startsWith('OneDrive - ')) add(`${home}/${name}`, name, 'onedrive');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
add(`${home}/BaiduSyncdisk`, '百度网盘同步空间', 'baidu');
|
|
43
|
+
|
|
44
|
+
const nutstore = `${home}/Nutstore Files`;
|
|
45
|
+
for (const name of io.list(nutstore)) add(`${nutstore}/${name}`, name, 'nutstore');
|
|
46
|
+
|
|
47
|
+
// The default place is offered whether or not it exists yet: the first backup
|
|
48
|
+
// creates it.
|
|
49
|
+
const local = `${home}/${BACKUP_FOLDER_NAME}`;
|
|
50
|
+
if (!seen.has(local))
|
|
51
|
+
out.push({ id: local, label: BACKUP_FOLDER_NAME, path: local, kind: 'local' });
|
|
52
|
+
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The name the help page tells the user to look for. Drives that have no name
|
|
58
|
+
* of our own keep the one the drive put on its folder.
|
|
59
|
+
*/
|
|
60
|
+
export function placeLabel(place: BackupPlace, text: LrText): string {
|
|
61
|
+
const places = text.backup.places;
|
|
62
|
+
switch (place.kind) {
|
|
63
|
+
case 'icloud':
|
|
64
|
+
return places.icloud;
|
|
65
|
+
case 'baidu':
|
|
66
|
+
return places.baidu;
|
|
67
|
+
case 'nutstore':
|
|
68
|
+
return format(places.nutstore, { folder: place.label });
|
|
69
|
+
case 'local':
|
|
70
|
+
return places.local;
|
|
71
|
+
default:
|
|
72
|
+
return place.label;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -41,15 +41,23 @@ function allText(el: Element): string {
|
|
|
41
41
|
/**
|
|
42
42
|
* Copies the page's DOM into plain objects in canvas units. Runs in the browser
|
|
43
43
|
* only: every figure comes from layout, so nothing here can be tested off-DOM.
|
|
44
|
+
* `onTooLarge` tells the caller the page was cut off rather than simply empty.
|
|
44
45
|
*/
|
|
45
|
-
export function snapshotPage(
|
|
46
|
+
export function snapshotPage(
|
|
47
|
+
canvas: HTMLElement,
|
|
48
|
+
scale: number,
|
|
49
|
+
onTooLarge?: () => void,
|
|
50
|
+
): SnapNode | null {
|
|
46
51
|
if (!(scale > 0)) return null;
|
|
47
52
|
const origin = canvas.getBoundingClientRect();
|
|
48
53
|
let count = 0;
|
|
49
54
|
|
|
50
55
|
const visit = (el: Element, clip: SnapBox | null): SnapNode | { tooLarge: true } | null => {
|
|
51
56
|
count += 1;
|
|
52
|
-
if (count > MAX_ELEMENTS)
|
|
57
|
+
if (count > MAX_ELEMENTS) {
|
|
58
|
+
onTooLarge?.();
|
|
59
|
+
return { tooLarge: true };
|
|
60
|
+
}
|
|
53
61
|
|
|
54
62
|
const style = window.getComputedStyle(el);
|
|
55
63
|
if (style.display === 'none' || style.visibility === 'hidden') return null;
|
|
@@ -24,6 +24,25 @@ export type SelfCheckInput = {
|
|
|
24
24
|
|
|
25
25
|
const wait = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms));
|
|
26
26
|
|
|
27
|
+
/** Time between two reads of the same page; a slow machine can commit for longer than a frame. */
|
|
28
|
+
const READ_INTERVAL_MS = 100;
|
|
29
|
+
/**
|
|
30
|
+
* A page can look finished and still commit more (a chart, a long list) a few
|
|
31
|
+
* hundred milliseconds later, so a matching pair alone is not enough.
|
|
32
|
+
*/
|
|
33
|
+
const MIN_OBSERVE_MS = 350;
|
|
34
|
+
|
|
35
|
+
function treeShape(tree: SnapNode): { count: number; text: string } {
|
|
36
|
+
let count = 1;
|
|
37
|
+
let text = tree.fullText;
|
|
38
|
+
for (const child of tree.children) {
|
|
39
|
+
const shape = treeShape(child);
|
|
40
|
+
count += shape.count;
|
|
41
|
+
text += `\u0000${shape.text}`;
|
|
42
|
+
}
|
|
43
|
+
return { count, text };
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
const frames = (count: number) =>
|
|
28
47
|
new Promise<void>((resolve) => {
|
|
29
48
|
const step = (left: number) => {
|
|
@@ -79,41 +98,67 @@ export function SelfCheckRunner({
|
|
|
79
98
|
}
|
|
80
99
|
let cancelled = false;
|
|
81
100
|
|
|
82
|
-
const readTree = (index: number): SnapNode | null => {
|
|
101
|
+
const readTree = (index: number, tooLarge: { value: boolean }): SnapNode | null => {
|
|
83
102
|
const box = host.current?.querySelector<HTMLElement>(`[data-lr-self-check-page="${index}"]`);
|
|
84
103
|
const canvas = box?.querySelector<HTMLElement>('[data-osd-canvas]');
|
|
85
104
|
if (!canvas) return null;
|
|
86
105
|
try {
|
|
87
|
-
return snapshotPage(canvas, SCALE)
|
|
106
|
+
return snapshotPage(canvas, SCALE, () => {
|
|
107
|
+
tooLarge.value = true;
|
|
108
|
+
});
|
|
88
109
|
} catch {
|
|
89
110
|
return null;
|
|
90
111
|
}
|
|
91
112
|
};
|
|
92
113
|
|
|
114
|
+
/**
|
|
115
|
+
* A page is read once it looks the same twice, 100 ms apart, and shows
|
|
116
|
+
* something of its own (the canvas alone is not a page). A page that never
|
|
117
|
+
* settles, or that overruns the element limit at any read, is unreadable.
|
|
118
|
+
*/
|
|
119
|
+
const readSettled = async (index: number): Promise<SnapNode | null> => {
|
|
120
|
+
const started = Date.now();
|
|
121
|
+
const deadline = started + READY_TIMEOUT_MS;
|
|
122
|
+
let previous: { count: number; text: string } | null = null;
|
|
123
|
+
for (;;) {
|
|
124
|
+
if (cancelled) return null;
|
|
125
|
+
const tooLarge = { value: false };
|
|
126
|
+
const tree = readTree(index, tooLarge);
|
|
127
|
+
if (tooLarge.value) return null;
|
|
128
|
+
const shape = tree && tree.children.length > 0 ? treeShape(tree) : null;
|
|
129
|
+
if (
|
|
130
|
+
shape &&
|
|
131
|
+
previous &&
|
|
132
|
+
shape.count === previous.count &&
|
|
133
|
+
shape.text === previous.text &&
|
|
134
|
+
Date.now() - started >= MIN_OBSERVE_MS
|
|
135
|
+
) {
|
|
136
|
+
return tree;
|
|
137
|
+
}
|
|
138
|
+
previous = shape;
|
|
139
|
+
if (Date.now() + READ_INTERVAL_MS > deadline) return null;
|
|
140
|
+
await wait(READ_INTERVAL_MS);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
93
144
|
const run = async () => {
|
|
94
145
|
await Promise.race([document.fonts.ready, wait(READY_TIMEOUT_MS)]);
|
|
95
146
|
await frames(2);
|
|
96
147
|
if (cancelled) return;
|
|
97
|
-
const
|
|
148
|
+
const indices: number[] = [];
|
|
98
149
|
for (let index = start; index < Math.min(start + PER_PASS, total); index += 1) {
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
102
|
-
while ([...trees.values()].some((tree) => tree === null) && Date.now() < deadline) {
|
|
103
|
-
await frames(1);
|
|
104
|
-
if (cancelled) return;
|
|
105
|
-
for (const [index, tree] of trees) {
|
|
106
|
-
if (!tree) trees.set(index, readTree(index));
|
|
107
|
-
}
|
|
150
|
+
indices.push(index);
|
|
108
151
|
}
|
|
109
|
-
|
|
152
|
+
const trees = await Promise.all(indices.map((index) => readSettled(index)));
|
|
153
|
+
if (cancelled) return;
|
|
154
|
+
indices.forEach((index, offset) => {
|
|
110
155
|
collected.current.push({
|
|
111
156
|
n: index + 1,
|
|
112
|
-
tree: trees
|
|
157
|
+
tree: trees[offset] ?? null,
|
|
113
158
|
notes: input.notes?.[index] ?? '',
|
|
114
159
|
title: input.titles?.[index] ?? '',
|
|
115
160
|
});
|
|
116
|
-
}
|
|
161
|
+
});
|
|
117
162
|
setPass((value) => value + 1);
|
|
118
163
|
};
|
|
119
164
|
void run();
|
|
@@ -41,4 +41,9 @@ describe('isFeatureEnabled', () => {
|
|
|
41
41
|
expect(isFeatureEnabled('share', { dev: true })).toBe(true);
|
|
42
42
|
expect(isFeatureEnabled('share', { dev: false })).toBe(false);
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
it('keeps backup to dev, where the backup endpoints run', () => {
|
|
46
|
+
expect(isFeatureEnabled('backup', { dev: true })).toBe(true);
|
|
47
|
+
expect(isFeatureEnabled('backup', { dev: false })).toBe(false);
|
|
48
|
+
});
|
|
44
49
|
});
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export type Tier = 'free' | 'pro';
|
|
2
|
-
export type FeatureId =
|
|
2
|
+
export type FeatureId =
|
|
3
|
+
| 'board'
|
|
4
|
+
| 'trash'
|
|
5
|
+
| 'settings'
|
|
6
|
+
| 'outline'
|
|
7
|
+
| 'templates'
|
|
8
|
+
| 'share'
|
|
9
|
+
| 'backup'
|
|
10
|
+
| 'help';
|
|
3
11
|
|
|
4
12
|
export type Feature = { id: FeatureId; tier: Tier; devOnly: boolean };
|
|
5
13
|
|
|
@@ -10,6 +18,8 @@ export const FEATURES: readonly Feature[] = [
|
|
|
10
18
|
{ id: 'outline', tier: 'free', devOnly: true },
|
|
11
19
|
{ id: 'templates', tier: 'free', devOnly: true },
|
|
12
20
|
{ id: 'share', tier: 'free', devOnly: true },
|
|
21
|
+
{ id: 'backup', tier: 'free', devOnly: true },
|
|
22
|
+
{ id: 'help', tier: 'free', devOnly: true },
|
|
13
23
|
];
|
|
14
24
|
|
|
15
25
|
/** The single place a paid tier will hook into later; today every tier is unlocked. */
|