feat(mobile): keep screen up and use persistent instance id
This commit is contained in:
parent
5d0311b731
commit
22070ba33a
6
Makefile
6
Makefile
|
@ -16,7 +16,7 @@ test: test-go ## Executing tests
|
||||||
test-go: deps
|
test-go: deps
|
||||||
( set -o allexport && source .env && set +o allexport && go test -v -count=1 $(GOTEST_ARGS) ./... )
|
( set -o allexport && source .env && set +o allexport && go test -v -count=1 $(GOTEST_ARGS) ./... )
|
||||||
|
|
||||||
build: build-desktop build-mobile build-client ## Build artefacts
|
build: build-desktop build-android build-client ## Build artefacts
|
||||||
|
|
||||||
build-desktop: deps ## Build executable
|
build-desktop: deps ## Build executable
|
||||||
CGO_ENABLED=0 go build \
|
CGO_ENABLED=0 go build \
|
||||||
|
@ -30,12 +30,12 @@ build-client: deps ## Build executable
|
||||||
-o ./bin/client \
|
-o ./bin/client \
|
||||||
./cmd/client
|
./cmd/client
|
||||||
|
|
||||||
build-mobile: tools/gogio/bin/gogio deps ## Build executable
|
build-android: tools/gogio/bin/gogio deps ## Build executable
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
GOOS=android CGO_CFLAGS="-I${JDK_PATH}/include -I${JDK_PATH}/include/linux -w" tools/gogio/bin/gogio -target android -buildmode archive -o android/app/libs/mobile.aar -x ./cmd/mobile
|
GOOS=android CGO_CFLAGS="-I${JDK_PATH}/include -I${JDK_PATH}/include/linux -w" tools/gogio/bin/gogio -target android -buildmode archive -o android/app/libs/mobile.aar -x ./cmd/mobile
|
||||||
( cd android && ./gradlew assembleDebug )
|
( cd android && ./gradlew assembleDebug )
|
||||||
|
|
||||||
install-android: build-mobile
|
install-android: build-android
|
||||||
adb install android/app/build/outputs/apk/debug/app-debug.apk
|
adb install android/app/build/outputs/apk/debug/app-debug.apk
|
||||||
adb shell monkey -p com.cadoles.arcast_player -c android.intent.category.LAUNCHER 1
|
adb shell monkey -p com.cadoles.arcast_player -c android.intent.category.LAUNCHER 1
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -8,6 +8,9 @@
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|
|
@ -13,11 +13,13 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import com.cadoles.arcast_player.ui.theme.ArcastplayerTheme
|
import com.cadoles.arcast_player.ui.theme.ArcastplayerTheme
|
||||||
import org.gioui.GioActivity
|
import org.gioui.GioActivity
|
||||||
|
import android.view.WindowManager
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
startActivity(Intent(this, GioActivity::class.java))
|
startActivity(Intent(this, GioActivity::class.java))
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"forge.cadoles.com/arcad/arcast/pkg/browser/gioui"
|
"forge.cadoles.com/arcad/arcast/pkg/browser/gioui"
|
||||||
"forge.cadoles.com/arcad/arcast/pkg/server"
|
"forge.cadoles.com/arcad/arcast/pkg/server"
|
||||||
|
@ -14,18 +15,15 @@ import (
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
"gioui.org/op"
|
"gioui.org/op"
|
||||||
"github.com/gioui-plugins/gio-plugins/plugin"
|
"github.com/gioui-plugins/gio-plugins/plugin"
|
||||||
|
"github.com/gioui-plugins/gio-plugins/safedata"
|
||||||
|
"github.com/gioui-plugins/gio-plugins/safedata/giosafedata"
|
||||||
"github.com/gioui-plugins/gio-plugins/webviewer/webview"
|
"github.com/gioui-plugins/gio-plugins/webviewer/webview"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gitlab.com/wpetit/goweb/logger"
|
"gitlab.com/wpetit/goweb/logger"
|
||||||
|
|
||||||
// Android permissions
|
|
||||||
_ "net"
|
|
||||||
|
|
||||||
_ "gioui.org/app/permission/networkstate"
|
|
||||||
_ "gioui.org/app/permission/storage"
|
|
||||||
_ "gioui.org/app/permission/wakelock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const instanceIDSecretIdentifier = "instance_id"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
@ -36,6 +34,12 @@ func main() {
|
||||||
|
|
||||||
browser := gioui.NewBrowser(window)
|
browser := gioui.NewBrowser(window)
|
||||||
|
|
||||||
|
var safeDataConfig safedata.Config
|
||||||
|
var safeDataConfigWaigGroup sync.WaitGroup
|
||||||
|
var initSafeDataConfig sync.Once
|
||||||
|
|
||||||
|
safeDataConfigWaigGroup.Add(1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ops := new(op.Ops)
|
ops := new(op.Ops)
|
||||||
for {
|
for {
|
||||||
|
@ -50,16 +54,30 @@ func main() {
|
||||||
gtx := layout.NewContext(ops, evt)
|
gtx := layout.NewContext(ops, evt)
|
||||||
browser.Layout(gtx)
|
browser.Layout(gtx)
|
||||||
evt.Frame(gtx.Ops)
|
evt.Frame(gtx.Ops)
|
||||||
|
case app.ViewEvent:
|
||||||
|
initSafeDataConfig.Do(func() {
|
||||||
|
defer safeDataConfigWaigGroup.Done()
|
||||||
|
safeDataConfig = giosafedata.NewConfigFromViewEvent(window, evt, "com.cadoles.arcast_player")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
server := server.New(browser)
|
safeDataConfigWaigGroup.Wait()
|
||||||
|
safe := safedata.NewSafeData(safeDataConfig)
|
||||||
|
|
||||||
|
instanceID, err := getInstanceIDFromSafeData(safe)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal(ctx, "could not retrieve instance id", logger.CapturedE(errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
server := server.New(browser, server.WithInstanceID(instanceID))
|
||||||
|
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
logger.Fatal(ctx, "could not start server", logger.CapturedE(errors.WithStack(err)))
|
logger.Fatal(ctx, "could not start server", logger.CapturedE(errors.WithStack(err)))
|
||||||
|
@ -79,3 +97,27 @@ func main() {
|
||||||
|
|
||||||
app.Main()
|
app.Main()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getInstanceIDFromSafeData(safe *safedata.SafeData) (string, error) {
|
||||||
|
instanceIDSecret, err := safe.Get(instanceIDSecretIdentifier)
|
||||||
|
if err != nil && err.Error() != "not found" {
|
||||||
|
return "", errors.Wrapf(err, "could not retrieve instance id secret")
|
||||||
|
}
|
||||||
|
|
||||||
|
var instanceID string
|
||||||
|
if len(instanceIDSecret.Data) > 0 {
|
||||||
|
instanceID = string(instanceIDSecret.Data)
|
||||||
|
} else {
|
||||||
|
instanceID = server.NewRandomInstanceID()
|
||||||
|
|
||||||
|
instanceIDSecret.Identifier = instanceIDSecretIdentifier
|
||||||
|
instanceIDSecret.Data = []byte(instanceID)
|
||||||
|
instanceIDSecret.Description = "Arcast player instance identifier"
|
||||||
|
|
||||||
|
if err := safe.Set(instanceIDSecret); err != nil {
|
||||||
|
return "", errors.Wrapf(err, "could not save instance id secret")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return instanceID, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue