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

Neovide.app seems non-standard boot method? #1987

Closed
9mm opened this issue Aug 20, 2023 · 13 comments · Fixed by #2189
Closed

Neovide.app seems non-standard boot method? #1987

9mm opened this issue Aug 20, 2023 · 13 comments · Fixed by #2189
Labels
bug Something isn't working

Comments

@9mm
Copy link
Contributor

9mm commented Aug 20, 2023

Describe the bug

First, sorry if this issue already exists. Despite searching for some time, the last few issues I've made have all been duplicates.

Here is similar stuff here, but no one seems to mention the 'double open' thing (see video in second comment of issue)

Something about the way Neovide.app works on OSX seems non-standard, although I don't know what it is.

First, all I'm trying to do is have a Neovide icon on my dock. 99% of the time I open neovide from terminal from a custom shell script, but there are cases where I want to drag some file into the dock icon.

For MacVim, I solved this by creating an automator script with the following:

open -a /opt/homebrew/opt/macvim/MacVim.app "$@"
image

Neovide comes with a cask, so the first thing I did was make an exact duplicate of Macvim automator:

open -a /Applications/Neovide.app "$@"

There are 2 problems with this though:

  1. it doesnt behave the same as macvim because when this automator script is dragged to the dock, and clicked, it creates a whole separate launch of the app, its not the same process as what automator opened for some reason. This behavior is quite strange.
  2. even if it DID work, I don't think I would be able to pass --multigrid and --frame buttonless, but this is beside the point

The next thing I tried was dragging Neovide.app from /Applications onto my dock.

This creates other issues:

  1. The app doesn't accept dragging anything to it as input (such as a file). Notice dragging something into the icon in macvim works fine (or any other mac app that accepts opening a file). For Neovide the icon doesn't change visual appearance, indicating it doesnt accept input
image
  1. The 2nd problem is, if I simply click neovide icon on the dock, it actually animates twice very quickly in succession, as if its booting TWICE. Perhaps this is part of the problem why it doesn't behave the same as Macvim? I've never seen an app do this, so that tells me something non-standard is happening with how neovide is choosing to boot the app on OSX.

Ultimately.... all of these things are not technically the problem i'm facing, they're more of roadblocks along the way of my ultimate goal, which is this:

My goal is to have a Neovide icon in my dock that I can drag files into, and which passes in the multigrid and buttonless options in at the same time.

Here is a binary n I made which lets me boot neovim from terminal, and works great:

#!/bin/bash
exec neovide --multigrid --frame buttonless "$@" > /dev/null 2>&1
exit $?

As an added bonus I would love it if it also passes: -- -c 'cd ~/Desktop' so that telescope doesnt try to index half a million files every time I open neovide without a path, but I would figure that out myself once I can at least get the above to work.

To Reproduce

  1. Drag the icon from /Applications to your dock, and click it. Notice the weird double boot behavior
  2. Also notice you cannot drag anything into it
  3. If you want to see the automator script, you can paste the code above into a new automator and go to Export, now drag that to the dock and click it.

Expected behavior

Of all the things I wrote above, there's a lot going on and some of the things I'm unsure of. What I am certain of though is an app dragged to the dock should not try to boot twice in quick succession. That I'm sure of.

The other thing I'm pretty sure of is that if an app Opens by clicking its icon, it shouldnt be doing fancy wizardry in the background where the app I just clicked is closed, and somehow spawns some secondary app which is separate from the app I clicked

Desktop (please complete the following information):

  • OS: 13.5 (22G74)
  • Neovide Version: neovide 0.11.1
  • Neovim Version:

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

@9mm 9mm added the bug Something isn't working label Aug 20, 2023
@MultisampledNight
Copy link
Contributor

MultisampledNight commented Aug 20, 2023

Hi, thanks for reporting! I can't say anything about the larger picture this issue tries to cover since I'm not on any macOS platform, but about passing --multigrid and --frame buttonless, you could check out the config file or environment variables (the ones with $ (dollar signs)) instead.

@9mm
Copy link
Contributor Author

9mm commented Aug 20, 2023

