fix: improve desktop chat performance

This commit is contained in:
Simos Mikelatos
2026-06-24 20:49:24 +00:00
parent fe116a7138
commit 8ad18f8587
11 changed files with 153 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -682,10 +682,18 @@ export class DesktopWindowManager {
}
configurePermissions() {
session.defaultSession.setPermissionRequestHandler((webContents, permission, callback) => {
const isAllowedPermission = (webContents, permission) => {
const sourceUrl = webContents.getURL();
const allowedPermissions = new Set(['clipboard-read', 'media']);
callback(isAllowedPermissionOrigin(sourceUrl, this.getCloudState().controlPlaneUrl) && allowedPermissions.has(permission));
const allowedPermissions = new Set(['clipboard-read', 'media', 'notifications']);
return isAllowedPermissionOrigin(sourceUrl, this.getCloudState().controlPlaneUrl) && allowedPermissions.has(permission);
};
session.defaultSession.setPermissionRequestHandler((webContents, permission, callback) => {
callback(isAllowedPermission(webContents, permission));
});
session.defaultSession.setPermissionCheckHandler((webContents, permission) => {
if (!webContents) return false;
return isAllowedPermission(webContents, permission);
});
}

View File

@@ -12,6 +12,7 @@ import { TabsController } from './tabs.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const APP_NAME = 'CloudCLI';
const APP_USER_MODEL_ID = 'ai.cloudcli.desktop';
const CALLBACK_PROTOCOL = 'cloudcli';
const CALLBACK_URL = `${CALLBACK_PROTOCOL}://auth/callback`;
const CLOUDCLI_CONTROL_PLANE_URL = process.env.CLOUDCLI_CONTROL_PLANE_URL || 'https://cloudcli.ai';
@@ -20,6 +21,10 @@ const AUTH_CALLBACK_TTL_MS = 10 * 60 * 1000;
const tabs = new TabsController();
if (process.platform === 'win32') {
app.setAppUserModelId(APP_USER_MODEL_ID);
}
let activeTarget = { kind: 'launcher', name: APP_NAME, url: null };
let desktopWindow = null;
let localServer = null;

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env node
import fs from 'node:fs/promises';
import path from 'node:path';
import sharp from 'sharp';
const assetsDir = 'electron/assets';
const sourcePath = 'public/logo-512.png';
const icoPath = path.join(assetsDir, 'logo-windows.ico');
const sizes = [16, 24, 32, 48, 64, 128, 256];
function writeDirectoryEntry(buffer, image, offset) {
buffer.writeUInt8(image.size === 256 ? 0 : image.size, offset);
buffer.writeUInt8(image.size === 256 ? 0 : image.size, offset + 1);
buffer.writeUInt8(0, offset + 2);
buffer.writeUInt8(0, offset + 3);
buffer.writeUInt16LE(1, offset + 4);
buffer.writeUInt16LE(32, offset + 6);
buffer.writeUInt32LE(image.buffer.length, offset + 8);
buffer.writeUInt32LE(image.offset, offset + 12);
}
async function renderPng(size) {
return sharp(sourcePath)
.resize(size, size, { fit: 'contain' })
.png()
.toBuffer();
}
await fs.mkdir(assetsDir, { recursive: true });
const images = await Promise.all(
sizes.map(async (size) => ({
size,
buffer: await renderPng(size),
offset: 0,
})),
);
const headerSize = 6 + images.length * 16;
let cursor = headerSize;
for (const image of images) {
image.offset = cursor;
cursor += image.buffer.length;
}
const ico = Buffer.alloc(cursor);
ico.writeUInt16LE(0, 0);
ico.writeUInt16LE(1, 2);
ico.writeUInt16LE(images.length, 4);
images.forEach((image, index) => {
writeDirectoryEntry(ico, image, 6 + index * 16);
image.buffer.copy(ico, image.offset);
});
await fs.writeFile(icoPath, ico);
console.log(`Wrote ${icoPath}`);