mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Add simple desktop app
This commit is contained in:
parent
5312bad52d
commit
4bdd1873c4
17 changed files with 540 additions and 1 deletions
22
desktop/lib/main.dart
Normal file
22
desktop/lib/main.dart
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:musicus_common/musicus_common.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart' as pp;
|
||||
|
||||
import 'settings.dart';
|
||||
import 'platform.dart';
|
||||
import 'playback.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
final dir = await pp.getApplicationSupportDirectory();
|
||||
final dbPath = p.join(dir.path, 'db.sqlite');
|
||||
|
||||
runApp(MusicusApp(
|
||||
dbPath: dbPath,
|
||||
settingsStorage: SettingsStorage(),
|
||||
platform: MusicusDesktopPlatform(),
|
||||
playback: MusicusDesktopPlayback(),
|
||||
));
|
||||
}
|
||||
66
desktop/lib/platform.dart
Normal file
66
desktop/lib/platform.dart
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:file_chooser/file_chooser.dart';
|
||||
import 'package:musicus_common/musicus_common.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class MusicusDesktopPlatform extends MusicusPlatform {
|
||||
@override
|
||||
Future<String> chooseBasePath() async {
|
||||
final result = await showOpenPanel(
|
||||
canSelectDirectories: true,
|
||||
);
|
||||
|
||||
if (result != null && !result.canceled) {
|
||||
return result.paths.first;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Document>> getChildren(String parentId) async {
|
||||
final List<Document> result = [];
|
||||
|
||||
final parent = Directory(parentId ?? basePath);
|
||||
await for (final fse in parent.list()) {
|
||||
result.add(Document(
|
||||
id: fse.path,
|
||||
name: p.basename(fse.path),
|
||||
parent: parentId,
|
||||
isDirectory: fse is Directory,
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> getIdentifier(String parentId, String fileName) async {
|
||||
return p.absolute(parentId, fileName);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> readDocument(String id) async {
|
||||
try {
|
||||
return await File(id).readAsString();
|
||||
} on FileSystemException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> readDocumentByName(String parentId, String fileName) async {
|
||||
try {
|
||||
return await File(p.absolute(parentId, fileName)).readAsString();
|
||||
} on FileSystemException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> writeDocumentByName(
|
||||
String parentId, String fileName, String contents) async {
|
||||
await File(p.absolute(parentId, fileName)).writeAsString(contents);
|
||||
}
|
||||
}
|
||||
43
desktop/lib/playback.dart
Normal file
43
desktop/lib/playback.dart
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import 'package:musicus_common/musicus_common.dart';
|
||||
|
||||
class MusicusDesktopPlayback extends MusicusPlayback {
|
||||
@override
|
||||
Future<void> addTracks(List<InternalTrack> tracks) async {
|
||||
// TODO: implement addTracks
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> playPause() async {
|
||||
// TODO: implement playPause
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeTrack(int index) async {
|
||||
// TODO: implement removeTrack
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> seekTo(double pos) async {
|
||||
// TODO: implement seekTo
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setup() async {
|
||||
// TODO: implement setup
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> skipTo(int index) async {
|
||||
// TODO: implement skipTo
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> skipToNext() async {
|
||||
// TODO: implement skipToNext
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> skipToPrevious() async {
|
||||
// TODO: implement skipToPrevious
|
||||
}
|
||||
}
|
||||
30
desktop/lib/settings.dart
Normal file
30
desktop/lib/settings.dart
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import 'package:musicus_common/musicus_common.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsStorage extends MusicusSettingsStorage {
|
||||
SharedPreferences _pref;
|
||||
|
||||
Future<void> load() async {
|
||||
_pref = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> getInt(String key) {
|
||||
return Future.value(_pref.getInt(key));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> getString(String key) {
|
||||
return Future.value(_pref.getString(key));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setInt(String key, int value) async {
|
||||
await _pref.setInt(key, value);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setString(String key, String value) async {
|
||||
await _pref.setString(key, value);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue