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

Implement support for opening files. #276

Closed
wants to merge 4 commits into from
Closed

Implement support for opening files. #276

wants to merge 4 commits into from

Conversation

kirb
Copy link

@kirb kirb commented Jul 19, 2016

Nice project! Wanted to contribute a quick little feature.

This implements the open-file event on app, which is fired when one of the following happens:

  • A file is launched (ie, double-click in Finder), and the file’s type is set to be handled by HyperTerm.
  • A file is dropped onto the dock icon.
  • The user runs open -b co.zeit.hyperterm blah.sh, or equivalent in Cocoa. (This adds support with my own TermHere.)

The implementation works like this:

  1. The last used window is tracked, based on the last one spawned or focused (8a4bbd1).
  2. When the event is fired, if a window exists, we send an open file command to it; otherwise we create a new window and send it to that (a495b3f).
  3. The path given is escaped to be used as a shell argument (8db2ad8). If it’s a directory, prepend cd.
  4. Write the command to the TTY.

Bugs – I’m not too sure how these should be fixed:

  • When closing a window, with other windows open but minimised, lastWindow will be undefined as another window hasn’t gained focus. This also assumes the window manager will give focus to another window from the same app, which I don’t think is the case on Windows.
  • When opening a new window, two tabs are created. The first is the default one created automatically; the second is the one created by the open-file event.

@thomaslindstrom
Copy link

A file is dropped onto the dock icon.

Yuss! 👍

@erikng
Copy link

erikng commented Jul 19, 2016

The user runs open -b co.zeit.hyperterm blah.sh, or equivalent in Cocoa. (This adds support with my own TermHere.)

Yes!

@lordgiotto
Copy link
Contributor

Hi, great additions, I'm working exactly on the same fix :)

There are still a couple of problem to handle:

  • Without a Info.plist modification, you'll not be able to drop file onto the dock icon (I can make a pull request for it)
  • If you modify Info.plist and try to drop a file on the dock icon when the app is not running, open file not works. I guess it's because it occurs in an earlier event ('will-finish-launching'), even before CreateWindow is declared inside 'ready' event.

@kirb
Copy link
Author

kirb commented Jul 20, 2016

As far as I'm aware open-file is fired very early, before even ready. So in fact, this should be accounting for that (make note of the file path and fire the logic in createWindow). Will work on that.

@lordgiotto
Copy link
Contributor

@kirb, starting from this pull request I've created another pull request (#329) that fixes all the problem we talked about. I wanted to make a pull request to your repo, to merge our PR, but i rebased your code on the last hyperterm master (in order to avoid merge conflicts) and the PR to your repo results in a mess.

I hope you're not upset if I create a new PR, I gave you the attribution for your commits and your idea :)

@kirb
Copy link
Author

kirb commented Jul 21, 2016

No worries. It's a group effort after all!

@rauchg
Copy link
Member

rauchg commented Jul 21, 2016

Closing this in favor of @lordgiotto. Thank you @kirb!

@rauchg rauchg closed this Jul 21, 2016
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.

5 participants