mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-10 10:15:34 +01:00
#157 new: icloud sync
This commit is contained in:
@@ -52,3 +52,19 @@ class DockerErr extends Err<DockerErrType> {
|
||||
return 'DockerErr<$type>: $message';
|
||||
}
|
||||
}
|
||||
|
||||
enum ICloudErrType {
|
||||
generic,
|
||||
notFound,
|
||||
multipleFiles,
|
||||
}
|
||||
|
||||
class ICloudErr extends Err<ICloudErrType> {
|
||||
ICloudErr({required ICloudErrType type, String? message})
|
||||
: super(from: ErrFrom.docker, type: type, message: message);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ICloudErr<$type>: $message';
|
||||
}
|
||||
}
|
||||
|
||||
7
lib/data/model/app/json.dart
Normal file
7
lib/data/model/app/json.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
abstract class JsonSerializable<T> {
|
||||
/// Convert [this] to json
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
/// Create [this] from json
|
||||
T fromJson(Map<String, dynamic> json);
|
||||
}
|
||||
9
lib/data/model/app/syncable.dart
Normal file
9
lib/data/model/app/syncable.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
abstract class SyncAble<T> {
|
||||
/// If [other] is newer than [this] then return true,
|
||||
/// else return false
|
||||
bool needSync(T other);
|
||||
|
||||
/// Merge [other] into [this],
|
||||
/// return [this] after merge
|
||||
T merge(T other);
|
||||
}
|
||||
@@ -3,23 +3,43 @@ import 'dart:io';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:toolbox/core/utils/platform.dart';
|
||||
|
||||
Future<Directory> get docDir async {
|
||||
String? _docDir;
|
||||
String? _sftpDir;
|
||||
String? _fontDir;
|
||||
|
||||
Future<String> get docDir async {
|
||||
if (_docDir != null) {
|
||||
return _docDir!;
|
||||
}
|
||||
if (isAndroid) {
|
||||
final dir = await getExternalStorageDirectory();
|
||||
if (dir != null) {
|
||||
return dir;
|
||||
_docDir = dir.path;
|
||||
return dir.path;
|
||||
}
|
||||
// fallthrough to getApplicationDocumentsDirectory
|
||||
}
|
||||
return await getApplicationDocumentsDirectory();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
_docDir = dir.path;
|
||||
return dir.path;
|
||||
}
|
||||
|
||||
Future<Directory> get sftpDir async {
|
||||
final dir = Directory('${(await docDir).path}/sftp');
|
||||
return dir.create(recursive: true);
|
||||
Future<String> get sftpDir async {
|
||||
if (_sftpDir != null) {
|
||||
return _sftpDir!;
|
||||
}
|
||||
_sftpDir = '${await docDir}/sftp';
|
||||
final dir = Directory(_sftpDir!);
|
||||
await dir.create(recursive: true);
|
||||
return _sftpDir!;
|
||||
}
|
||||
|
||||
Future<Directory> get fontDir async {
|
||||
final dir = Directory('${(await docDir).path}/font');
|
||||
return dir.create(recursive: true);
|
||||
Future<String> get fontDir async {
|
||||
if (_fontDir != null) {
|
||||
return _fontDir!;
|
||||
}
|
||||
_fontDir = '${await docDir}/font';
|
||||
final dir = Directory(_fontDir!);
|
||||
await dir.create(recursive: true);
|
||||
return _fontDir!;
|
||||
}
|
||||
|
||||
@@ -198,6 +198,13 @@ class SettingStore extends PersistentStore {
|
||||
false,
|
||||
);
|
||||
|
||||
/// Only valid on iOS and macOS
|
||||
late final icloudSync = StoreProperty(
|
||||
box,
|
||||
'icloudSync',
|
||||
false,
|
||||
);
|
||||
|
||||
// Never show these settings for users
|
||||
// Guide for these settings:
|
||||
// - key should start with `_` and be shorter as possible
|
||||
|
||||
Reference in New Issue
Block a user