@MultisampledNight ! Excellent, thank you! That helps a ton to get closer

@9mm
Copy link
Contributor Author

9mm commented Aug 20, 2023

I recorded a video of what it does. Watch the animation when each app boots.

Screen.Recording.2023-08-20.at.3.18.50.PM.mov

@codeitlikemiley
Copy link

Try my solution:

#1984

it would solve your issue on telescope indexing the root directory.

also would allow you to bind keys / remap especially CMD + h , if your using it like i do...

@9mm

@9mm
Copy link
Contributor Author

9mm commented Aug 21, 2023

@codeitlikemiley interesting, I read it. I have solved the indexing in a similar way. CMD+H works fine for me interestingly enough. I just remapped all the command keys manually like this:

  -- command mapping
  vim.keymap.set({ 'i', 'n' }, '<D-a>', '<ESC>ggVG')                              -- select all
  vim.keymap.set({ 'i', 'n' }, '<D-w>', function() close_tab() end)               -- close tab
  vim.keymap.set({ 'i', 'n' }, '<D-[>', function() vim.cmd('BufferPrevious') end) -- previous tab
  vim.keymap.set({ 'i', 'n' }, '<D-]>', function() vim.cmd('BufferNext') end)     -- next tab
  vim.keymap.set('i', '<D-t>', '<C-o>:tabnew<CR><ESC>')                           -- new tab (insert)
  vim.keymap.set('n', '<D-t>', ':tabnew<CR>')                                     -- new tab (insert)
  vim.keymap.set('i', '<D-s>', '<C-o>:w<CR>')                                     -- save (insert)
  vim.keymap.set('n', '<D-s>', ':w<CR>')                                          -- save (normal)
  vim.keymap.set('x', '<D-x>', '"+d')                                             -- cut
  vim.keymap.set('x', '<D-c>', '"+y')                                             -- copy
  vim.keymap.set('i', '<D-v>', '<C-r><C-o>+')                                     -- paste (insert)
  vim.keymap.set('n', '<D-v>', 'i<C-r><C-o>+<ESC>l')                              -- paste (normal)
  vim.keymap.set('x', '<D-v>', '"+P')                                             -- paste (visual)
  vim.keymap.set('c', '<D-v>', '<C-r>+')                                          -- paste (command)
  -- vim.keymap.set('n', '<D-q>', ':q<CR>')                                          -- quit

The greater problem I have though is that Neovide.app when launched immediately terminates itself and launches ANOTHER process or something.

Did you notice that?

To see it, go to where Neovide.app is located, probably somewhere like: /opt/homebrew/Cellar/neovide/HEAD-d6d65e3/Neovide.app. Now double click it. You will see the app start to launch, after about 50ms it will abort and then launch a second time... as if the process that started exited after launching a whole separate process.

Now, go to terminal and type neovide and when this is the entry point, now Neovide.app launches perfectly.

So in other words, launching Neovide.app as an app somehow is broken, and that's very common to deal with the .app version in OSX obviously, for example ... putting things in the dock

I wish I knew what it was doing to try and find ways to work around it, but I don't know enough about OSX development.

Basically I want Neovide to appear in the dock, but I can't create a 'launcher' via automator or whatever, because if I drag that to the dock, the launcher simply launches Neovide.app as a whole separate dock icon.

@MultisampledNight
Copy link
Contributor

as if the process that started exited after launching a whole separate process

That's exactly what happens by default through forking. You can disable that through the --nofork argument, which doesn't have an environment variable equivalent (yet, would be easy to add in src/cmd_line.rs).

@9mm
Copy link
Contributor Author

9mm commented Aug 21, 2023

Ah! So I knew about that option the whole time but I didn't think to pass that via --args to Neovide.app... let me try some stuff with this:

open -n /opt/homebrew/Cellar/neovide/HEAD-d6d65e3/Neovide.app --args --nofork -- -c 'cd ~/Desktop'

@codeitlikemiley
Copy link

My Setup never terminate or re-launch, yours is a very weird behavior....

my only suggestion is try to re-install the app just download it directly on the neovide.dev

https://github.com/neovide/neovide/releases/latest/download/Neovide.dmg.zip

