115 lines
4.0 KiB
Dart
115 lines
4.0 KiB
Dart
import 'package:cwtch/notification_manager.dart';
|
|
import 'package:cwtch/widgets/rightshiftfixer.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:cwtch/cwtch/ffi.dart';
|
|
import 'package:cwtch/cwtch/gomobile.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:cwtch/errorHandler.dart';
|
|
import 'package:cwtch/settings.dart';
|
|
import 'package:cwtch/torstatus.dart';
|
|
import 'package:cwtch/views/triplecolview.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'cwtch/cwtch.dart';
|
|
import 'cwtch/cwtchNotifier.dart';
|
|
import 'licenses.dart';
|
|
import 'model.dart';
|
|
import 'views/profilemgrview.dart';
|
|
import 'views/splashView.dart';
|
|
import 'dart:io' show Platform;
|
|
import 'opaque.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
var globalSettings = Settings(Locale("en", ''), Opaque.dark);
|
|
var globalErrorHandler = ErrorHandler();
|
|
var globalTorStatus = TorStatus();
|
|
|
|
void main() {
|
|
LicenseRegistry.addLicense(() => licenses());
|
|
runApp(Flwtch());
|
|
}
|
|
|
|
class Flwtch extends StatefulWidget {
|
|
final Key flwtch = GlobalKey();
|
|
|
|
@override
|
|
FlwtchState createState() => FlwtchState();
|
|
}
|
|
|
|
class FlwtchState extends State<Flwtch> {
|
|
final TextStyle biggerFont = const TextStyle(fontSize: 18);
|
|
late Cwtch cwtch;
|
|
bool cwtchInit = false;
|
|
late ProfileInfoState selectedProfile;
|
|
String selectedConversation = "";
|
|
var columns = [1]; // default or 'single column' mode
|
|
//var columns = [1, 1, 2];
|
|
late ProfileListState profs;
|
|
|
|
@override
|
|
initState() {
|
|
super.initState();
|
|
cwtchInit = false;
|
|
|
|
profs = ProfileListState();
|
|
|
|
if (Platform.isAndroid) {
|
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager());
|
|
cwtch = CwtchGomobile(cwtchNotifier);
|
|
} else if (Platform.isLinux) {
|
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, LinuxNotificationsManager());
|
|
cwtch = CwtchFfi(cwtchNotifier);
|
|
} else {
|
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager());
|
|
cwtch = CwtchFfi(cwtchNotifier);
|
|
}
|
|
|
|
cwtch.Start().then((val) {
|
|
setState(() {
|
|
cwtchInit = true;
|
|
});
|
|
});
|
|
}
|
|
|
|
ChangeNotifierProvider<TorStatus> getTorStatusProvider() => ChangeNotifierProvider.value(value: globalTorStatus);
|
|
ChangeNotifierProvider<ErrorHandler> getErrorHandlerProvider() => ChangeNotifierProvider.value(value: globalErrorHandler);
|
|
ChangeNotifierProvider<Settings> getSettingsProvider() => ChangeNotifierProvider.value(value: globalSettings);
|
|
Provider<FlwtchState> getFlwtchStateProvider() => Provider<FlwtchState>(create: (_) => this);
|
|
ChangeNotifierProvider<ProfileListState> getProfileListProvider() => ChangeNotifierProvider(create: (context) => profs);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
//appStatus = AppModel(cwtch: cwtch);
|
|
globalSettings.initPackageInfo();
|
|
return MultiProvider(
|
|
providers: [
|
|
getFlwtchStateProvider(),
|
|
getProfileListProvider(),
|
|
getSettingsProvider(),
|
|
getErrorHandlerProvider(),
|
|
getTorStatusProvider(),
|
|
],
|
|
builder: (context, widget) {
|
|
return Consumer<Settings>(
|
|
builder: (context, settings, child) => MaterialApp(
|
|
key: Key('app'),
|
|
locale: settings.locale,
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
title: 'Cwtch',
|
|
theme: mkThemeData(settings),
|
|
// from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(),
|
|
// from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(),
|
|
home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ShiftRightFixer(child: ProfileMgrView())) : SplashView(),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
cwtch.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|