Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom icon themes #520

Merged
merged 22 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d2938c2
:wrench: Add methods for listing user icons
Schneegans Jul 5, 2024
f50d9ad
:wrench: Use icon theme registry in the menu class
Schneegans Jul 5, 2024
045138c
:wrench: Allow loading local files during development
Schneegans Jul 6, 2024
cef629e
:tada: Add user icon themes
Schneegans Jul 6, 2024
61114eb
:wrench: Prevent custom icons from being draggable
Schneegans Jul 6, 2024
ae8f4ce
:bug: Hide custom icons on minimized menu items
Schneegans Jul 7, 2024
65cc444
:wrench: Load icons only if they are in view in the icon picker
Schneegans Jul 7, 2024
74e4158
:wrench: Load custom icon themes recursively
Schneegans Jul 7, 2024
ed47027
:wrench: Run checks also on pull requests
Schneegans Jul 7, 2024
0a511b7
:wrench: Delete tooltips when reloading the icon list
Schneegans Jul 7, 2024
0c2d9c3
Merge branch 'main' into feature/custom-icon-themes
Schneegans Jul 8, 2024
958b46c
:wrench: Show a question mark if no icon theme is found
Schneegans Jul 8, 2024
aed5932
:memo: Add changelog entry
Schneegans Jul 8, 2024
bbc3da9
:memo: Split configuring docs into two files
Schneegans Jul 8, 2024
201f4fa
:memo: Add some docs on icon themes
Schneegans Jul 8, 2024
1d25ae2
:memo: Update icon docs
Schneegans Jul 8, 2024
e5069ca
:memo: Rename docs page
Schneegans Jul 9, 2024
bdef677
:memo: Add new documentation chapter
Schneegans Jul 9, 2024
0dee79d
:twisted_rightwards_arrows: Merge branch 'main' into feature/custom-i…
Schneegans Jul 9, 2024
8a9784b
:bug: Properly close the editor when opening an external link
Schneegans Jul 9, 2024
47a96fb
:wrench: Add header to icon picker
Schneegans Jul 9, 2024
3b8ae33
:bug: Fix scrolling icon into view when opening the icon picker
Schneegans Jul 9, 2024
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
Next Next commit
🔧 Add methods for listing user icons
  • Loading branch information
Schneegans committed Jul 5, 2024
commit d2938c28311554a470f22d4521296cadbb7e34ab
9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@popperjs/core": "^2.11.8",
"@types/bootstrap": "^5.2.10",
"@types/lodash.isequal": "^4.5.8",
"@types/mime-types": "^2.1.4",
"bootstrap": "^5.3.1",
"chokidar": "^3.6.0",
"commander": "^12.0.0",
Expand All @@ -71,6 +72,7 @@
"lodash.isequal": "^4.5.0",
"match-sorter": "^6.3.4",
"material-symbols": "^0.20.0",
"mime-types": "^2.1.35",
"node-addon-api": "^8.0.0",
"octokit": "^4.0.2",
"simple-icons-font": "^13.0.0"
Expand Down
2 changes: 2 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ declare global {
getCurrentMenu: () => Promise<number>;
};
getBackendInfo: () => Promise<IBackendInfo>;
getUserIconThemes: () => Promise<Array<string>>;
listUserIcons: (string: iconTheme) => Promise<Array<string>>;
showDevTools: () => void;
movePointer: (dist: IVec2) => void;
log: (message: string) => void;
Expand Down
48 changes: 47 additions & 1 deletion src/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
// SPDX-License-Identifier: MIT

import os from 'node:os';
import { screen, BrowserWindow, ipcMain, shell, Tray, Menu, app } from 'electron';
import fs from 'fs';
import mime from 'mime-types';
import path from 'path';
import { screen, BrowserWindow, ipcMain, shell, Tray, Menu, app } from 'electron';
import { Notification } from 'electron';

import { Backend, getBackend } from './backends';
Expand Down Expand Up @@ -565,6 +567,50 @@ export class KandoApp {
return this.backend.getBackendInfo();
});

// Allow the renderer to retrieve all subdirectories of the icon-themes directory.
ipcMain.handle('get-user-icon-themes', async () => {
return new Promise<string[]>((resolve, reject) => {
const iconThemesDir = path.join(app.getPath('userData'), 'icon-themes');
fs.readdir(iconThemesDir, { withFileTypes: true }, (err, dirents) => {
if (err) {
reject(err);
return;
}

const iconThemes = dirents
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

resolve(iconThemes);
});
});
});

// Allow the renderer to retrieve all files in the given icon theme directory.
ipcMain.handle('list-user-icons', async (event, iconTheme: string) => {
return new Promise<string[]>((resolve, reject) => {
const iconDir = path.join(app.getPath('userData'), 'icon-themes', iconTheme);
fs.readdir(iconDir, { withFileTypes: true }, (err, files) => {
if (err) {
reject(err);
return;
}

// Filter by mimetype to only return image files.
files = files.filter((file) => {
if (!file.isFile()) {
return false;
}

const mimeType = mime.lookup(file.name);
return mimeType && mimeType.startsWith('image/');
});

resolve(files.map((file) => file.name));
});
});
});

// Show the web developer tools if requested.
ipcMain.on('show-dev-tools', () => {
this.window.webContents.openDevTools();
Expand Down
17 changes: 17 additions & 0 deletions src/renderer/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ contextBridge.exposeInMainWorld('api', {
return ipcRenderer.invoke('get-backend-info');
},

/**
* This will return all subdirectories of the icon-themes directory in the config
* directory.
*/
getUserIconThemes: function () {
return ipcRenderer.invoke('get-user-icon-themes');
},

/**
* This will return all files in the given icon theme directory.
*
* @param iconTheme The icon theme to list.
*/
listUserIcons: function (iconTheme: string) {
return ipcRenderer.invoke('list-user-icons', iconTheme);
},

/** This will show the web developer tools. */
showDevTools: function () {
ipcRenderer.send('show-dev-tools');
Expand Down