Skip to content

fs: add support for flag --no-console on windows to hide the console … - #4953

Merged
ncw merged 1 commit into
rclone:masterfrom
albertony:no_console
Jan 27, 2021
Merged

ncw merged 1 commit into
rclone:masterfrom
albertony:no_console

Conversation

@albertony

@albertony albertony commented Jan 24, 2021 •

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Add option to hide rclone's console window, with a new flag --no-console. Mostly relevant in combination with remote control, mount, web gui etc commands, but also long running sync operations etc, and especially when starting rclone automatically from task scheduler or windows service (nssm).

The implementation is based on Syncthing's:
syncthing/syncthing@80dca96

Note: When starting rclone with --no-console from "run" dialog, desktop shortcut etc, the console window "flashes" briefly on startup, before it gets set to hidden. If you start up cmd.exe and then execute rclone with --no-console from there, it actually hides the existing cmd.exe window, and when rclone process exits the cmd process is left running hidden. This can perhaps be a bit surprising for users, but I do not know a way around it (this is how Syncthing does it as well).

PS: Should it be called --no-console or --hide-console, or something else? Syncthing used no-console, and rclone already have some --no-... flags so I kept that.

PS 2: It would be nice to include this in a doc page for the typical use case of auto-starting rclone for mount etc. The following from Syncthing is really detailed and well written and could serve as an inspiration: https://docs.syncthing.net/users/autostart.html

Was the change discussed in an issue or in the forum before?

The actual option has not been discussed, but tips and workarounds on how to hide the console window has been discussed numerous times.

https://forum.rclone.org/t/how-to-mount-a-personal-jottacloud-as-a-drive-on-win10/21601/37
https://forum.rclone.org/t/autostart-mount-on-windows-without-cmd-popping-up/20896

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a nice feature :-)

See inline for a could of comments.

I thought you had to do this with linker flags...

PS: Should it be called --no-console or --hide-console, or something else? Syncthing used no-console, and rclone already have some --no-... flags so I kept that.

Happy to go with prior art of syncthing

PS 2: It would be nice to include this in a doc page for the typical use case of auto-starting rclone for mount etc. The following from Syncthing is really detailed and well written and could serve as an inspiration: https://docs.syncthing.net/users/autostart.html

Yes autostart could be a new page, or maybe a section in the install.md - nice idea. We could put systemd for mount and cron for syncing in there.

Comment thread fs/config/configflags/configflags.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I try (I don't always succeed!) to make the internal names HideConsole agree with the flag names --no-console - so let's pick one or the other! Note that the internal names show in the rc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Function is called HideConsole, and flag is called no-console, so internal name matched the function name instead of the flag name. Switched that. Could have renamed the function also to NoConsole but think it is more correct to call it HideConsole since that is what it does.

Comment thread lib/terminal/hidden_windows.go Resolved
@albertony

Copy link
Copy Markdown
Contributor Author

Force-pushed an update according to your comments. Merge if you think its ok now, if not just let me know and I will be happy to do another iteration.

This is a nice feature :-)

It will be a nice addition, and easier for new users, ref various forum threads on the subject. But its not at all perfect, it annoys me that the console window flashes on startup, but seemed like Syncthing had a couple of iterations on it without finding a better method, and I did not want to invest much more time myself.

I thought you had to do this with linker flags...

I wanted to debug this issue related to mount, but since build failed I had to find something else to do that I could build without -tags cmount.. :)

@ncw

ncw commented Jan 27, 2021

Copy link
Copy Markdown
Member

This looks great now - thank you!

I will merge it now.

Note that here: https://stackoverflow.com/a/23250506/164234 shows how to link the executable so the console window never appears. I don't think we want to do this but I thought you might like to see it if you haven't already.

@ncw
ncw merged commit 7a49675 into rclone:master Jan 27, 2021
@ncw

ncw commented Jan 27, 2021

Copy link
Copy Markdown
Member

I wanted to debug this issue related to mount, but since build failed I had to find something else to do that I could build without -tags cmount.. :)

What is broken? I think you posted on the forum about this but my memory is failing me here ;-)

@albertony

Copy link
Copy Markdown
Contributor Author

Yes, it was the mingw gcc error "export ordinal too large". Solved by adding "-buildmode exe". Thank you for that tip! :)

@albertony albertony mentioned this pull request Jan 27, 2021
4 of 5 tasks
@albertony
albertony deleted the no_console branch January 29, 2021 22:18
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.

2 participants