Recently, I was learning the Go language, and I was thinking of finding some projects to do. It happened that I always wanted to make a software that “local area network PC and mobile phone can exchange files without using wechat /QQ and other harassment software”, so I used Go to do it. The final screenshot is as follows:

The function is simple:

  1. After the text or file is uploaded to the PC, a QR code is created for the mobile browser to download
  2. After a text or file is uploaded to the browser, the mobile phone automatically sends a websocket notification to the PC, and a download prompt is displayed

Here basically say realization idea.

Implementation approach

Create Windows with Loca

I learned that Go has the following libraries to implement Windows:

  1. Lorca – Call system existing Chrome/Edge implementation of simple Windows, UI through HTML/CSS/JS implementation
  2. Webview – much more powerful than Lorca and similar ideas for UI implementation
  3. Fyne – UI framework with Canvas drawing, good performance
  4. Qt – more complex and powerful UI framework

I picked the simplest Lorca at random and started.

Make UI with HTML/CSS/JS

I use React + ReactRouter to implement the page structure. File uploads and dialog boxes are written in native JS by myself. UI details are done in CSS3 without relying on other UI component libraries.

Lorca’s main function is to display the index.html that I wrote.

withginImplementing background interface

JS in index.html uses five interfaces, which I use gin to implement:

router.GET("/uploads/:path", controllers.UploadsController)              
router.GET("/api/v1/addresses", controllers.AddressesController) 
router.GET("/api/v1/qrcodes", controllers.QrcodesController)   
router.POST("/api/v1/files", controllers.FilesController)      
router.POST("/api/v1/texts", controllers.TextsController)
Copy the code

So the qrcode is generated using go-qrcode.

withgorilla/websocketRealize mobile phone notification PC

This library provides an example of a chat room that can be tweaked to work for me.

The overall train of thought

In general:

  1. Create a window with Lorca
  2. Make interface with HTML, call background interface with JS
  3. Gin is used to implement the background interface
  4. The uploaded files are placed in the Uploads folder

400 lines of Go code, 700 lines of JS code.

How to use

At present, I only tested the Windows system, which can run normally. Theoretically, macOS and Linux will work, but I haven’t tested it.

You can download the executable on the Releases page, or compile the source code yourself to get the executable.

Windows User Instructions

Windows users need to run port 27149 connections in the inbound rules of the firewall, otherwise the software cannot be accessed by mobile phones.

To compile

git clone [email protected]:FrankFang/synk.git
cd synk
./scripts/build_for_mac.sh
./scripts/build_for_win.sh
Copy the code

I harvest

  1. Know how to write a publish subscription using Go.
  2. knowch2 <- ch1ch2 <- (<-ch1)The former is usually written wrong
  3. You know how the Go application code introduces native packages