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

Add Cli launching, file associations, shortcut generation #127

Merged
merged 50 commits into from
Aug 21, 2024

Conversation

zeptofine
Copy link
Collaborator

@zeptofine zeptofine commented Aug 3, 2024

Add Cli launching, file associations, shortcut generation
This adds methods to launch different versions of blender from the commandline, and using those methods, also adds file associations via .desktop files on linux and registry keys on windows.

New settings

image

The Create Shortcut button makes a popup dialog to choose where to make the shortcut. Since I started this branch in Linux, I naturally started with making the shortcut option first because I had assumed it would be as similar on windows

(Un)Register File Association options are only available on Windows, as on Linux the shortcut allows the same thing via .desktop application mimetypes.

Launch timer describes how much time you have before a blendfile is opened in the selected blender build. This is only active if there is a good initial guess on which build the user wants to run.

File Association launching

image

This opens when you launch .blend files with Blender Launcher. Every option here controls a query that is sent to a matcher that matches every build available to it.

In the list, you can double-click builds to insert the build information to the fields. It's a good choice to quickly choose a specific build.

That prompt Save query for 4.2.0 blendfiles will save the current configuration to the settings, and will fill in the fields for every blendfile you launch that was made in 4.2.0. It can remember the configuration for every minor version (2.79, 3.0, 3.1, 4.0, 4.2, etc.)

You can use characters ^, *, - to control relevancy.

  • ^ compares the newest/largest version.
  • * lets anything pass-- it does nothing.
  • - compares the oldest/smallest version.
    the characters ^ and - work on all pieces of the version selection, and the date selection.

In my experience, date comparison using hard datetime values are really unreliable, so I only expose the temporal and wildcard options for the date.

The Launch button is enabled when there is only one possible solution to the version query.

Related to #81

@zeptofine zeptofine added the enhancement New feature or request label Aug 3, 2024
@Victor-IX
Copy link
Owner

I have this error when clicking Create Shortcut and Cancel

[2024-08-03 23:35:35,577:ERROR] Windows - Blender Launcher 2.2.0
Traceback (most recent call last):
  File "h:\Projects\Blender-Launcher-V2\source\widgets\settings_window\general_tab.py", line 237, in create_shortcut
    generate_program_shortcut(Path(file_place[0]))
  File "h:\Projects\Blender-Launcher-V2\source\modules\shortcut.py", line 179, in generate_program_shortcut
    dest = destination.with_suffix(".lnk").as_posix()
  File "C:\Python\Python39\lib\pathlib.py", line 903, in with_suffix
    raise ValueError("%r has an empty name" % (self,))
ValueError: WindowsPath('.') has an empty name

@Victor-IX
Copy link
Owner

On Windows, is the Create Shortcut option only creating a shortcut of the program?
When I launch the shortcut, it launches the Blender Launcher but with a Command Prompt window. I don't know if this is intended.

When I did the file association registration, Windows asked me to choose a program to launch the Blender file on the first launch, and instead of the Blender Launcher, it was Python with the Python icon.
Maybe rebooting Windows will fix the name and icon, but it would be best to force the use of the Blender Launcher as the default program.

Also, .blend1 files use the Blender Launcher by default, and I didn't get the window popup asking me which program I would like to use to launch it. Maybe because I never assigned a default program for the .blend1 file type.

@zeptofine
Copy link
Collaborator Author

zeptofine commented Aug 4, 2024

I have this error when clicking Create Shortcut and Cancel

Oh oops, that's an easy fix. I'll do that rn

When I launch the shortcut, it launches the Blender Launcher but with a Command Prompt window. I don't know if this is intended.

Are you creating the shortcut outside of a bundled executable? If so it's likely python needs a terminal for whatever reason. For me at least, no terminal shows up when I create a shortcut using the frozen executable.

When I did the file association registration, Windows asked me to choose a program to launch the Blender file on the first launch, and instead of the Blender Launcher, it was Python with the Python icon.

This is also a symptom of running it directly from Python, from my testing

@Victor-IX
Copy link
Owner

I forgot I had to use the package version...

