avoid currentUser call more than once when initializing app
This commit is contained in:
parent
5831db260f
commit
20db4bed01
@ -253,7 +253,8 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
width: 8,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: svcStopped.value || stateGlobal.svcStatus.value == SvcStatus.connecting
|
||||
color: svcStopped.value ||
|
||||
stateGlobal.svcStatus.value == SvcStatus.connecting
|
||||
? kColorWarn
|
||||
: (stateGlobal.svcStatus.value == SvcStatus.ready
|
||||
? Color.fromARGB(255, 50, 190, 166)
|
||||
|
@ -33,9 +33,6 @@ int? kWindowId;
|
||||
WindowType? kWindowType;
|
||||
late List<String> kBootArgs;
|
||||
|
||||
/// Uni links.
|
||||
StreamSubscription? _uniLinkSubscription;
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
debugPrint("launch args: $args");
|
||||
@ -123,7 +120,6 @@ void runMainApp(bool startService) async {
|
||||
// trigger connection status updater
|
||||
await bind.mainCheckConnectStatus();
|
||||
if (startService) {
|
||||
// await windowManager.ensureInitialized();
|
||||
gFFI.serverModel.startService();
|
||||
bind.pluginSyncUi(syncTo: kAppTypeMain);
|
||||
bind.pluginListReload();
|
||||
@ -229,7 +225,7 @@ void runConnectionManagerScreen(bool hide) async {
|
||||
await showCmWindow(isStartup: true);
|
||||
}
|
||||
// Start the uni links handler and redirect links to Native, not for Flutter.
|
||||
_uniLinkSubscription = listenUniLinks(handleByFlutter: false);
|
||||
listenUniLinks(handleByFlutter: false);
|
||||
}
|
||||
|
||||
showCmWindow({bool isStartup = false}) async {
|
||||
|
@ -10,6 +10,8 @@ import '../common.dart';
|
||||
import 'model.dart';
|
||||
import 'platform_model.dart';
|
||||
|
||||
bool refresing_user = false;
|
||||
|
||||
class UserModel {
|
||||
final RxString userName = ''.obs;
|
||||
final RxBool isAdmin = false.obs;
|
||||
@ -29,13 +31,16 @@ class UserModel {
|
||||
'id': await bind.mainGetMyId(),
|
||||
'uuid': await bind.mainGetUuid()
|
||||
};
|
||||
if (refresing_user) return;
|
||||
try {
|
||||
refresing_user = true;
|
||||
final response = await http.post(Uri.parse('$url/api/currentUser'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token'
|
||||
},
|
||||
body: json.encode(body));
|
||||
refresing_user = false;
|
||||
final status = response.statusCode;
|
||||
if (status == 401 || status == 400) {
|
||||
reset();
|
||||
@ -52,6 +57,7 @@ class UserModel {
|
||||
} catch (e) {
|
||||
debugPrint('Failed to refreshCurrentUser: $e');
|
||||
} finally {
|
||||
refresing_user = false;
|
||||
await updateOtherModels();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user