Keep all your desktop Fyne apps in sync

One of the projects that the Fyne team are discussing for a future release is the option for apps to stay in sync using some cloud service. Such a feature would enable you to start work on a document, drawing or game on one computer, put it down and immediately continue work on a different device (great for people on the move, or when you just want to add a finishing touch but you’re not at the office). You can expect to see this land in a future release, with a variety of cloud providers supported.

But what do we do until then?

The really great news is that it is already possible to keep all of your desktop apps in sync, and do so using an existing cloud storage provider (so there are no additional costs to you or your team!). We can enable this by storing the fyne preferences location in your cloud documents location. The rest of this post will show you how you can set up app sync for all your Fyne apps in one go (unfortunately this does not currently work for your mobile devices).

Any applications that are built using Fyne v2.0.0 or later will automatically stay up to date, you can even place two computers next to each other, type into one and see the other update (for example with our Fyne Notes app). The key is the use of the Preferences API – any app that uses these values will always have the latest data, and using either the AddChangeListener callback or the data binding features will automatically refresh the app when that data changes.

Show me how!

OK so here are the details – we explore how to set up sync from a macOS computer, and then add a linux and windows computer to sync up. You should start this process on whichever of your computers you have used most with Fyne apps, or where most of your data lives, the others will update to copy its data.

Before you begin it is assumed that you have subscribed to some cloud storage service and that it is set up and running on your computers. What is important is that it offers offline storage – this means you can continue to use the data if the internet connection is not reliable.

  1. First you need to locate where your fyne preferences are stored. For our macOS computer that will be ~/Library/Preferences/fyne, for a Linux or BSD computer it would be ~/.config/fyne and for Windows the location is ~\AppData\Roaming\fyne.
  2. Second is to make sure that you have closed any open Fyne apps. This is not essential, but leaving them open could lead to problems if they save data after this process is complete.
  3. Move this folder to your cloud storage, any folder name will work, but if you have a “.” prefix then it should remain hidden. For example to do this on a macOS computer that uses Dropbox to sync, issue the following:
    $ mv ~/Library/Preferences/fyne ~/Dropbox/.fyne
  4. Lastly we set up a symlink from the old location into the synchronised data. This means that when you start a Fyne app later it will automatically read and write data using your could provider.
    $ ln -s ~/Dropbox/.fyne ~/Library/Preferences/fyne

That is all you need to set up your data in the cloud, we now update any other computers to use this data instead. There are two steps to this, firstly to back up your old data, and secondly to set up a link into the cloud storage like before. Continuing with our Dropbox example above we can set up a linux computer as follows (from the command line):

$ mv ~/.config/fyne ~/fynebackup
$ ln -s ~/Dropbox/.fyne ~/.config/fyne

If there is an error to say that “Dropbox/.fyne” cannot be found you should check the internet connection, wait a few seconds and try again.

To set up on a windows computer you will need to open a command prompt “As Administrator” and issue the following commands:

> move C:\Users\username\AppData\Roaming\fyne C:\Users\username\fynebackup
> mklink /j C:\Users\username\AppData\Roaming\fyne C:\Users\username\Dropbox\.fyne

And that’s all there is to it. Your applications will now share state over cloud sync and all included in your current subscription.

If you have any problems with the steps above or would like to know more about cloud sync or storage solutions with Fyne apps please get in touch.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s