Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/prod/okcode-windows.ico
Binary file not shown.
46 changes: 46 additions & 0 deletions scripts/build-desktop-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,42 @@ function stageLinuxIcons(stageResourcesDir: string) {
});
}

function icoContains256Frame(bytes: Uint8Array): boolean {
if (bytes.byteLength < 6) {
return false;
}

const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const reserved = view.getUint16(0, true);
const imageType = view.getUint16(2, true);
const imageCount = view.getUint16(4, true);

if (reserved !== 0 || imageType !== 1 || imageCount <= 0) {
return false;
}

const directoryEnd = 6 + imageCount * 16;
if (directoryEnd > bytes.byteLength) {
return false;
}

for (let index = 0; index < imageCount; index += 1) {
const entryOffset = 6 + index * 16;
const widthRaw = bytes[entryOffset];
const heightRaw = bytes[entryOffset + 1];
if (widthRaw === undefined || heightRaw === undefined) {
return false;
}
const width = widthRaw === 0 ? 256 : widthRaw;
const height = heightRaw === 0 ? 256 : heightRaw;
if (width >= 256 && height >= 256) {
return true;
}
}

return false;
}

function stageWindowsIcons(stageResourcesDir: string) {
return Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
Expand All @@ -360,6 +396,16 @@ function stageWindowsIcons(stageResourcesDir: string) {
});
}

const iconBytes = yield* fs.readFile(iconSource);
if (!icoContains256Frame(iconBytes)) {
return yield* new BuildScriptError({
message:
`Production Windows icon at ${iconSource} must include a 256x256 frame. ` +
`Regenerate ${BRAND_ASSET_PATHS.productionWindowsIconIco} with multi-size ICO entries ` +
`(for example 16,32,48,64,128,256) before packaging.`,
});
}

const iconPath = path.join(stageResourcesDir, "icon.ico");
yield* fs.copyFile(iconSource, iconPath);
});
Expand Down
Loading