~f4814n/frost

e4e468bd5a3ba6609451e680cf72a5bc19b5914e — Fabian Geiselhart 10 months ago 79d0baa
Add android support
5 files changed, 73 insertions(+), 3 deletions(-)

M .gitignore
M cmd/frost/main.go
A cmd/frost/platform_android.go
M cmd/frost/platform_linux.go
M flake.nix
M .gitignore => .gitignore +1 -0
@@ 1,2 1,3 @@
/frost
result
frost.apk

M cmd/frost/main.go => cmd/frost/main.go +6 -1
@@ 87,7 87,12 @@ func (a *App) run() error {
			case system.FrameEvent:
				var ops op.Ops
				gtx := layout.NewContext(&ops, e)
				a.view.Layout(gtx)
				layout.Inset{
					Top: e.Insets.Top,
					Bottom: e.Insets.Bottom,
					Left: e.Insets.Left,
					Right: e.Insets.Right,
				}.Layout(gtx, a.view.Layout)
				e.Frame(gtx.Ops)
			case system.DestroyEvent:
				return e.Err

A cmd/frost/platform_android.go => cmd/frost/platform_android.go +57 -0
@@ 0,0 1,57 @@
// +build android

package main

import (
	"os"
	"encoding/json"
	"git.sr.ht/~f4814n/matrix"
	"git.sr.ht/~f4814n/matrix/util/cache"
	backend "git.sr.ht/~f4814n/matrix/backend/sqlite"
)

var (
	baseDir = "/data/data/de.f4814n.frost"
	dataDir = baseDir + "/data"
	configFilePath = baseDir + "/config.json"
	cacheDir = baseDir + "/cache"
)

type Platform struct {
	Cache cache.Cache
}

func InitPlatform() Platform {
	// Create Cache
	cache, err := cache.NewFSCache(cacheDir)
	if err != nil {
		// XXX Fallback to memory cache, warn
		panic(err.Error())
	}

	return Platform{Cache: cache}
}

func (p Platform) LoadConfig() (cfg AppConfig, err error) {
	f, err := os.Open(configFilePath)
	if err != nil {
		return
	}

	err = json.NewDecoder(f).Decode(&cfg)
	return
}

func (p Platform) FlushConfig(cfg AppConfig) (err error) {
	f, err := os.Create(configFilePath)
	if err != nil {
		return
	}

	err = json.NewEncoder(f).Encode(cfg)
	return
}

func (p Platform) NewBackend() matrix.Backend {
	return backend.New(dataDir)
}

M cmd/frost/platform_linux.go => cmd/frost/platform_linux.go +2 -0
@@ 1,3 1,5 @@
// +build linux,!android

package main

import (

M flake.nix => flake.nix +7 -2
@@ 12,9 12,13 @@

  outputs = { self, nixpkgs, flake-utils, ... }:
    let
      devShell = with import nixpkgs { system = "x86_64-linux"; }; {
        devShell."x86_64-linux" = mkShell {
      devShell = with import nixpkgs { system = "x86_64-linux"; config = { android_sdk.accept_license = true; }; }; {
        devShell."x86_64-linux" = let
            sdk = (androidenv.composeAndroidPackages{ platformVersions = [ "28" ]; abiVersions = [ "arm64" ]; includeNDK = true; includeEmulator = true; }).androidsdk;
        in mkShell {
          buildInputs = [
            sdk
            openjdk
            nixfmt
            go
            goimports


@@ 30,6 34,7 @@
          shellHook = ''
            export GOPATH=~/.cache/gopath
            export PATH=$(go env GOPATH)/bin:$PATH
            export ANDROID_SDK_ROOT=${sdk}/libexec/android-sdk
          '';
        };
      };