Muffin Sync

I use a tool called Obsidian to make notes on things I am likely to forget in the future. One of the many things I like about Obsidian is that notes are stored in markdown on the disk, not in some binary/proprietary format, so they can be read and written by other programs. I wanted to sync my project notes between my phone and my chromebook so I can access them at almost all times, and Obsidian provides a tool for this called Sync. However, it is a paid service, so I thought I would try and make my own for free.

The ideal tool for this would be git – despite the fact that it is intended for code, the way it works is suitable for markdown as well, as it can merge two versions of the same file trivially if they are in plain text format. Markdown is very similar to plain text, so this should be no problem for git.

My chromebook has a Linux subsystem available on it, which I can use to set up a shell command which will push/pull my files from a remote (I am using Github for this). However, despite running android, there is no easy way to run git on my phone without the use of external apps, so I was going to need to make my own for this to work.

I first tried to download Android Studio, but unfortunately my chromebook doesn’t have the resources to support it (I did actually manage to get it to build, but it took 8 minutes and was extremely unresponsive), so I resorted to building from the command line. There are apparently no tools for creating an app from command line, so I wrote a small python script the clones a blueprint from a git repository and then updates all of the names inside (https://github.com/CoderMuffin/MuffinStudio if you are interested). Then, after a slow initial build, I managed to get the app compiling and running in around 45 seconds, which is a speed improvement of more than 10 times(!), and in my opinion very impressive for the hardware.

I initially started building the app using XML layout and java, but became more interested in using Jetpack Compose, a recently released framework that is somewhat similar to reactive frameworks seen in JS like, well, React. This is quite different to XML layout, which is more event driven, so it was quite interesting to learn this as a new way of doing things. Development was relatively smooth after this, and it was very nice to have the latest material styles built-in. The only minor issues I encountered were with UI code not being able to call functions without a SideEffect clause – which does make sense retrospectively, considering you do not want to run the function on every recompose.

The major issue I did encounter was with permissions regarding the git library I was using. I chose to use Eclipse’s JGit for this, which did work very well considering it was not designed for android. The issue was occuring when trying to read/write to files using their content URIs. Android uses URIs for files rather than paths, which can make it really difficult to pin down the actual location of a file. This can be done (granted, through some scary looking stack overflow code that is at least 5 years dry aged), but I wasn’t able to get JGit to play nicely, even with administrator permissions (although maybe I kind of expected that from the stack overflow post, but anyway). I couldn’t find a way around this, so I ended up copying the whole directory tree using the content URI APIs to a temporary work directory that JGit could modify for some reason, and then copying everything back. It isn’t a great fix, and the majority of time spent syncing is actually just copying these files, but its better than nothing.

I am very happy with the result, and while it does stumble on merge conflicts sometimes, it has proved far more useful than I originally thought it would, as did the CLI app maker! Screenshots of the app are below 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *