Skip to content

Commit ec4f9f3

Browse files
committed
fix: file size #6
1 parent f167c33 commit ec4f9f3

4 files changed

Lines changed: 49 additions & 556 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
2-
dist
3-
release
2+
dist*
3+
release

main.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const fs = require("fs/promises");
1010
const fsSync = require("fs"); // Use sync version for setup
1111
const { exec } = require("child_process");
1212
const os = require("os");
13-
const sharp = require("sharp"); // Import the sharp library
1413

1514
let mainWindow = null;
1615

@@ -156,15 +155,13 @@ ipcMain.handle("get-thumbnail", async (event, imageName) => {
156155
const data = await fs.readFile(thumbPath);
157156
return data.toString("base64");
158157
} catch {
159-
// If cache miss, generate a new thumbnail
158+
// Use native macOS sips command to generate thumbnail
160159
try {
161-
const buffer = await sharp(sourcePath)
162-
.resize({ width: 400 }) // Resize to 400px wide, maintaining aspect ratio
163-
.toBuffer();
160+
const sipsCommand = `sips -Z 400 "${sourcePath}" --out "${thumbPath}"`;
161+
await run(sipsCommand);
164162

165-
// Save the new thumbnail to the cache for next time
166-
await fs.writeFile(thumbPath, buffer);
167-
return buffer.toString("base64");
163+
const data = await fs.readFile(thumbPath);
164+
return data.toString("base64");
168165
} catch (generationError) {
169166
console.error(
170167
`Failed to generate thumbnail for ${imageName}:`,

0 commit comments

Comments
 (0)