Something went wrong. Try again.
Self-hosted, federated location sharing app and server that prioritizes user privacy and security
Something went wrong. Try again.
2.9 kB · 117 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118// Neededimport 'package:flutter/material.dart';import 'dart:ui';import 'dart:async';import 'dart:convert';
// Local imports//import 'backgroundservices.dart' as background_services;import 'utils/storage.dart';import 'utils/api.dart' as api;//import 'utils/time.dart';
// Background serviceimport 'package:flutter_background_service/flutter_background_service.dart';
// Main app entry pointFuture<void> main() async { WidgetsFlutterBinding.ensureInitialized();
// This is for testing only await appStorage.deleteAll(); await appStorage.write( key: 'server-url', value: 'http://192.168.68.103:3000', );
await appStorage.write(key: 'viewers', value: '{}');
debugPrint('viewers: ${await appStorage.read(key: "viewers")}');
final original = (await appStorage.read(key: 'viewers')).toString(); dynamic temp = jsonDecode(original);
final json = '{"viewer_id": "viewernumxxx"}'; // This would be the response final viewerId = jsonDecode(json)['viewer_id'];
temp[viewerId] = 'active';
final jsonNew = jsonEncode(temp);
await appStorage.write(key: 'viewers', value: jsonNew);
debugPrint('viewers: ${await appStorage.read(key: "viewers")}');
await startBackgroundLocationService(); startBackgroundService();
await api.sendPings();
runApp(const MainApp());}
class MainApp extends StatelessWidget { const MainApp({super.key});
@override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold(body: Center(child: Text('Hello World!'))), ); }}
// Background serviceFuture<void> startBackgroundLocationService() async { WidgetsFlutterBinding.ensureInitialized(); await initializeService();}
void startBackgroundService() { final service = FlutterBackgroundService(); service.startService();}
void stopBackgroundService() { final service = FlutterBackgroundService(); service.invoke("stop");}
Future<void> initializeService() async { final service = FlutterBackgroundService();
await service.configure( iosConfiguration: IosConfiguration( autoStart: true, onForeground: onStart, onBackground: onIosBackground, ), androidConfiguration: AndroidConfiguration( autoStart: true, onStart: onStart, isForegroundMode: true, autoStartOnBoot: true, ), );}
@pragma('vm:entry-point')Future<bool> onIosBackground(ServiceInstance service) async { WidgetsFlutterBinding.ensureInitialized(); DartPluginRegistrant.ensureInitialized();
return true;}
@pragma('vm:entry-point')void onStart(ServiceInstance service) async { Timer.periodic(const Duration(seconds: 1), (timer) async { /*await LocationUtils.updatePosition(); await api.sendLocation( LocationUtils.getLatitude(), LocationUtils.getLongitude(), );*/ });}
// Background service end