Hide Console -- Source Code?

I’ve seen several solutions for starting syncthing in Windows with -no-console, but is there a way to accomplish this in the source code before building the EXE?

I’d like to have the syncthing.exe automatically hide the console window.

Any ideas?

Just make a batch file in the same dir as syncthing.exe called syncthing.bat and put in it:

syncthing.exe -no-console

Bam, instant GUI clickability with no console. :slight_smile:

Many windows ppl use batch files cause we also like no-browser verbose and logfile options also.

Modifying the build script to use go build -ldflags -H=windowsgui ... should accomplish the same, by not having it start the console at all, ever.

Thank you Jakob for your quick response. Would I modify the actual script, “build.go”, or would I add those options in the build command “go run build.go” somehow?

If I am modifying the actual build.go script, where would I add those options?

You need to modify the script, look for where it sets ldflags already.

I’ve been searching through build.go this morning, but the references to -ldflags are confusing to me. I don’t see where it is setting any ldflags already. Sorry, I’m new to GO and Syncthing.

Can you tell me where to do this exactly? Much appreciated…

Try adding it after this line, in the same fashion as the preceding lines:

Do I just include this part at the end – instead of “buildHost”? -H=windowsgui

Sorry again. I’ve tried a few things, but I have no idea what I should type…

I don’t know how to make this line: go build -ldflags -H=windowsgui

into this format: fmt.Fprintf(b, " -X main.BuildHost%c%s", sep, buildHost())

I hesitate to say this, but perhaps modifying the source to accomplish your goal is not the way you should pursue? It’s something that’s inherently somewhat tricky to a non-programmer and will need maintenance for each release in the future to keep up to date. @nrm21’s solution with a bat file adding -no-console might be sufficient?

I understand. I’d really like to try your method though, and I can track and build with this one change pretty well if I can get it setup the first time. So, if you’re willing to help me with this one line, I’d really appreciate it. I want the user to be able to download just the EXE file and not have to worry about other files and folders.

Also, if this is beyond your normal support scope, I would be happy to pay to have you help me accomplish this task… Again, I have modified the GUI and have successfully built with that, but I just need this one change.
Let me know.

Bare in mind, the license requires any files that have been modified to be opensourced.

Yes, absolutely. It is all remaining open source. I’m just removing some of the GUI options that may be confusing to beginners and keeping a link for anyone to download the modified source code.

It should be:

fmt.Fprintf(b, " -H=windowsgui")

But needs building on Windows obviously

Ok. Thank you. You make a good point. Is there a different flag I could set if I build it on a MAC?

Actually, from testing just now this seems to work fine even when cross compiled from Mac. I didn’t think it would, either, but it does. At least according to file, I didn’t try running the binaries themselves.

# with patch
jb@syno:~/s/g/s/syncthing $ file syncthing.exe 
syncthing.exe: PE32+ executable for MS Windows (GUI) Mono/.Net assembly

# without
jb@syno:~/s/g/s/syncthing $ file syncthing.exe 
syncthing.exe: PE32+ executable for MS Windows (console) Mono/.Net assembly

No idea why it thinks it’s a .Net assembly but I’m not going to investigate that

Thanks guys. Again, I really appreciate it. I will test it out later today and let you know.

I’m cross compiling syncthing-tray from linux to windows using -ldflags -H=windowsgui I can confirm that this works.

Okay, I tried this, and it works great… No console and the GUI opens in the browser.

Now, I have an unforseen problem… If the user closes the browser, and then tries to launch syncthing.exe again, it won’t load because it is already running. There’s no way to close syncthing without the console (except for task manager). I’ll have to think about this. Any ideas?