mirror of
https://github.com/dragonwocky/obsidian-tray.git
synced 2025-04-03 11:39:02 +00:00
feat: #2 customisable tray icon image
This commit is contained in:
parent
84a02f157a
commit
db671961c5
35
main.js
35
main.js
@ -122,7 +122,9 @@ const addQuickNote = (plugin) => {
|
||||
},
|
||||
createTrayIcon = (plugin) => {
|
||||
log(LOG_TRAY_ICON);
|
||||
const obsidianIcon = nativeImage.createFromDataURL(OBSIDIAN_BASE64_ICON),
|
||||
const obsidianIcon = nativeImage.createFromDataURL(
|
||||
plugin.settings.trayIconImage ?? OBSIDIAN_BASE64_ICON
|
||||
),
|
||||
contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
type: "normal",
|
||||
@ -236,6 +238,16 @@ const OPTIONS = [
|
||||
type: "toggle",
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
key: "trayIconImage",
|
||||
desc: `
|
||||
Set the image used by the tray/menubar icon. Recommended size: 16x16
|
||||
<br>Preview: <img data-preview style="height: 16px; vertical-align: bottom;">
|
||||
<br>${REQUIRES_RESTART}
|
||||
`,
|
||||
type: "image",
|
||||
default: OBSIDIAN_BASE64_ICON,
|
||||
},
|
||||
{
|
||||
key: "toggleWindowFocusHotkey",
|
||||
desc: ACCELERATOR_FORMAT,
|
||||
@ -311,6 +323,27 @@ class SettingsTab extends obsidian.PluginSettingTab {
|
||||
.setValue(this.plugin.settings[opt.key] ?? opt.default)
|
||||
.onChange(onChange);
|
||||
});
|
||||
} else if (opt.type === "image") {
|
||||
const previewImg = setting.descEl.querySelector("img[data-preview");
|
||||
if (previewImg) {
|
||||
const src = this.plugin.settings[opt.key] ?? opt.default;
|
||||
previewImg.src = src;
|
||||
}
|
||||
const fileUpload = setting.descEl.createEl("input");
|
||||
fileUpload.style.visibility = "hidden";
|
||||
fileUpload.type = "file";
|
||||
fileUpload.onchange = (event) => {
|
||||
const file = event.target.files[0],
|
||||
reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
onChange(reader.result);
|
||||
if (previewImg) previewImg.src = reader.result;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
setting.addButton((button) => {
|
||||
button.setIcon("image").onClick(() => fileUpload.click());
|
||||
});
|
||||
} else if (opt.type === "moment") {
|
||||
setting.addMomentFormat((moment) => {
|
||||
const previewEl = setting.descEl.querySelector("[data-preview]");
|
||||
|
Loading…
Reference in New Issue
Block a user