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