Skip to content

Commit e3579ca

Browse files
author
Kevin Arthur
committed
feat(format): add .varve extension with full .strata compatibility
- New saves default to filename.varve (DOCUMENT_EXT, withDocumentExt); .strata files remain openable and map to the same persisted kind - Save As filters offer both extensions; saveDocumentToDisk suggests .varve - File → Save now writes disk-opened documents back to their original path (Figma/Photoshop behavior) via new platform writeDocumentToPath; web falls back to the picker, memory is a no-op - Native import keeps original document JSON and display name for .varve/.strata (was: blank placeholder); BulkImport accepts .varve - Native metadata: tauri.conf.json registers application/x-varve + legacy application/x-strata; shared-mime-info XML and AUR PKGBUILD register both globs; the home-dir watcher watches both extensions - Persisted identifiers: version-history localStorage keys renamed with legacy read-fallback; recovery IndexedDB migrated once from strata-recovery (never deleted, idempotent) - E2E: legacy .strata opens intact, .varve opens identically, save emits .varve download, malformed documents rejected safely
1 parent 0e18f7c commit e3579ca

20 files changed

Lines changed: 420 additions & 51 deletions

File tree

‎apps/desktop/src-tauri/linux/dev.varve.desktop.xml‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
shared-mime-info definition for Strata documents.
3+
shared-mime-info definitions for Varve documents.
44
55
tauri.conf.json's `fileAssociations` makes Tauri write
6-
`MimeType=application/x-strata` into the .desktop entry, but it does not
7-
emit this file — and without it no desktop environment ever learns that
8-
`*.strata` means `application/x-strata`. The association therefore looked
9-
configured while double-clicking a document did nothing.
6+
`MimeType=application/x-varve;application/x-strata` into the .desktop
7+
entry, but it does not emit this file — and without it no desktop
8+
environment ever learns that `*.varve` means `application/x-varve` or
9+
that `*.strata` means `application/x-strata`. The association therefore
10+
looked configured while double-clicking a document did nothing.
1011
1112
Installed to /usr/share/mime/packages/ by the deb and rpm bundles. The
1213
post-install `update-mime-database` run is handled by the packaging tooling
1314
on Debian and Fedora; on a manual install, run:
1415
sudo update-mime-database /usr/share/mime
1516
-->
1617
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
17-
<mime-type type="application/x-strata">
18+
<mime-type type="application/x-varve">
1819
<comment>Varve design document</comment>
19-
<comment xml:lang="en-GB">Strata design document</comment>
20-
<glob pattern="*.strata"/>
20+
<glob pattern="*.varve"/>
2121
<icon name="dev.varve.desktop"/>
2222
<generic-icon name="image-x-generic"/>
2323
<!--
2424
Documents are JSON (see packages/platform/src/tauri.ts — the save dialog
2525
writes the native JSON format), so declare the supertype. This gives
26-
sensible fallback behaviour in file managers that do not know Strata.
26+
sensible fallback behaviour in file managers that do not know Varve.
2727
-->
2828
<sub-class-of type="application/json"/>
29+
<magic priority="40">
30+
<match type="string" value="{&quot;varve&quot;" offset="0:64"/>
31+
</magic>
32+
</mime-type>
33+
<mime-type type="application/x-strata">
34+
<comment>Varve design document (legacy Strata format)</comment>
35+
<glob pattern="*.strata"/>
36+
<icon name="dev.varve.desktop"/>
37+
<generic-icon name="image-x-generic"/>
38+
<sub-class-of type="application/json"/>
2939
<magic priority="40">
3040
<match type="string" value="{&quot;strata&quot;" offset="0:64"/>
3141
</magic>

‎apps/desktop/src-tauri/src/lib.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,11 @@ pub fn run() {
22102210
let has_document_ext = event
22112211
.paths
22122212
.iter()
2213-
.any(|p| p.extension().map(|e| e == "strata").unwrap_or(false));
2213+
.any(|p| {
2214+
p.extension()
2215+
.map(|e| e == "varve" || e == "strata")
2216+
.unwrap_or(false)
2217+
});
22142218
if has_document_ext {
22152219
let _ = tx.send(());
22162220
}

‎apps/desktop/src-tauri/tauri.conf.json‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@
4343
"https://www.googleapis.com",
4444
"https://*.githubusercontent.com",
4545
"https://*.huggingface.co",
46-
"https://*.hf.co"
46+
"https://*.hf.co",
47+
"https://api.iconify.design",
48+
"https://api.simplesvg.com",
49+
"https://api.unisvg.com"
4750
],
4851
"worker-src": ["'self'"],
4952
"media-src": ["'self'", "blob:", "data:"],
@@ -70,7 +73,10 @@
7073
"https://www.googleapis.com",
7174
"https://*.githubusercontent.com",
7275
"https://*.huggingface.co",
73-
"https://*.hf.co"
76+
"https://*.hf.co",
77+
"https://api.iconify.design",
78+
"https://api.simplesvg.com",
79+
"https://api.unisvg.com"
7480
],
7581
"worker-src": ["'self'"],
7682
"media-src": ["'self'", "blob:", "data:"],
@@ -89,9 +95,16 @@
8995
"resources": ["onnxruntime-libs/**/*"],
9096
"fileAssociations": [
9197
{
92-
"ext": ["strata"],
98+
"ext": ["varve"],
9399
"name": "Varve Document",
94100
"description": "Varve design document",
101+
"mimeType": "application/x-varve",
102+
"role": "Editor"
103+
},
104+
{
105+
"ext": ["strata"],
106+
"name": "Varve Document (legacy)",
107+
"description": "Varve design document (legacy Strata format)",
95108
"mimeType": "application/x-strata",
96109
"role": "Editor"
97110
}

‎apps/desktop/src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export function App() {
118118
id: entry.id,
119119
name: entry.name,
120120
json,
121+
filePath: entry.filePath,
121122
seq: (prev?.seq ?? 0) + 1,
122123
}));
123124
markEditorStateInitialized();
@@ -144,6 +145,7 @@ export function App() {
144145
id: entry.id,
145146
name: entry.name,
146147
json,
148+
filePath: entry.filePath,
147149
seq: (prev?.seq ?? 0) + 1,
148150
}));
149151
markEditorStateInitialized();

