📜 ⬆️ ⬇️

What to write desktop client for a web service?

I asked this question when it became necessary to write a Windows client for my new Hyrax service.

The service allows you to share the clipboard between computers and / or Android devices, as well as receive on the computer all notifications that come to the phone. So, the first requirements were formed:



A small, lightweight utility that runs on any Windows system.
The size of the program is important, since it should be distributed via the Internet and, although modern speeds allow you to download gigabyte movies, it is much more pleasant when a small body shakes instantly. Great attention should have been given to libraries that can inflate any 'hello world' application so that it will weigh several dozen MB
')


The ability to port to a Mac with minimal effort - was the second requirement
Because of this requirement, we had to abandon the most obvious option - the use of MS .NET. Programming in .NET takes much less time, allows you to write simple code and the size of the program is small, because the .NET Framework is already installed on Windows. But, alas ... an attempt to launch a .NET application on a Mac is an exercise, though theoretically possible, but nontrivial and will scare away 99% of users.



Ui doesn't matter much
As planned, the application should send a clipboard to the server by pressing the hot keys (no mouse clicks!) And download new data from the server using long polling . Therefore, with the exception of a primitive window where you need to show the history, no UI was planned (later, though, a window appeared to display notifications from the phone).

It turns out that, if we discard .NET and Java (not every user wants to install Java for the program downloaded from the Internet), only C ++ remains. Began the search for UI libraries for C ++. At one time, I had the opportunity to write UI using MFC and WTL , but nowadays, the QT library is the most widely heard. According to the reviews and the description, it’s all good, but the free version can only be used with dynamic linking, and I really wanted it to be one single easy EXE file.

As a result, I stopped at the free cross-platform open source library wxWidgets . During the search I was very surprised that the choice is very, very limited, and good UI libraries for C ++ can be counted on the fingers of one hand. The wxWidget library allows you to create a UI for any platform, be it Windows, Mac or Linux, but it will look very simple, and it cannot be compared with the beauty that you can create using, say .NET WPF.
To communicate with the service, at first I began to use the JsonCPP libraries in conjunction with libcurl , on which the well-known curl utility (a command line utility that allows you to send data over many network protocols) is built, but later I learned about the excellent open source library from Microsoft (yes, yes there are also some good open source libraries from them) - cpprest (another name is Casablanca ) CppRest allows you to write code for the web service in modern C ++, besides it already has Json support, which eliminates the need to use other json libraries.

To build this project regardless of the platform, CMake is used. CMake allows you to describe the structure of the C ++ project and collect it on various platforms. Here such a hodgepodge turned out a team , a stack of libraries for a simple program to facilitate the exchange of data between computers and Android devices.

PS I told about the server technologies stack here .

Source: https://habr.com/ru/post/279447/


All Articles