Skip to content

Commit

Permalink
Merge pull request #398 from bobs4462/main
Browse files Browse the repository at this point in the history
Minor bug fixes, build 2.2.9+5
  • Loading branch information
bmuddha authored Apr 1, 2021
2 parents 9497ac6 + 75e1a31 commit 1212129
Show file tree
Hide file tree
Showing 32 changed files with 1,219 additions and 816 deletions.
7 changes: 4 additions & 3 deletions android/app/src/main/kotlin/com/twake/twake/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
/* import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService */
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService;

class Application : FlutterApplication(), PluginRegistrantCallback {

override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this);
}

override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
/* GeneratedPluginRegistrant.registerWith(registry); */
}
}
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// Add the google services classpath
classpath 'com.google.gms:google-services:4.3.2'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
1 change: 0 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'


# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ SPEC CHECKSUMS:
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96

PODFILE CHECKSUM: 955a4ce6ca109c044ef3069e126096ea43d23878
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

COCOAPODS: 1.10.1
18 changes: 15 additions & 3 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 6Z27TKCGWF;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -380,8 +382,10 @@
MARKETING_VERSION = 2.2.2;
PRODUCT_BUNDLE_IDENTIFIER = twake;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VERSIONING_SYSTEM = "apple-generic";
};
name = Profile;
Expand Down Expand Up @@ -504,7 +508,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 6Z27TKCGWF;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -523,9 +529,11 @@
MARKETING_VERSION = 2.2.2;
PRODUCT_BUNDLE_IDENTIFIER = twake;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
Expand All @@ -537,7 +545,9 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 1;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 6Z27TKCGWF;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -556,8 +566,10 @@
MARKETING_VERSION = 2.2.2;
PRODUCT_BUNDLE_IDENTIFIER = twake;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1220"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

This file was deleted.