It would be nice to have the option to download the corresponding version of Blender if it's missing from the library. This might be tricky to implement...

Also, what do you think about having no timer if the user inputs 0 for the launch timer?

image

@zeptofine
Copy link
Collaborator Author

It would be nice to have the option to download the corresponding version of Blender if it's missing from the library. This might be tricky to implement...

It may be a little tricky, but that's what the version matching system is great at :D

Also, what do you think about having no timer if the user inputs 0 for the launch timer?

Yeah, that could be done. Does that mean it won't launch automatically or it will launch as soon as possible?
Maybe:

  • 0: launches as soon as possible
  • -1: does not launch automatically

@Victor-IX
Copy link
Owner

Oh, okay, I misunderstood how this was working. So yes, the old button description makes more sense. I just feel like it's a bit too technical for a typical user; they might not understand what the button does. Some people might not know what a query is.

Lambda users?

Ah, this is not used in English 😅. It's a French expression for "typical user".

@zeptofine
Copy link
Collaborator Author

zeptofine commented Aug 5, 2024

I just feel like it's a bit too technical for a typical user; they might not understand what the button does.

That's true, it could still be rethought

Ah, this is not used in English 😅. It's a French expression for "typical user".

Oh that makes sense lol. I only know lambda in the Python meaning and sort of the math meaning

There are benefits for both interpretations, but there are also cons

Saving the search query for individual files mean if you want to run a specific version of 4.2.0 on a file made in version 4.2.0, you can set it and not have to worry. But on the other hand, every file would have to be configured, and we would have a problem with how to actually save that data; would we open the blendfile and save it somewhere in scene data? would we keep a dictionary of paths and search queries? what happens when those files move? I like this idea but when it comes to actually performing it, I'm sorta stumped

Saving the search query for minor versions mean that you can more easily change the default build of every blendfile made in that version. The downside is you can't make special cases that the first strategy is great at making (eg. you can't assign a specific build to a specific file)

There is a world where these two strategies are used in combination. Default builds per version, but individual files can specify what build they want. We do sort of allow this in the commandline. It's trivial to set this up yourself with the current method. You're just using a shell/batch script instead of the actual file. This is why I'm hesitant to rewrite the whole system to accomodate this one case

./blenderlauncher launch -c -f file.blend -v <major_num>.<minor>.<patch>[-<branch>][+<build_hash>][@<commit time>]

@Victor-IX
Copy link
Owner

I made a quick diagram of the system to be sure I've understood everything right:
image
Tell me if I'm missing something.

After thinking a bit more about the system, I feel like having the specific version for each file is not very important, and I don't think a lot of users will benefit from this functionality. For the few times you need to use a specific build for a file, you can open it manually with the desired version.

@zeptofine
Copy link
Collaborator Author

yeah that looks about right to me

@zeptofine
Copy link
Collaborator Author

So what is left for us to do here before we merge this?

I saw you were doing stuff with special file icons. We could probably accomplish that if we extract it from the exe at some point and direct the windows registry to the extracted icon. In Linux, something else handles icons so we don't need to worry about that

@Victor-IX
Copy link
Owner

Yes, I think it's the last thing to do. I'm not really sure how to export the icon and link it to the blend file.

@zeptofine
Copy link
Collaborator Author

is there some sort of project file you used to make the file icons? might be a good idea to add it for consistency sake, like the launcher logo blendfile

@Victor-IX
Copy link
Owner

I remade it in Blender, it's in a new scene in the Blender file

@zeptofine
Copy link
Collaborator Author

oh cool, thanks

@Victor-IX
Copy link
Owner

Are we ready to merge this pr?

@zeptofine
Copy link
Collaborator Author

Everything seems to be in order, the only thing left to do is to let people test it i guess :D

@Victor-IX
Copy link
Owner

We will do a pre-release with all of that soon! If possible I want to wait for the request issue to be fixed.
Also, can you validate the PR for the header?

@Victor-IX Victor-IX merged commit 89bf1db into main Aug 21, 2024
@zeptofine zeptofine deleted the cli-launching branch August 22, 2024 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants