Skip to content

Commit

Permalink
hacked firebase for windows & linux
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen committed Aug 7, 2023
1 parent 9cb8fcb commit 7776bad
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/components/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:Moyubie/components/markdown.dart';
import 'package:Moyubie/controller/chat_room.dart';
import 'package:Moyubie/controller/message.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:Moyubie/firebase_hack.dart';
import 'package:get/get.dart';
import 'package:Moyubie/controller/settings.dart';
import 'dart:async';
Expand Down
2 changes: 1 addition & 1 deletion lib/components/chat_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:Moyubie/data/color.dart';
import 'package:Moyubie/repository/chat_room.dart' as repo;
import 'package:Moyubie/controller/chat_room.dart' as comp;
import 'package:uuid/uuid.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:Moyubie/firebase_hack.dart';
import 'package:flutter/services.dart';

import '../controller/settings.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/components/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:io';
import 'package:dart_openai/dart_openai.dart';
import 'package:dual_screen/dual_screen.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:Moyubie/firebase_hack.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down
22 changes: 22 additions & 0 deletions lib/firebase_hack.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:firebase_analytics/firebase_analytics.dart' as g;

// A really hack way to handle that in unsupported platforms, firebase throws
// exception while calling `FirebaseAnalytics.instance`.
class FirebaseAnalytics {
static dynamic get instance {
try {
return g.FirebaseAnalytics.instance;
} catch (e) {
return Noop();
}
}
}

class Noop {
// So, everything goes noop...
// Thankfully we don't rely on the return value of any firebase methods.
@override
noSuchMethod(Invocation invocation) {
return;
}
}
2 changes: 1 addition & 1 deletion lib/repository/chat_room.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:mysql_client/exception.dart';
import 'package:sqflite/sqflite.dart';
import 'package:Moyubie/utils/tidb.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:Moyubie/firebase_hack.dart';
import 'package:path/path.dart';
import 'package:mysql_client/mysql_client.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
Expand Down

0 comments on commit 7776bad

Please sign in to comment.