Skip to content

Commit

Permalink
files: Cleanup repo and update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
HrX03 committed Mar 6, 2023
1 parent b0753cb commit e41fca1
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 218 deletions.
Binary file removed lib/assets/icons/file.png
Binary file not shown.
Binary file removed lib/assets/icons/folder.png
Binary file not shown.
16 changes: 0 additions & 16 deletions lib/assets/locales/en-US/strings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/backend/database/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 22 additions & 71 deletions lib/backend/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,34 @@ import 'package:files/backend/database/helper.dart';
import 'package:files/backend/database/model.dart';
import 'package:files/backend/folder_provider.dart';
import 'package:files/backend/stat_cache_proxy.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:ubuntu_service/ubuntu_service.dart';

class _ProvidersSingleton {
_ProvidersSingleton._();

bool _inited = false;

late Isar? _isar;
late FolderProvider? _folderProvider;
late EntityStatCacheHelper? _helper;
late StatCacheProxy? _cacheProxy;

Isar get isar {
_checkForAvailability();
return _isar!;
}

FolderProvider get folderProvider {
_checkForAvailability();
return _folderProvider!;
}

EntityStatCacheHelper get helper {
_checkForAvailability();
return _helper!;
}

StatCacheProxy get cacheProxy {
_checkForAvailability();
return _cacheProxy!;
}

void _checkForAvailability() {
if (!_inited) throw Exception("Providers not inited or disposed");
}

static final _ProvidersSingleton instance = _ProvidersSingleton._();

Future<void> _init() async {
if (_inited) return;
WidgetsFlutterBinding.ensureInitialized();
final dir = await getApplicationDocumentsDirectory();
_isar = await Isar.open(
[EntityStatSchema],
directory: isarPath(dir),
);
_folderProvider = await FolderProvider.init();
_helper = EntityStatCacheHelper();
_cacheProxy = StatCacheProxy();
_inited = true;
}

Future<void> _dispose() async {
await isar.close();
_folderProvider = null;
_helper = null;
_cacheProxy = null;
_inited = false;
}

String isarPath(Directory dir) {
final String path = p.join(dir.path, 'isar');
if (!Directory(path).existsSync()) Directory(path).create();
return path;
}
String _isarPath(Directory dir) {
final String path = p.join(dir.path, 'isar');
if (!Directory(path).existsSync()) Directory(path).create();
return path;
}

Future<void> initProviders() async => _ProvidersSingleton.instance._init();

Future<void> disposeProviders() async => _ProvidersSingleton.instance._dispose();
Future<void> initProviders() async {
final dir = await getApplicationDocumentsDirectory();
final isar = await Isar.open(
[EntityStatSchema],
directory: _isarPath(dir),
);
final folderProvider = await FolderProvider.init();

registerServiceInstance<Isar>(isar);
registerServiceInstance<FolderProvider>(folderProvider);
registerService<EntityStatCacheHelper>(EntityStatCacheHelper.new);
registerService<StatCacheProxy>(StatCacheProxy.new);
}

Isar get isar => _ProvidersSingleton.instance.isar;
Isar get isar => getService<Isar>();

FolderProvider get folderProvider => _ProvidersSingleton.instance.folderProvider;
FolderProvider get folderProvider => getService<FolderProvider>();

EntityStatCacheHelper get helper => _ProvidersSingleton.instance.helper;
EntityStatCacheHelper get helper => getService<EntityStatCacheHelper>();

StatCacheProxy get cacheProxy => _ProvidersSingleton.instance.cacheProxy;
StatCacheProxy get cacheProxy => getService<StatCacheProxy>();
13 changes: 2 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//credits: @HrX03 for basic UI https://github.com/HrX03/Flux

import 'dart:async';

import 'package:animations/animations.dart';
import 'package:files/backend/providers.dart';
import 'package:files/backend/utils.dart';
Expand All @@ -27,18 +23,13 @@ import 'package:files/widgets/tab_strip.dart';
import 'package:files/widgets/workspace.dart';
import 'package:flutter/material.dart';

// ignore: avoid_void_async
void main() async {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await init();
await initProviders();

runApp(const Files());
}

Future<void> init() async {
await initProviders();
}

class Files extends StatelessWidget {
const Files({super.key});

Expand Down
Loading

0 comments on commit e41fca1

Please sign in to comment.