Skip to content

Commit

Permalink
Improve desktop icon quality and generation
Browse files Browse the repository at this point in the history
This commit refactors the icon and logo generation process by replacing
multiple dependencies with ImageMagick. This simplifies the build
process and enhances maintainability.

Key changes:

- Remove unnecessary icon files for macOS (.icns) and Linux
  (size-specific PNGs). Electron-builder can now auto-generate these
  from a single `logo.png` starting from version 19.54.0, see:
  - electron-userland/electron-builder#1682
  - electron-userland/electron-builder#2533
- Retain `ico` generation with multiple sizes to fix pixelated/bad
  looking icons on Windows, see:
  - electron-userland/electron-builder#7328
  - electron-userland/electron-builder#3867
- Replaced `svgexport`, `icon-gen`, and `electron-icon-builder`
  dependencies with ImageMagick, addressing issues with outdated
  dependencies and unreliable CI/CD builds.
- Move electron-builder build resources to
  `src/presentation/electron/build` for better project structure.
- Improve `electron-builder` configuration file by making it
  importable/reusable without prebuilding the Electron application.
  • Loading branch information
undergroundwires committed May 4, 2024
1 parent 813d820 commit ab25e0a
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 4,090 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/checks.scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
-
name: Checkout
uses: actions/checkout@v4
-
name: Install ImageMagick on macOS
if: matrix.os == 'macos'
run: brew install imagemagick
-
name: Setup node
uses: ./.github/actions/setup-node
Expand Down
5 changes: 0 additions & 5 deletions build/README.md

This file was deleted.

Binary file removed build/icons/1024x1024.png
Binary file not shown.
Binary file removed build/icons/128x128.png
Binary file not shown.
Binary file removed build/icons/16x16.png
Binary file not shown.
Binary file removed build/icons/24x24.png
Binary file not shown.
Binary file removed build/icons/256x256.png
Binary file not shown.
Binary file removed build/icons/32x32.png
Binary file not shown.
Binary file removed build/icons/48x48.png
Binary file not shown.
Binary file removed build/icons/512x512.png
Binary file not shown.
Binary file removed build/icons/64x64.png
Binary file not shown.
Binary file removed build/icons/icon.icns
Binary file not shown.
6 changes: 4 additions & 2 deletions docs/presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ The presentation layer uses an event-driven architecture for bidirectional react
- [**`styles/`**](./../src/presentation/assets/styles/): Contains shared styles.
- [**`main.scss`**](./../src/presentation/assets/styles/main.scss): Main Sass file, imported by other components as single entrypoint..
- [**`electron/`**](./../src/presentation/electron/): Contains Electron code.
- [`/main/` **`index.ts`**](./../src/presentation/main.ts): Main entry for Electron, managing application windows and lifecycle events.
- [`/preload/` **`index.ts`**](./../src/presentation/main.ts): Script executed before the renderer, securing Node.js features for renderer use.
- [`/main/` **`index.ts`**](./../src/presentation/electron/main/index.ts): Main entry for Electron, managing application windows and lifecycle events.
- [`/preload/` **`index.ts`**](./../src/presentation/electron/preload/index.ts): Script executed before the renderer, securing Node.js features for renderer use.
- [**`/shared/`**](./../src/presentation/electron/shared/): Shared logic between different Electron processes.
- [**`/build/`**](./../src/presentation/electron/build/): `electron-builder` build resources directory, [README.md](./../src/presentation/electron/build/README.md).
- [**`/vite.config.ts`**](./../vite.config.ts): Contains Vite configurations for building web application.
- [**`/electron.vite.config.ts`**](./../electron.vite.config.ts): Contains Vite configurations for building desktop applications.
- [**`/postcss.config.cjs`**](./../postcss.config.cjs): Contains PostCSS configurations for Vite.
Expand Down
17 changes: 13 additions & 4 deletions electron-builder.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-template-curly-in-string */

const { join } = require('node:path');
const { readdirSync } = require('fs');
const { join, resolve } = require('node:path');
const { readdirSync, existsSync } = require('node:fs');
const { electronBundled, electronUnbundled } = require('./dist-dirs.json');

/**
Expand All @@ -17,6 +17,7 @@ module.exports = {
},
directories: {
output: electronBundled,
buildResources: resolvePathFromProjectRoot('src/presentation/electron/build'),
},
extraMetadata: {
main: findMainEntryFile(
Expand Down Expand Up @@ -53,10 +54,18 @@ module.exports = {
* Finds by accommodating different JS file extensions and module formats.
*/
function findMainEntryFile(parentDirectory) {
const files = readdirSync(parentDirectory);
const absoluteParentDirectory = resolvePathFromProjectRoot(parentDirectory);
if (!existsSync(absoluteParentDirectory)) {
return null; // Avoid disrupting other processes such `npm install`.
}
const files = readdirSync(absoluteParentDirectory);
const entryFile = files.find((file) => /^index\.(cjs|mjs|js)$/.test(file));
if (!entryFile) {
throw new Error(`Main entry file not found in ${parentDirectory}.`);
throw new Error(`Main entry file not found in ${absoluteParentDirectory}.`);
}
return join(parentDirectory, entryFile);
}

function resolvePathFromProjectRoot(pathSegment) {
return resolve(__dirname, pathSegment);
}

0 comments on commit ab25e0a

Please sign in to comment.