-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add the ability to disable/enable the context menu #93
Add the ability to disable/enable the context menu #93
Conversation
@sindresorhus I also have updated the fixture.js and html files, but I'm not sure whether I did it "correctly", so it's parked on a separate branch. See loopmode@26f36c4 It adds a checkbox to enable or disable the context menu, but for that to work while keeping it simple, I moved the entire logic our of the js and into the html file. I can provide another PR for that. |
|
||
const dispose = () => { | ||
disposables.forEach(dispose => dispose()); | ||
isDisposed = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a boolean, just empty the array and check the length. You should empty the array regardless as you don't want to hold onto those forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I believe it would cause a chicken/egg problem and we'd never create the menu in the first place in https://github.com/loopmode/electron-context-menu/blob/feature/dispose-function/index.js#L258-L265
Looking into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it's not that easy.
Avoiding the flag requires either a completely different approach, or several more changes that seem unnecessarily complex.
It's really about bailing out in certain deferred edge cases, and the significant piece of information of the flag is: "No need to create the menu anymore, the callsite already disposed it".
I already tried a couple variants, and I still believe the flag is the best solution.
Should let go of the references despite of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array length reset
This looks great :) You also need to add it to https://github.com/sindresorhus/electron-context-menu/blob/master/index.d.ts |
I think you should create a new fixture just for this. It's totally fine that it's in the HTML file. It can be as just |
Great, will do that! |
Bump :) |
# Conflicts: # package.json
# Conflicts: # package.json
# Conflicts: # index.js
Hey @sindresorhus So.. I did quite some things extra here, hope it doesn't make accepting the PR too much of a problem?
Ah, and I added couple of cleanup commits to pass through your travis pipeline. |
I'm not interested in having this. |
👍 |
readme.md
Outdated
@@ -52,10 +52,21 @@ let mainWindow; | |||
})(); | |||
``` | |||
|
|||
Note that the return value of `contextMenu()` is a dispose function: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readme and index.d.ts should be in sync documentation-wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of differences, as I didn't know about the sync aspect. Will adjust.
Actually, there's even a react hook example in index.d.ts that is not in readme.
I will remove that altogether as it feels out of scope here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readme and index.d.ts should be in sync documentation-wise.
Synced
index.js
Outdated
label: 'No Guesses Found', | ||
visible: hasText && props.misspelledWord, | ||
enabled: false | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do unrelated changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry. Related to prettierrc - will disable auto-formatting in my editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do unrelated changes.
Reverted
removed
Synced
Reverted |
package.json
Outdated
@@ -10,10 +10,12 @@ | |||
"email": "sindresorhus@gmail.com", | |||
"url": "https://sindresorhus.com" | |||
}, | |||
"contributors": ["Jovica Aleksic <jovica.aleksic@loopmode.de>"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't use this field. It's not actually used anywhere and it's creates inequality with contributors that doesn't add themselves there. I prefer to keep it simple and just not use it. Hope you understand :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely no problem! :)
Thanks :) |
This PR adds a dispose function and fixes #82 and fixes #84.
The implementation is such that the
contextMenu()
return value is a function that will remove the registered event listeners.