18 changes: 10 additions & 8 deletions lib/blocs/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
// print('CONSOLE LINK: ${repository.twakeConsole}');
if (repository.authMode == 'INTERNAL') return;
this.webView = HeadlessInAppWebView(
initialUrl: repository.twakeConsole,
initialUrlRequest: URLRequest(url: Uri.parse(repository.twakeConsole)),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
cacheEnabled: false,
Expand All @@ -54,18 +54,22 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
// onConsoleMessage: (ctrl, msg) => print('CONSOLEJS: $msg'),
onLoadStop: (ctrl, url) async {
// print('URL: $url');
if (Uri.parse(_prevUrl).path == Uri.parse(url).path) {
if (Uri.parse(_prevUrl).path == url.path) {
this.add(WrongAuthCredentials());
_prevUrl = '';
return;
}
_prevUrl = url;
if (url.contains('redirect_to_app')) {
final qp = Uri.parse(url).queryParameters;
_prevUrl = url.path;
if (url.path.contains('redirect_to_app')) {
final qp = url.queryParameters;
// Logger().d('PARAMS: $qp');
if (qp['token'] == null || qp['username'] == null) {
repository.logger.e('NO TOKEN AND USERNAME');
ctrl.loadUrl(url: repository.twakeConsole);
ctrl.loadUrl(
urlRequest: URLRequest(
url: Uri.parse(repository.twakeConsole),
),
);
this.add(WrongAuthCredentials());
return;
}
Expand Down Expand Up @@ -102,7 +106,6 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
yield Authenticated(initData);
break;
case AuthResult.NetworkError:
// TODO Work out the case with absent network connection
final InitData initData = await initMain();
yield Authenticated(initData);
break;
Expand Down Expand Up @@ -212,7 +215,6 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
return;
}
await CookieManager.instance().deleteAllCookies();
await CookieManager.instance().getCookies(url: 'auth.twake.app');
_prevUrl = '';
await webView.dispose();
// print('Running webview...');
Expand Down
2 changes: 2 additions & 0 deletions lib/blocs/directs_bloc/directs_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class DirectsBloc extends BaseChannelBloc {

@override
Stream<ChannelState> mapEventToState(ChannelsEvent event) async* {
print('Event in DirectsBloc: $event');

if (event is ReloadChannels) {
yield ChannelsLoading();
final filter = {
Expand Down
18 changes: 11 additions & 7 deletions lib/blocs/fields_cubit/fields_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:meta/meta.dart';
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:twake/repositories/fields_repository.dart';
Expand All @@ -8,25 +9,28 @@ class FieldsCubit extends Cubit<FieldsState> {

FieldsCubit(this.repository) : super(FieldsInitial());

void add(Widget field, int index) async {
final result = await repository.add(field, index);
Future<void> add({@required Widget field, @required int atIndex}) async {
final result = await repository.add(field, atIndex);
// print('Current map: ${repository.data}');
emit(Added(fields: result));
}

void remove(int index) async {
final result = await repository.remove(index);
Future<void> remove({@required int atIndex}) async {
final result = await repository.remove(atIndex);
// print('Current map: ${repository.data}');
emit(Removed(fields: result));
}

void update(int index, String content) async {
final result = await repository.updateData(index, content);
Future<void> update({
@required String withContent,
@required int atIndex,
}) async {
final result = await repository.updateData(atIndex, withContent);
// print('Current map: $result');
emit(Updated(data: result));
}

void clear() async {
Future<void> clear() async {
final result = await repository.clear();
emit(
result.isEmpty
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/fields_cubit/fields_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Updated extends FieldsState {
Updated({@required this.data});

@override
List<Object> get props => [fields];
List<Object> get props => [data];

@override
List<Widget> get fields => [];
Expand All @@ -59,7 +59,7 @@ class Error extends FieldsState {
Error(this.message);

@override
List<Object> get props => [];
List<Object> get props => [message];

@override
List<Widget> get fields => [];
Expand Down
43 changes: 27 additions & 16 deletions lib/blocs/notification_bloc/notification_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {

final logger = Logger();
final _api = Api();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;

Map<String, dynamic> subscriptionRooms = {};
StreamSubscription _subscription;
Expand All @@ -58,8 +58,9 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
authBloc.repository.socketIOHost,
IO.OptionBuilder()
.setPath('/socket')
.setTimeout(10000)
.enableAutoConnect()
.disableAutoConnect()
.enableReconnection()
.setTransports(['websocket']).build(),
);
_authSubscription = authBloc.listen((state) {
Expand All @@ -79,17 +80,20 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
});
setupListeners();
if (connectionBloc.state is ConnectionActive) {
socket = socket.connect();
if (socket.disconnected) socket.connect();
}
}

void _iOSpermission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
void _iOSpermission() async {
await _firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}

void setupListeners() {
Expand All @@ -103,12 +107,12 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
socketConnectionState = SocketConnectionState.CONNECTED;
while (socketConnectionState != SocketConnectionState.AUTHENTICATED &&
authBloc.repository.accessToken != null) {
print('AUTHENTICATING SOCKEIO');
if (socket.disconnected) socket = socket.connect();
socket.emit(SocketIOEvent.AUTHENTICATE, {
'token': authBloc.repository.accessToken,
});
await Future.delayed(Duration(seconds: 5));
print('WAITING FOR SOCKET AUTH');
}
});
socket.onError((e) => logger.e('ERROR ON SOCKET \n$e'));
Expand All @@ -125,24 +129,31 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
// logger.d('PING $ping');
// });
socket.on(SocketIOEvent.EVENT, (data) {
logger.d('GOT EVENT: $data');
// logger.d('GOT EVENT: $data');
handleSocketEvent(data);
});
socket.on(SocketIOEvent.RESOURCE, (data) {
logger.d('GOT RESOURCE: $data');
// logger.d('GOT RESOURCE: $data');
handleSocketResource(data);
});
socket.on(SocketIOEvent.JOIN_ERROR, (data) {
logger.d('FAILED TO JOIN: $data');
logger.d('FAILED TO JOIN TO SOCKEIO ROOM: $data');
});
socket.on(SocketIOEvent.JOIN_SUCCESS, (data) {
// logger.d('SUCCESSFUL JOIN: $data');
});
}

void reinit() async {
if (connectionBloc.state is ConnectionLost) return;
if (socket.disconnected) socket = socket.connect();
while (true) {
if (connectionBloc.state is ConnectionLost) return;
if (socket.disconnected) socket = socket.connect();
// Wait for the socket to authenticate;
await Future.delayed(Duration(seconds: 3));
if (this.socketConnectionState == SocketConnectionState.AUTHENTICATED) {
break;
}
}
for (String room in subscriptionRooms.keys) {
unsubscribe(room);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:connectivity/connectivity.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -17,6 +18,7 @@ import 'package:twake/utils/sentry.dart';
void main() async {
runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

final AuthRepository authRepository = await initAuth();
final ConfigurationRepository configurationRepository =
Expand Down
Loading

0 comments on commit 1212129

Please sign in to comment.