Skip to content

feat: Automatic print start dialog on upload #2223

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ammmze
Copy link
Contributor

@ammmze ammmze commented May 22, 2025

Description

This PR adds a couple ways to have the start print dialog automatically open.

  1. When the app is installed as a Progressive Web App on a desktop/laptop, the app will now be associated with gcode files. If you open a gcode file with Mainsail, the gcode file will be uploaded to the printer and the start print dialog will be presented to the user.
  2. When the new configuration option "Show Print on Upload" is enabled, then when a new gcode file is recognized by Mainsail, we will open the start print dialog for that new file. This can be useful to help streamline tool mapping when starting MMU prints.
  • I felt like this may not be a feature a user would want in all instances of mainsail, so I've made this setting browser local (by saving to localStorage). I would expect people would want it enabled in their slicer, but probably not anywhere else. By default if the browser user agent contains "slicer", then I am enabling this setting (but can be overwritten by toggling the setting). Note: I only verified Orca Slicer, but it presents a user agent that starts with "BBL-Slicer".

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings

Note

The recordings show the application with the new Happy Hare functionality, but none of my changes are dependent on that functionality. I've just simply cherry-picked my commits from my HH fork onto a new branch from the mainline develop branch.

PWA "Open With"

This demonstrates opening a gcode file with the "installed" Mainsail application (side note: I believe a user would need to re-install the application for it to set up that file type association).

Screen.Recording.2025-05-21.at.10.53.26.PM.mp4

Show Print on Upload

This demonstrates slicing a file and then using the "upload" along with the option to show the device page after uploading, which then automatically takes you to Mainsail after uploading and the start print dialog is displayed and the user may then start the print, perform tool mapping and then start the print, etc.

Screen.Recording.2025-05-21.at.10.55.23.PM.mp4

[optional] Are there any post-deployment tasks we need to perform?

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 22, 2025
Copy link
Contributor

Language file analysis report:

File Missing Keys Unused Keys
en.json 0 0

ammmze added 2 commits May 21, 2025 23:27
When Mainsail is installed as an app on a desktop, it should get configured as an application that supports opening ".gcode" files. So you can either directly association gcode files to it, or right-click > Open With > Mainsail. When you do this, the file will get uploaded to the server and then open the print start dialog so that you can review and start the print.
@ammmze ammmze force-pushed the launch-print-dialog branch from 59875fc to 30cc407 Compare May 22, 2025 06:28
Copy link
Contributor

Language file analysis report:

File Missing Keys Unused Keys
en.json 0 0

const latestKnownGcodeFileTime = Number(localStorage.getItem('latestKnownGcodeFileTime') ?? 0)
if (file && file.modified > latestKnownGcodeFileTime) {
localStorage.setItem('latestKnownGcodeFileTime', String(file.modified))
if (latestKnownGcodeFileTime > 0 && this.showPrintOnUpload)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing i've kind of been on the fence with here is perhaps maybe we should add an additional condition that the modified timestamp is within the last 5 minutes or so? The reason being, if I've got multiple instances of mainsail that I use with the "showPrintOnUpload" setting enabled, then lets say i send a print and go to mainsail, the dialog is presented, and i go ahead an hit print (or cancel). Then later I open another mainsail instance with the setting turned on, it would see there is a new gcode file with a timestamp newer than what it had saved in its localStorage, so it would present the dialog for the other instance.

Or alternatively, perhaps we save the latestKnownGcodeFileTime in the moonraker db, so we can track the latest one any of the mainsail instances have seen? The main caveat there is AFAICT the moonraker db stuff isn't actively updated (nor do I see a way to subscribe to changes to the db), so that means if there are multiple instances already open, they could have stale latestKnownGcodeFileTime attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant