dashPi: a self-hosted home dashboard, its sync server and phone app
The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fb3c01cdd7
333 changed files with 45151 additions and 0 deletions
33
app/packages/gb_export/.gitignore
vendored
Normal file
33
app/packages/gb_export/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Miscellaneous
|
||||
*.class
|
||||
*.log
|
||||
*.pyc
|
||||
*.swp
|
||||
.DS_Store
|
||||
.atom/
|
||||
.build/
|
||||
.buildlog/
|
||||
.history
|
||||
.svn/
|
||||
.swiftpm/
|
||||
migrate_working_dir/
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
# The .vscode folder contains launch configuration and tasks you configure in
|
||||
# VS Code which you may wish to be included in version control, so this line
|
||||
# is commented out by default.
|
||||
#.vscode/
|
||||
|
||||
# Flutter/Dart/Pub related
|
||||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
|
||||
/pubspec.lock
|
||||
**/doc/api/
|
||||
.dart_tool/
|
||||
.flutter-plugins-dependencies
|
||||
/build/
|
||||
/coverage/
|
||||
30
app/packages/gb_export/.metadata
Normal file
30
app/packages/gb_export/.metadata
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
|
||||
version:
|
||||
revision: "6b182d2c7585eba26d4edce0f97630effd256c33"
|
||||
channel: "stable"
|
||||
|
||||
project_type: plugin
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: 6b182d2c7585eba26d4edce0f97630effd256c33
|
||||
base_revision: 6b182d2c7585eba26d4edce0f97630effd256c33
|
||||
- platform: android
|
||||
create_revision: 6b182d2c7585eba26d4edce0f97630effd256c33
|
||||
base_revision: 6b182d2c7585eba26d4edce0f97630effd256c33
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
9
app/packages/gb_export/android/.gitignore
vendored
Normal file
9
app/packages/gb_export/android/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.cxx
|
||||
75
app/packages/gb_export/android/build.gradle.kts
Normal file
75
app/packages/gb_export/android/build.gradle.kts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
group = "dev.bashynx.gb_export"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
buildscript {
|
||||
val kotlinVersion = "2.3.20"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle:9.0.1")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "dev.bashynx.gb_export"
|
||||
|
||||
compileSdk = 36
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
getByName("main") {
|
||||
java.srcDirs("src/main/kotlin")
|
||||
}
|
||||
getByName("test") {
|
||||
java.srcDirs("src/test/kotlin")
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 24
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests {
|
||||
isIncludeAndroidResources = true
|
||||
all {
|
||||
it.useJUnitPlatform()
|
||||
|
||||
it.outputs.upToDateWhen { false }
|
||||
|
||||
it.testLogging {
|
||||
events("passed", "skipped", "failed", "standardOut", "standardError")
|
||||
showStandardStreams = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
}
|
||||
1
app/packages/gb_export/android/settings.gradle.kts
Normal file
1
app/packages/gb_export/android/settings.gradle.kts
Normal file
|
|
@ -0,0 +1 @@
|
|||
rootProject.name = "gb_export"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="dev.bashynx.gb_export">
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package dev.bashynx.gb_export
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.DocumentsContract
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.PluginRegistry
|
||||
import java.io.File
|
||||
|
||||
// "dash/gbexport": pick() → uri or null (needs the activity) · info(uri) → {size, modified} or null ·
|
||||
// copy(uri, path) → true when copied · timeZone() → the phone's zone ("Europe/Bucharest").
|
||||
// info / copy / timeZone work without an activity (background tasks).
|
||||
class GbExportPlugin : FlutterPlugin, ActivityAware, PluginRegistry.ActivityResultListener {
|
||||
private val pickCode = 4711
|
||||
private lateinit var channel: MethodChannel
|
||||
private lateinit var context: Context
|
||||
private var activity: ActivityPluginBinding? = null
|
||||
private var pending: MethodChannel.Result? = null
|
||||
|
||||
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
context = binding.applicationContext
|
||||
channel = MethodChannel(binding.binaryMessenger, "dash/gbexport")
|
||||
channel.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"pick" -> {
|
||||
val a = activity?.activity
|
||||
if (a == null) {
|
||||
result.error("no_activity", "the picker needs the app on screen", null)
|
||||
} else {
|
||||
pending = result
|
||||
val i = Intent(Intent.ACTION_OPEN_DOCUMENT).addCategory(Intent.CATEGORY_OPENABLE).setType("*/*")
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
|
||||
a.startActivityForResult(i, pickCode)
|
||||
}
|
||||
}
|
||||
"info" -> result.success(info(Uri.parse(call.argument<String>("uri"))))
|
||||
"timeZone" -> result.success(java.util.TimeZone.getDefault().id)
|
||||
"copy" -> result.success(try {
|
||||
context.contentResolver.openInputStream(Uri.parse(call.argument<String>("uri")))!!.use { inp ->
|
||||
File(call.argument<String>("path")!!).outputStream().use { inp.copyTo(it) }
|
||||
}
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
})
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) = channel.setMethodCallHandler(null)
|
||||
|
||||
private fun info(uri: Uri): Map<String, Long>? = try {
|
||||
context.contentResolver.query(uri, arrayOf(DocumentsContract.Document.COLUMN_SIZE,
|
||||
DocumentsContract.Document.COLUMN_LAST_MODIFIED), null, null, null)?.use { c ->
|
||||
if (c.moveToFirst()) mapOf("size" to c.getLong(0), "modified" to (if (c.isNull(1)) 0L else c.getLong(1))) else null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
|
||||
if (requestCode != pickCode) return false
|
||||
val uri = if (resultCode == Activity.RESULT_OK) data?.data else null
|
||||
if (uri != null) {
|
||||
try {
|
||||
context.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
} catch (e: SecurityException) {
|
||||
}
|
||||
}
|
||||
pending?.success(uri?.toString())
|
||||
pending = null
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
||||
activity = binding
|
||||
binding.addActivityResultListener(this)
|
||||
}
|
||||
|
||||
override fun onDetachedFromActivityForConfigChanges() = onDetachedFromActivity()
|
||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) = onAttachedToActivity(binding)
|
||||
override fun onDetachedFromActivity() {
|
||||
activity?.removeActivityResultListener(this)
|
||||
activity = null
|
||||
}
|
||||
}
|
||||
25
app/packages/gb_export/lib/gb_export.dart
Normal file
25
app/packages/gb_export/lib/gb_export.dart
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Gadgetbridge's database export on this phone, through Android's file picker: picked once (the read
|
||||
// permission is kept), then read again after every new export — from the app and from background tasks
|
||||
// (a plugin, so WorkManager's engine has it too). Android: GbExportPlugin.kt.
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
const _channel = MethodChannel('dash/gbexport');
|
||||
|
||||
/// The system file picker → the file's uri (null = cancelled). Needs the app on screen.
|
||||
Future<String?> pickExport() => _channel.invokeMethod<String>('pick');
|
||||
|
||||
/// {size, modified (ms)} — null when the file is gone or no longer readable.
|
||||
Future<Map<String, int>?> exportInfo(String uri) => _channel.invokeMapMethod<String, int>('info', {'uri': uri});
|
||||
|
||||
/// The phone's time zone ("Europe/Bucharest"); null where there's no Android (tests).
|
||||
Future<String?> timeZone() async {
|
||||
try {
|
||||
return await _channel.invokeMethod<String>('timeZone');
|
||||
} on MissingPluginException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Copy the file to [path] → true when copied.
|
||||
Future<bool> copyExport(String uri, String path) async =>
|
||||
await _channel.invokeMethod<bool>('copy', {'uri': uri, 'path': path}) ?? false;
|
||||
19
app/packages/gb_export/pubspec.yaml
Normal file
19
app/packages/gb_export/pubspec.yaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
name: gb_export
|
||||
description: "dashPi app: read Gadgetbridge's database export through Android's file picker (kept permission) — also from a background task."
|
||||
version: 0.0.1
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
flutter: '>=3.3.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
platforms:
|
||||
android:
|
||||
package: dev.bashynx.gb_export
|
||||
pluginClass: GbExportPlugin
|
||||
Loading…
Add table
Add a link
Reference in a new issue