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

minimize on alt+f4 (#1556) #1808

Closed
wants to merge 0 commits into from
Closed

Conversation

gorgulenkozxc
Copy link
Contributor

@gorgulenkozxc gorgulenkozxc commented Oct 16, 2023

resolve #1556

@Vendicated
Copy link
Owner

hi! thanks for the contribution but this is a bad way to solve this problem for various reasons

  • linux and mac use a different shortcut than alt f4
  • the current code reads and parses the settings on every single key stroke. this is very inefficient. it would be much better to instead disable the electron keybinds responsible for it

@gorgulenkozxc
Copy link
Contributor Author

gorgulenkozxc commented Oct 18, 2023

hi! thanks for the contribution but this is a bad way to solve this problem for various reasons

* linux and mac use a different shortcut than alt f4

* the current code reads and parses the settings on every single key stroke. this is very inefficient. it would be much better to instead disable the electron keybinds responsible for it

hello, thank you for taking the time to write a complete response!

indeed, I should've been more aware of the existing code and register the key combination according to the OS

as you suggested, I tried to use the registration of the shortcut via the electron.js native ways: globalShortcut and submenu. here are the pieces of code I tried to solve the problem with:
index.ts in main

globalShortcut.register("Alt+F4", () => {
    app.hide();
});

patcher.ts, analogy with winCtrlQ

const originalBuild = Menu.buildFromTemplate;
Menu.buildFromTemplate = function (template) {
    if (template[0]?.label === "&File") {
        const { submenu } = template[0];
        if (Array.isArray(submenu)) {
            submenu.push({
                label: "Alt+F4's supress",
                visible: false,
                acceleratorWorksWhenHidden: true,
                accelerator: "Alt+F4",
                click: () => { }
            });
        }
    }
    return originalBuild.call(this, template);
};

none of the methods was able to prevent the application from being completely closed by pressing alt+f4

I also don't quite get the statement «the current code reads and parses the settings on every single key stroke» and consider that the settings will be read only if alt and F4 keys are pressed at the same time

@Vendicated
Copy link
Owner

Vendicated commented Jan 6, 2024

both of your code snippets should work, however you also need to prevent the default action. both those click handlers should obtain the event as first argument. calling event.preventDefault() will prevent it

I also don't quite get the statement «the current code reads and parses the settings on every single key stroke» and consider that the settings will be read only if alt and F4 keys are pressed at the same time

disregard this, i don't know what i was saying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Option: Alt + F4 minimize to tray instead of closing.
2 participants