You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
4 years ago
|
import 'dart:io';
|
||
|
|
||
|
import 'package:dde_gesture_manager/builder/provider_annotation.dart';
|
||
|
import 'package:dde_gesture_manager/extensions.dart';
|
||
4 years ago
|
import 'package:dde_gesture_manager/models/scheme.dart';
|
||
4 years ago
|
import 'package:path/path.dart' show join;
|
||
|
import 'package:path_provider/path_provider.dart';
|
||
|
|
||
4 years ago
|
import 'local_schemes.dart';
|
||
4 years ago
|
|
||
4 years ago
|
export 'local_schemes.dart';
|
||
4 years ago
|
|
||
|
@ProviderModel()
|
||
4 years ago
|
class LocalSchemes implements LocalSchemesInterface<LocalSchemeEntryLinux> {
|
||
|
LocalSchemes() {
|
||
|
schemeEntries.then((value) => schemes = value);
|
||
4 years ago
|
}
|
||
|
|
||
|
@override
|
||
4 years ago
|
Future<List<LocalSchemeEntryLinux>> get schemeEntries async {
|
||
4 years ago
|
var _supportDirectory = await getApplicationSupportDirectory();
|
||
4 years ago
|
var directory = Directory(join(_supportDirectory.path, 'schemes'));
|
||
4 years ago
|
if (!directory.existsSync()) directory.createSync();
|
||
|
directory.path.sout();
|
||
|
return directory
|
||
|
.list()
|
||
4 years ago
|
.map<LocalSchemeEntryLinux?>((f) {
|
||
|
LocalSchemeEntryLinux? entry;
|
||
4 years ago
|
try {
|
||
|
var content = File(f.path).readAsStringSync();
|
||
4 years ago
|
entry = LocalSchemeEntryLinux(
|
||
|
path: f.path, scheme: Scheme.parse(content), lastModifyTime: f.statSync().modified);
|
||
4 years ago
|
} catch (e) {
|
||
|
e.sout();
|
||
|
}
|
||
|
return entry;
|
||
|
})
|
||
|
.where((e) => e != null)
|
||
4 years ago
|
.cast<LocalSchemeEntryLinux>()
|
||
4 years ago
|
.toList();
|
||
|
}
|
||
|
|
||
|
@ProviderModelProp()
|
||
4 years ago
|
List<LocalSchemeEntry>? schemes;
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
class LocalSchemeEntryLinux implements LocalSchemeEntry {
|
||
4 years ago
|
@override
|
||
|
String path;
|
||
|
|
||
|
@override
|
||
4 years ago
|
Scheme scheme;
|
||
4 years ago
|
|
||
|
@override
|
||
|
DateTime lastModifyTime;
|
||
|
|
||
4 years ago
|
LocalSchemeEntryLinux({
|
||
4 years ago
|
required this.path,
|
||
4 years ago
|
required this.scheme,
|
||
4 years ago
|
required this.lastModifyTime,
|
||
|
});
|
||
|
|
||
|
@override
|
||
|
save() {
|
||
|
// TODO: implement save
|
||
|
throw UnimplementedError();
|
||
|
}
|
||
|
}
|