Skip to content

AI-native design editor. Open-source Figma alternative.

fix(desktop): allow reading recent .fig files for thumbnails (#872)

Danila Poyarkovf2485d692634
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7fe1e4717..15508a87e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,7 @@
### Fixed
+- Show `.fig` thumbnails in the desktop app's recent files, which the app was not permitted to read.
- Give paints set through the plugin API, `eval`, and AI and MCP scripts an opacity of 1 and make them visible when the script leaves those out, as Figma does. Such paints were stored without them, which the Design panel could not show.
- Show variable-bound colours and numbers correctly when a `.fig` exported from OpenPencil opens in Figma. Figma draws the value a bound field stores until something makes it resolve the variable again, and exports stored the colour from before the binding, so a bound fill appeared in its old colour. Each bound field is now written as it resolves in its layer's mode, or in the collection's default mode when the layer sets none.
- Open Figma files that use slots with each instance's own slot content instead of its component's default, keep slot properties, their settings, and instance content when saving back to `.fig`, and keep an instance's slot content when you switch its variant.
diff --git a/desktop/capabilities/default.json b/desktop/capabilities/default.json
index 0926a3560..86ca5fc2b 100644
--- a/desktop/capabilities/default.json
+++ b/desktop/capabilities/default.json
@@ -19,6 +19,17 @@
"identifier": "fs:allow-read-file",
"allow": [{ "path": "**" }]
},
+ {
+ "identifier": "fs:allow-stat",
+ "allow": [{ "path": "**" }]
+ },
+ {
+ "identifier": "fs:allow-open",
+ "allow": [{ "path": "**" }]
+ },
+ "fs:allow-fstat",
+ "fs:allow-seek",
+ "fs:allow-read",
{
"identifier": "fs:allow-read-text-file",
"allow": [
diff --git a/tests/e2e/native/recent-files.spec.ts b/tests/e2e/native/recent-files.spec.ts
new file mode 100644
index 000000000..cd5d9b5cf
--- /dev/null
+++ b/tests/e2e/native/recent-files.spec.ts
@@ -0,0 +1,31 @@
+import { strict as assert } from 'node:assert'
+import { join } from 'node:path'
+
+import { invokeNative, invokeNativeBytes } from '#tests/helpers/tauri/invoke'
+
+const fixture = join(process.cwd(), 'tests', 'fixtures', 'gold-preview.fig')
+// A .fig file is a zip archive.
+const ZIP_SIGNATURE = [0x50, 0x4b, 0x03, 0x04]
+
+describe('recent file thumbnails', () => {
+ it('reads a .fig file the way the thumbnail loader does', async () => {
+ const info = await invokeNative<{ size: number }>('plugin:fs|stat', { path: fixture })
+ assert.ok(info.size > 0, 'stat returned no size')
+
+ const rid = await invokeNative<number>('plugin:fs|open', {
+ path: fixture,
+ options: { read: true }
+ })
+ try {
+ const handle = await invokeNative<{ size: number }>('plugin:fs|fstat', { rid })
+ assert.equal(handle.size, info.size)
+ await invokeNative('plugin:fs|seek', { rid, offset: 0, whence: 0 })
+ // The plugin appends the byte count as a big-endian u64 after the data.
+ const read = await invokeNativeBytes('plugin:fs|read', { rid, len: ZIP_SIGNATURE.length })
+ assert.deepEqual(read.slice(0, -8), ZIP_SIGNATURE)
+ assert.equal(read.at(-1), ZIP_SIGNATURE.length)
+ } finally {
+ await invokeNative('plugin:resources|close', { rid })
+ }
+ })
+})
diff --git a/tests/helpers/tauri/invoke.ts b/tests/helpers/tauri/invoke.ts
index 2150c9830..0f9ea6321 100644
--- a/tests/helpers/tauri/invoke.ts
+++ b/tests/helpers/tauri/invoke.ts
@@ -14,3 +14,20 @@ export async function invokeNative<T>(command: string, args?: InvokeArguments):
args
)
}
+
+/** Invoke a command that returns raw bytes; WebDriver cannot serialize an ArrayBuffer. */
+export async function invokeNativeBytes(
+ command: string,
+ args?: InvokeArguments
+): Promise<number[]> {
+ return browser.execute(
+ async (command, args) => {
+ const core = window.__TAURI__?.core
+ if (!core) throw new Error('Native test requires app.withGlobalTauri')
+ const data = await core.invoke<ArrayBuffer | number[]>(command, args)
+ return Array.from(data instanceof ArrayBuffer ? new Uint8Array(data) : data)
+ },
+ command,
+ args
+ )
+}