‎packages/editor/src/Shell.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { ImageCompareOverlay } from './components/ImageCompareOverlay';
2121
import { PropertiesPanel } from './components/Inspector/PropertiesPanel';
2222
import type { LayersDnDHandle } from './components/LayersPanel/LayersTree';
2323
import { PresenceIndicator } from './components/LayersPanel/PresenceIndicator';
24-
import { LibraryPanel } from './components/LibraryPanel/LibraryPanel';
2524
import { LogoPanel } from './components/LogoPanel/LogoPanel';
2625
import { LogoPreviewDialog } from './components/LogoPreview/LogoPreviewDialog';
2726
import { MasterPanel } from './components/MasterPanel/MasterPanel';
@@ -32,6 +31,7 @@ import { PanelResizeHandle, usePanelWidths } from './components/PanelResizeHandl
3231
import { PromptDialog, promptDialog } from './components/PromptDialog';
3332
import { PrototypePresenter } from './components/Prototype/PrototypePresenter';
3433
import { QuickActionsBar } from './components/QuickActionsBar/QuickActionsBar';
34+
import { IconBrowserDialog, ResourcesPanel } from './components/ResourcesPanel/ResourcesPanel';
3535
import { SelectionInfoBar } from './components/SelectionInfoBar';
3636
import { SettingsProvider } from './components/Settings/SettingsContext';
3737
import { SettingsDialog } from './components/Settings/SettingsDialog';
@@ -183,6 +183,7 @@ function ShellInner({
183183
const [layersVisible, setLayersVisible] = useState(false);
184184
const [inspectorVisible, setInspectorVisible] = useState(false);
185185
const [settingsOpen, setSettingsOpen] = useState(false);
186+
const [iconBrowserOpen, setIconBrowserOpen] = useState(false);
186187
const [settingsSection, setSettingsSection] = useState<
187188
| 'general'
188189
| 'appearance'
@@ -241,6 +242,7 @@ function ShellInner({
241242
},
242243
onBatchBgRemove: () => exportLayerRef.current?.openBatchBgRemove(),
243244
onFindReplace: () => findReplaceLayerRef.current?.open(),
245+
onInsertIcon: () => setIconBrowserOpen(true),
244246
onOpenFile: () => fileRef.current?.click(),
245247
onImportFile: () => fileRef.current?.click(),
246248
});
@@ -410,7 +412,7 @@ function ShellInner({
410412
)}
411413
{libraryPanelVisible && !distractionFreeMode && (
412414
<div className="editor__library-panel" data-panel="library">
413-
<LibraryPanel
415+
<ResourcesPanel
414416
doc={editor.state.document}
415417
onInstallLibrary={editor.installLibrary}
416418
onUninstallLibrary={editor.uninstallLibrary}
@@ -563,7 +565,7 @@ function ShellInner({
563565
type="button"
564566
className="editor__fab editor__fab--library"
565567
onClick={() => editor.toggleLibraryPanel()}
566-
aria-label={libraryPanelVisible ? 'Hide library panel' : 'Show library panel'}
568+
aria-label={libraryPanelVisible ? 'Hide resources panel' : 'Show resources panel'}
567569
>
568570
<Icon name="Library" />
569571
</button>
@@ -607,7 +609,7 @@ function ShellInner({
607609
ref={fileRef}
608610
id="file-open-input"
609611
type="file"
610-
accept=".strata,.json"
612+
accept=".varve,.strata,.json"
611613
style={{ display: 'none' }}
612614
onChange={(e) => {
613615
const file = e.target.files?.[0];
@@ -743,6 +745,11 @@ function ShellInner({
743745
{/* Export dialog + batch BG removal (self-contained) */}
744746
<ExportLayer ref={exportLayerRef} platform={platform} />
745747
<FindReplaceLayer ref={findReplaceLayerRef} />
748+
<IconBrowserDialog
749+
open={iconBrowserOpen}
750+
onClose={() => setIconBrowserOpen(false)}
751+
title="Insert icon"
752+
/>
746753

747754
{editor.state.subjectPickerSession && (
748755
<SubjectPickerOverlay

‎packages/editor/src/context/usePersistence.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ export function usePersistence(
7575
const meta = s.sessions.find((sess) => sess.id === s.activeId);
7676
const json = DocumentCodec.encode(s.document);
7777
if (meta?.fileId) {
78+
// App-store copy (recents, thumbnails, home screen) — always kept.
7879
await upsertPreservingMeta(platform, meta.fileId, meta.name, json);
80+
// Figma/Photoshop behavior: a document opened from disk saves back
81+
// to its original path. When the runtime supports path writes,
82+
// keep the external file in sync too; unsupported runtimes (web)
83+
// fall back to the picker inside writeDocumentToPath.
84+
if (meta.filePath) {
85+
const written = await platform.writeDocumentToPath(meta.filePath, json);
86+
if (!written) {
87+
// The user cancelled the picker fallback — still keep the app
88+
// store copy, but surface the save as cancelled.
89+
return false;
90+
}
91+
}
7992
} else {
8093
return await saveAsImpl(platform, stateRef, recoveryRef, patch);
8194
}

‎packages/editor/src/recovery.ts‎

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ export class MemoryRecoveryStorage implements RecoveryStorage {
4646
}
4747

4848
export class IndexedDbRecoveryStorage implements RecoveryStorage {
49-
private dbName = 'strata-recovery';
49+
/** Live DB name. Recovery sessions are recovered-from or deleted within
50+
* seconds of an app crash, so a one-time copy of the legacy database
51+
* (strata-recovery) keeps pre-rename crash sessions discoverable. */
52+
private dbName = 'varve-recovery';
53+
private legacyDbName = 'strata-recovery';
5054
private storeName = 'sessions';
5155

5256
private async db(): Promise<IDBDatabase> {
@@ -60,7 +64,73 @@ export class IndexedDbRecoveryStorage implements RecoveryStorage {
6064
});
6165
}
6266

67+
/** Copy any legacy pre-rename sessions into the live database once, so
68+
* crash recovery survives the rename. Idempotent: the legacy DB is only
69+
* read; it is never deleted (rollback to an old build keeps working). */
70+
private async migrateLegacy(): Promise<void> {
71+
try {
72+
const legacy = indexedDB.open(this.legacyDbName, 1);
73+
const legacyDb = await new Promise<IDBDatabase | null>((resolve) => {
74+
legacy.onupgradeneeded = () => {
75+
// Never mutate the legacy schema.
76+
legacy.transaction?.abort();
77+
};
78+
legacy.onsuccess = () => resolve(legacy.result);
79+
legacy.onerror = () => resolve(null);
80+
});
81+
if (!legacyDb) return;
82+
try {
83+
const tx = legacyDb.transaction('sessions', 'readonly');
84+
const store = tx.objectStore('sessions');
85+
const keysReq = store.getAllKeys();
86+
const valuesReq = store.getAll();
87+
await Promise.all([
88+
new Promise<void>((resolve, reject) => {
89+
keysReq.onsuccess = () => resolve();
90+
keysReq.onerror = () => reject(keysReq.error);
91+
}),
92+
new Promise<void>((resolve, reject) => {
93+
valuesReq.onsuccess = () => resolve();
94+
valuesReq.onerror = () => reject(valuesReq.error);
95+
}),
96+
]);
97+
const live = await this.db();
98+
const liveTx = live.transaction(this.storeName, 'readwrite');
99+
const liveStore = liveTx.objectStore(this.storeName);
100+
const keys = keysReq.result as IDBValidKey[];
101+
const values = valuesReq.result as string[];
102+
keys.forEach((key, i) => {
103+
// Only fill missing keys — never overwrite a newer session.
104+
const existing = liveTx.objectStore(this.storeName).get(key);
105+
existing.onsuccess = () => {
106+
if (existing.result == null && values[i] != null) {
107+
liveStore.put(values[i] as string, key);
108+
}
109+
};
110+
});
111+
await new Promise<void>((resolve, reject) => {
112+
liveTx.oncomplete = () => resolve();
113+
liveTx.onerror = () => reject(liveTx.error);
114+
});
115+
} finally {
116+
legacyDb.close();
117+
}
118+
} catch {
119+
// Best-effort migration only.
120+
}
121+
}
122+
123+
private async ensureMigrated(): Promise<void> {
124+
if (!this.migrationDone) {
125+
this.migrationDone = true;
126+
await this.migrateLegacy();
127+
}
128+
}
129+
130+
private migrationDone = false;
131+
63132
async save(key: string, data: string): Promise<void> {
133+
await this.ensureMigrated();
64134
const db = await this.db();
65135
return new Promise((resolve, reject) => {
66136
const tx = db.transaction(this.storeName, 'readwrite');
@@ -71,6 +141,7 @@ export class IndexedDbRecoveryStorage implements RecoveryStorage {
71141
}
72142

73143
async load(key: string): Promise<string | null> {
144+
await this.ensureMigrated();
74145
const db = await this.db();
75146
return new Promise((resolve, reject) => {
76147
const tx = db.transaction(this.storeName, 'readonly');
@@ -81,6 +152,7 @@ export class IndexedDbRecoveryStorage implements RecoveryStorage {
81152
}
82153

83154
async list(): Promise<string[]> {
155+
await this.ensureMigrated();
84156
const db = await this.db();
85157
return new Promise((resolve, reject) => {
86158
const tx = db.transaction(this.storeName, 'readonly');
@@ -91,6 +163,7 @@ export class IndexedDbRecoveryStorage implements RecoveryStorage {
91163
}
92164

93165
async delete(key: string): Promise<void> {
166+
await this.ensureMigrated();
94167
const db = await this.db();
95168
return new Promise((resolve, reject) => {
96169
const tx = db.transaction(this.storeName, 'readwrite');

0 commit comments

Comments
 (0)