drag it to /Applications

Also i never open Neovide.app by itself by clicking it , i use the alias ,since opening by clicking it would just open in root folder and empty file.

The only way for you to know why your set up crash is to add the --log flagged ...

Then figure out a way why that issue is happening, might be an issue on ENV var / PATH missing not loaded...

try to launch using the cli neovide , no alias with --log....

it would dump some .log files and that might able to pin point what causes your set up to crash.

@9mm
Copy link
Contributor Author

9mm commented Aug 21, 2023

I don't think its actually crashing, or even if anything is wrong.

What happens if you drag the file from /applications to your dock, and click it from your dock. Do you notice the issue I mention? If you click from applications its obscured for some reason, which actually was a bit of an epiphany. It occured to me that for things to be on the dock Mac has to actually know what process they are so they can show if they're open or not, whereas things in the application folder it does not. I observed while doing this, things behave differently when they're in the dock.

Im curious though if you drag to the dock and click it, it looks the same as the video I put above.

Btw this is how I sorted out the home folder thing, similar but different. Maybe not the best, but I'm not a shell expert

#!/bin/bash

# to avoid indexing 500,000 files ~ use the following logic:
# - if no arguments are provided and the current directory is ~, set ~/Desktop to working directory
# - if no arguments are provided and the current directory is not ~, open neovim normally
# - if a directory is provided as an argument, set that working directory
# - if a file is provided as an argument, open that file directly
#
# vim uses the cwd of the process to determine the working directory of vim. This is what
# happens when you pass no flags. To override this, we need to use -c to set :cd ourself

export NEOVIDE_MULTIGRID=true
export NEOVIDE_FRAME=buttonless

current_dir=$(pwd)

if [ -z "$1" ]; then
  if [ "$current_dir" = "$HOME" ]; then
    exec neovide -- -c 'cd ~/Desktop' > /dev/null 2>&1
  else
    exec neovide > /dev/null 2>&1
  fi
else
  if [ -d "$1" ]; then
    exec neovide -- -c "cd $1" > /dev/null 2>&1
  else
    exec neovide "$@" > /dev/null 2>&1
  fi
fi

@9mm
Copy link
Contributor Author

9mm commented Aug 21, 2023

@MultisampledNight thanks, i'll have a look later to see if I can add it to the config, although perhaps not as I dont want to add mental overhead for ppl. I've mostly got everything with migrating my entire config over except just a few misc things... I may go away for awhile and come back with fresh brain to try to sort out the last 3% of straggling things to figure out... mostly boiling down to this issue, and restoring the window size properly from the config file, which I think is blocked by the render loop issue

@codeitlikemiley
Copy link

dont know why would you hard code ~/Desktop

the usual behaviour should be if you open a file it would get that file directory as the cwd.

if you open a directory that itself would be the cwd

neovide() {
	local arg="${1:-.}"
	local neovide_cwd
	local file

	if [[ -d "$arg" ]]; then
		neovide_cwd="$(realpath "${arg}")"
		file="$neovide_cwd"
	else
		file="$(realpath "${arg}")"
		neovide_cwd="$(dirname "${file}")"
	fi

	open -a Neovide.app --args "$file" --multigrid --frame buttonless -- -c "cd $neovide_cwd"
}

@9mm
Copy link
Contributor Author

9mm commented Aug 21, 2023

I hardcode desktop because I often use it as a scratch pad for current project, I do lots of file opts. there is 100% chance that if im opening vim from my home folder (which is my default terminal) then i want to do sort of experimental work not in any project, so in this case i just always use my desktop. it just suits all the type of work i do

I do like your version as well though, it basically just makes the CWD match the input arg, correct?

So then from the outside all that needs to happen is passing in a path or file and it doesn't matter

edit: Nevermind I see you rewrote my bash script, thanks! it does look a bit cleaner

@codeitlikemiley
Copy link

also stop using the neovide cli , use the Neovide.app , coz the Neovide.app have the macOS info.plist file ,
and when you open Neovide.app that points to the neovide cli as well .... most of the MacOS Features are lose the moment you use the stand alone cli...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants