parro-it / electron-localshortcut

Add keyboard shortcuts locally to a BrowserWindow instance, without using a Menu
MIT License
422 stars 38 forks source link

Uncaught Exception: TypeError: str.split is not a function #59

Closed speedpacer closed 5 years ago

speedpacer commented 6 years ago

I just installed and configured as instructed and I get this error when I launch electron.

This a new project, started with create-react-app and then adding electron, the standard main.js file from electron-quick-start, and the few necessary changes to package.json. I also added a .env file with BROWSER=none and a different port and I'm using concurrently and wait-on to start react in the electron window.

Could one of these things be interfering?

cutterbl commented 6 years ago

Having the exact same issue. In the beginning I defined each of my accelarators seperately, but I had a few that were duplicate key registrations, which it did not like. So, following the docs, I turned these into an array of accelerators in the register() method. When I call register() with an array of accelerators it hits the _checkAccelerator() call it goes all fubar. Looking at the source code I tried a quick test to check the accelerator argument type and process it differently

if (Array.isArray(accelerator)) {
        accelerator.forEach(key => {
            _checkAccelerator(key);
        });
    } else {
    _checkAccelerator(accelerator);
  }

This got it past that error, but then others followed once it tried to pass the array into the toKeyEvent(). I tried to code around that too, but then I started getting all kinds of error in the app itself on load.

parro-it commented 6 years ago

Could you check the version actually in master to see if it solve the problem? If you use an invalid shortcut chord, toy should see a warning in the console...

SilencerWeb commented 6 years ago

@parro-it, it happens when you are trying to pass an array of shortcuts. For example:

  electronLocalshortcut.register(window, ['Cmd+S', 'Ctrl+S'], () => {
    window.webContents.send('save-card');
  });

electron-localshortcut v3.1.0 electron v3.0.2 macOS v10.13.6

parro-it commented 5 years ago

Should be solved by https://github.com/parro-it/electron-localshortcut/pull/50 I'll publish a new release soon.