Closed Araxeus closed 3 years ago
It also has an src folder instead of lib, which means that cloning the repo and running dev will run an error because of lib folder missing which is abit weird
source belongs in repos, build data belongs in releases, and never the two shall meet except in dev repos and build servers. :-)
(at least, that's my personal take on it)
code changes look good, although i don't know where the duplicate checkbox toggling thing is. i don't know anything about the menu stuff actually, don't use it in my own instance at all.. but it looks good at a glance to me
@ericblade
I think checkbox + radio status internally works as usual when this.item.click()
is called
(but not updated visually until this.updateChecked()
or this.updateRadioGroup()
is called or submenu is closed and re-opened
And that's because this.item
isn't rendered again unless the whole submenu gets re-rendered)
That was the duplicate checkbox https://github.com/AlexTorresSk/custom-electron-titlebar/blob/04b3e09e0f122ebe5c11db0fcdbb36b8995cd533/src/menu/menuitem.ts#L141-L144
Yes, the checkbox toggled twice would explain #116. I would love to see your changes merged, they are looking great.
That was the duplicate checkbox
I see where you removed one, I was just curious where the other one is, since you said it was getting triggered twice, and that's not in the changelog, since you didn't touch it :-)
The original menuitem actions file isn't even in this git, only in release (You see the problem with repo not having the same version as release ??)
a repo might collect many changes before a release is made...
Above, I was addressing your concern about the src not being in the release, and the lib not being in the src, which is imo, something that should never occur. A repo collecting changes before a release is highly dependent on the maintainers, though. I personally advocate for an automatic release generator that will always package up master branch whenever there's a change and make a release. A lot of people haven't got to setting that sort of thing up though. I haven't even got it close to working the way I'd like it to, on even any of my bigger repos.
Anyway! LGTM, also 👍
Hello everybody.
Thanks guys for always being on the lookout for updates and bugs from the library. I haven't really had time to publish the 3.2.6 changes to npm. On the other hand, when I developed this library, I did not have the complete knowledge of releases, versioning, among others; therefore there is a lib folder which is actually the build folder for the entire project 🤭. As soon as I have time I will dedicate myself to cleaning and debugging the code.
Thanks again for your support.
@AlexTorresSk You should know that this pull request was tested on the 3.2.6, npm release So it should be easy to implement into npm :)
@AlexTorresSk
I ended up fixing more stuff:
Changed radio buttons to dynamically visually update on click (by iterating over all radio buttons in the same radioGroup)
radioGroup is a group of radio buttons in a submenu, possibly start/end with a "separator" -that's the way radio groups originally works in electron
Updated and fixed a typescript compile type error that was somehow missed, sorry about that 😅 (it has been recompiled and tested thoroughly)
Updated example/main.js to include a menu for easy testing using yarn dev
if menu
in titlebar.updateMenu(menu)
is null || undefined
, dispose of menu and exit function to avoid errors
@ericblade My last answer on why the checkbox got updated twice was wrong. this is the actual reason:
checkbox + radio checked status are updated when this.item.click()
is called (behavior of electron.menuItem),
but not updated visually until this.updateChecked()
OR submenu is closed and re-opened
(and that's because this.item isn't rendered again unless the whole submenu gets re-rendered)
I used this fact to enable dynamic updating of "radio" item groups
So CETMenuItem.onClick()
was calling item.click()
(first change) and then item.checked = !item.checked
(second change)
https://github.com/electron/electron/blob/master/lib/browser/api/menu-item.ts#L47-L52
I'll start with saying I love the idea of this lib, but I faced some problems while using it, that I fixed in my program awhile ago But I decided I should probably also share some fixes on the original source.
The Initial Problems:
.menubar-menu-container
CSS propertyoverflow-y
wasn't set tovisible
)checkbox
looked like it didn't do anything (it was settingitem.checked = !item.checked
twice)titlebar.updateMenu(null || undefined)
throws an error but works (dispose of current menu)The Fixes :
9dc885f Set menu-container internal css to
overflow-y: visible;
. fix #1245e17933 Fixes checkbox's being triggered twice. fix #116 (First trigger is in electron/menu-item.ts)
a7cfa0a / 918e8e6 inherit
closeSubmenu()
inSubmenu
class allows submenus to close when their content is clicked That fix items in submenu's not closing on clickda8999c Following the last change, submenu will close only if item type isn't
checkbox
orradio
which allows them to work as before76b0726 Fixes menu roles by emulating the accelerator shortcut buttonDown when menuitem is clicked. fix #133 abit of a hacky way but I think its way better than the ipc method that didn't even work
e4a5df1 Dynamically visually update radio button groups by passing menuContainer to
CETMenuItem
and updating all radio buttons in the menuContainer whenCETMenuItem.click()
is called andtype === radio
0e61412 if
menu
intitlebar.updateMenu(menu)
isnull || undefined
, dispose of menu and exit function to avoid errorsWould love feedback on this if there is any :)
Click to view sample menu template for testing
```javascript const template = [ { label: "Options", submenu: [ { label: "zoomIn", role: "zoomIn" }, { label: "zoomOut", role: "zoomOut" }, { label: "Radio1", type: "radio", checked: true }, { label: "Radio2", type: "radio", }, { label: "Checkbox1", type: "checkbox", checked: true, click: (item) => { console.log("item is checked? "+item.checked); } }, { label: "Checkbox2", type: "checkbox", checked: false, click: (item) => { console.log("item is checked? "+item.checked); } }, { label: "Radio Test", submenu: [ { label: "Sample Checkbox", type: "checkbox", checked: true }, { label: "Radio1", checked: true, type: "radio" }, { label: "Radio2", type: "radio" }, { label: "Radio3", type: "radio" } ] }, { label: "Quit", click: ()=>{app.quit()} }, ] } ]; const menu = Menu.buildFromTemplate(template); Menu.setApplicationMenu(menu); ```Also, why is this git repo not actually the same version as the npm package? (3.2.5 vs 3.2.6) It also has an src folder instead of lib, which means that when cloning the repo you don't have access to all files and running
dev
will result in an error because oflib
folder missing which is abit weird 😅