mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
mobile: Share database with playback service
This commit is contained in:
parent
5300d674b5
commit
7c9ac4e0ae
2 changed files with 49 additions and 15 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:moor/isolate.dart';
|
||||
|
|
@ -88,8 +89,6 @@ class BackendState extends State<Backend> {
|
|||
MusicusClient client;
|
||||
MusicLibrary ml;
|
||||
|
||||
MoorIsolate _moorIsolate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
@ -105,11 +104,22 @@ class BackendState extends State<Backend> {
|
|||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
_moorIsolate = await _createMoorIsolate();
|
||||
final dbConnection = await _moorIsolate.connect();
|
||||
player.setup();
|
||||
MoorIsolate moorIsolate;
|
||||
|
||||
final moorPort = IsolateNameServer.lookupPortByName('moorPort');
|
||||
if (moorPort != null) {
|
||||
moorIsolate = MoorIsolate.fromConnectPort(moorPort);
|
||||
} else {
|
||||
moorIsolate = await _createMoorIsolate();
|
||||
IsolateNameServer.registerPortWithName(
|
||||
moorIsolate.connectPort, 'moorPort');
|
||||
}
|
||||
|
||||
final dbConnection = await moorIsolate.connect();
|
||||
db = Database.connect(dbConnection);
|
||||
|
||||
player.setup();
|
||||
|
||||
await settings.load();
|
||||
|
||||
_updateMusicLibrary(settings.musicLibraryUri.value);
|
||||
|
|
@ -149,7 +159,6 @@ class BackendState extends State<Backend> {
|
|||
void dispose() {
|
||||
super.dispose();
|
||||
client.dispose();
|
||||
_moorIsolate.shutdownAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue