-
Notifications
You must be signed in to change notification settings - Fork 501
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
fix: Dragging and dropping files in to OSX dock icon #2191
Conversation
I made this PR as a draft before getting it working, so I can save all my notes here and get feedback on best approach, ie: how to handle the cargo bundle not supporting it. Can we just fork that or something, and merge one of those PR's? or is there a better approach |
I think we are missing some information here. What does cargo bundle not support? And which PRs are you talking about? |
Basically in order to have drag and drop support on OSX, it looks like in the https://stackoverflow.com/a/14527463/794481 I checked the bundled I tested this myself by adding the keys that are in Given that this Info.plist isn't anywhere in the repo, I am assuming it's coming from here at build time: https://github.com/neovide/neovide/blob/main/Cargo.toml#L106-L118 I am assuming https://github.com/burtonageo/cargo-bundle?tab=readme-ov-file#general-settings ^ In their docs, they only support a small variety of keys that can be added. There's several complaints in all the Github issues about how he isn't maintaining it with new types, and theres months old open PR's where he's also not adding new types. Heres an example of a PR adding a key: burtonageo/cargo-bundle#123 That one doesn't help us just showing that there's no actual way to just write your own keys/values which seems crazy to me. I also could be missing something obvious here... but otherwise I don't know how we can write the proper keys to the Info.plist, as full MacOS support requires a lot of identifiers which are missing, for example all the right click "open with" context menus, setting a program as a default when opening, etc, are all controlled via that. |
^ Other people wanting keys added, and him saying he doesn't have time to work on it anymore |
Ah, I see. I will search around if there are some alternatives to cargo bundle. The status of the projects says "very early alpha", and if the maintainer doesn't have time to work on it, then we have to look for alternatives. |
I only did a rudimentary 5 mins of googling so this may not end up being any good, but maybe "tauri-bundler" which looks to be based on cargo-bundler It looks like tauri is a full build system which wouldn't be desired, but maybe tauri-bundler can just be used separately Im trying to see though if it supports arbitrary keys... still searching |
I checked Alacritty and they seem to be doing it manually with a makefile and And with the icons and plist included in the repository https://github.com/alacritty/alacritty/tree/master/extra/osx/Alacritty.app/Contents So, I guess that's one way to go. But not sure if it's the best. I will do more searching later. |
It looks like it supports it through However i did see this: https://tauri.app/v1/guides/building/macos
It looks like it might support other OS's as well (maybe not related, I'm not sure how linux bundles work) |
But yes - whatever you think. This bit is outside my wheelhouse haha |
Maybe we could use the tool from MacVim https://github.com/macvim-dev/macvim/tree/master/src/MacVim/create-dmg |
That might be a great idea, I can certainly say MacVim has dialed in the native Mac experience, that's for sure. It's almost too much how they're dialed in 🤣 For example, they're basically in every single right click menu, context menu, top-bar menu. Not that we need all that but good to know it would be supported. |
I think it's in our best interest to move away from cargo-bundle for macOS at the least. Tauri builder (https://github.com/tauri-apps/tauri/tree/dev/tooling/bundler) at the least has not just support for If everything looks good, I'll whip up a PR to move the build process over to tauri-builder. Hopefully that should make this PR a bit easier to implement. |
I'm good wil tauri bundler but I'll defer to @fredizzimo - it looks like there's slight improvements on Linux + Windows as well, maybe some other issues would be fixed by that (ie, drag and drop on other OS's, etc) |
I would personally go with the MacVim's tool, since it seems more generic, while the tauri bundler seems specialized for their usecase of packaging tauri applications. I'm also not sure if the cargo.toml support is there in the tauri bundler anymore, they mentioned that they refactored into a library, and I can only see the library documentation. So if the support is there, it seems to be undocumented. And their CLI tool only seem to be able to build tauri applications. But if @shaunsingh, can get that to work, and you figure out how to enable the plist properies you need, then it should be fine. But for example it looks like you have to pass the file associations in a settings struct to enable what you want https://github.com/tauri-apps/tauri/blob/6892a8cbc1df39c48c3b83f3700b873cbad086ed/tooling/bundler/src/bundle/macos/app.rs#L221 |
Ah very good points, well I'm good with Macvim's obviously as well too, it does what we need in this issue and likely others for sure |
For that one, I think you could try it yourself, you just need to build a release build, and give the right parameters the path to the executable, the path to the icons and so on. |
Awesome, I might have some questions but I'll give it a go |
@fredizzimo this may be a dumb question but will this be able to be automated? It says it requires Mac OSX and I thought all your build stuff happens in github https://github.com/macvim-dev/macvim/tree/master/src/MacVim/create-dmg#requirements |
Yes the macOS CI runs on this https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md |
I also just noticed that the official repository for create-dmg is https://github.com/create-dmg/create-dmg |
Awesome, I'm workin on it already I'll let you know what i come up with. |
Btw, if I understand it correctly,this is the source folder macvim use, but you only need a few things from there, for example the plist with our own modifications |
Actually here's the command they use https://github.com/macvim-dev/macvim/blob/1a8aef0b01ce606f17115b3e71d4864f0640d1b2/src/Makefile#L3679-L3694 |
Sorry, after studying more, it seems to be more complex than that 😢 The plist needs to be compiled into the executable https://github.com/macvim-dev/macvim/blob/1a8aef0b01ce606f17115b3e71d4864f0640d1b2/src/MacVim/MacVim_xcode8.xcodeproj/project.pbxproj#L261 And that's probably partly what those bundle tools does |
Yes I was kind of coming to that conclusion at the same time, it also seems like it's just for dmg's after you already have the .app built |
Hm. based on the Alacritty makefile, I don't see anything special, it copies the executable to the same folder as the plist and renames it to Alacritty.app. So the Alacritty.app goes into a folder with the following structure https://github.com/alacritty/alacritty/tree/3d7d81c8482eb9465763020a397290765b70b541/extra/osx/Alacritty.app/Contents Then it creates the dmg from that https://github.com/alacritty/alacritty/blob/3d7d81c8482eb9465763020a397290765b70b541/Makefile |
Interesting, well I can make a rough version in a single file, and I will try to cobble it together and then someone perhaps could refine it, but ill get the core parts of it working first, if you think thats good approach |
Just an FYI -- this compiles, but does not deliver said functionality on my box as currently authored.
|
Ideally, a change that would enable document handling for macOS might be upstreamed in cargo-bundle (e.g. burtonageo/cargo-bundle#174). |
@abhillman I'm not an OSX developer so I dont have the skills to find a way for Neovide to hook into the separate event loop. If you read the comments you will see theres multiple event loops that need to be handled, there were some possible ways with fruitbasket, etc, but I couldn't get them to work. I have already done a lot of the heavy lifting which was a PRECURSOR to this which was adding an installer DMG and supporting the necessary But as far as hooking into that event, I'm at a loss. Which is a bummer because I'd really love this functionality. I work with dozens of CSV's every day on my desktop and i have no easy way to open them. I have to keep macvim on there to use it for that use case... which sux |
Also,if you read the first messages, you will find the reason why we decided to move away from The project status is
And that combined with very sporadic development and useful pull requests getting left open without any comments. |
^ yes that too. TBH it would be really cool to ship this issue eventually as I did spend a lot of time making a nice installer etc, which separates the good OSX from the chaff heres also what it is stuck on it seems: Would definitely be cool to find another way though, as who knows how far away that is |
Although |
@abhillman i doubt cargo-bundle will work any time soon given the sheer amount of new keys required, unless they specify some way to allow arbitrary key entry. You can see there are a huge amount of new keys here that added: |
Let's put aside the <key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array> In addition to this piece and other logistics, what remains is registering a message handler for the OS. |
Here's a sketch of how to bring this much of the rest of the way. Background
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames {
NSLog(@"Files dragged on: %@", fileNames);
}
Sketch of the solution use std::ffi::CString;
use objc::runtime::{
objc_getClass
};
unsafe fn add_url_handler() {
let class_name = CString::new("WinitApplicationDelegate").expect("CString::new failed");
let res = objc_getClass(class_name.as_ptr());
// TODO: use objc::runtime::class_addMethod to add a `application:openFiles:` method to the application delegate via the Objective-C Runtime
// TODO: tell neovim to open the file
} |
For a simple example demonstrating fetching winit's use std::ffi::CString;
use winit::{
event_loop::EventLoop,
window::WindowBuilder
};
use objc::runtime::{
objc_getClass
};
use winit::event::Event;
unsafe fn add_url_handler() {
let class_name = CString::new("WinitApplicationDelegate").expect("CString::new failed");
let res = objc_getClass(class_name.as_ptr());
// Prints a memory address like 0x6000019d85a0
println!("{:?}", res);
}
fn main() {
let event_loop = EventLoop::new().unwrap();
let _window = WindowBuilder::new().build(&event_loop).unwrap();
let loop_proxy = event_loop.create_proxy();
loop_proxy.send_event(()).unwrap();
event_loop.run(|event, target| {
match event {
Event::UserEvent(_) => {
// As-written, this will only be called once. It is called
// due to the `loop_proxy.send_event(())` call above.
unsafe { add_url_handler() }
}
_ => {}
}
}).expect("TODO: panic message");
} In order to use it, one would create a cargo project with the proper dependencies, drop the above source into |
@abhillman awesome! regarding your Info.plist, the only reason all the other keys are required if I remember right is that OSX requires that you explicitly specify every single filetype. Wildcard @fredizzimo what do you think of that above? I don't really know rust well enough. That would be awesome if this works tho Is there a way 2 people can collaborate on a PR so he can actually commit that to my PR? |
I don't really know what a good approach is, perhaps it would be worth asking the Winit team what their long-term vision is, and if this could be a good short-term workaround? @9mm, regarding collaboration, you can either give the other person write permissions to your branch, or they can send a PR to your fork targeting your branch, which you can then merge. But you have to be careful with re-basing if you are co-operating on the same branch, it's the safest to always use merges, they will be cleaned up anyway when we finally squash the PR. |
I sort of implemented this in polachok@9802ab3 with some limitations:
|
Awesome! I will check it out soon 💯 |
It actually works if I disable forking. Also, this makes "open with>Neovide" menu in finder work. I guess the "openFiles:" request is sent to the original process. We should probably make no-fork the default if not running from tty, using atty crate. What do you think? |
Interesting, thats def a question for @fredizzimo Nice work this is super exciting. This is the main feature left thats painful, so Im really stoked! |
For the forking, we have this issue: TLDR; |
Just opened a draft PR for this: #2395 |
In my testing, the following addition to <key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>All Text Files</string>
<key>LSItemContentTypes</key>
<array>
<string>public.text</string>
</array>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array> I'm no expert, but ChatGPT says the |
I guess this can be closed now? |
I believe so! |
What kind of change does this PR introduce?
Currently when a file is dragged over the Neovide dock icon, it doesn't change appearance (indicating it doesn't accept drag and drop). Furthermore, when the file is dragged over (after allowing extensions) it still didn't accept the drag event so is intending to be fixed too.
There are some other issues that could potentially be fixed as well if someone with Windows wants to help. It's possible that drag and dropping on windows doesn't work for a similar reason?
I actually think maybe this is related too, as thats the purpose of the massive CF type bundle is to say every type thats supported as an "Editor" role: #1682
Did this PR introduce a breaking change?