import 'package:vnoteapp/architecture/defines.dart';
import 'package:vnoteapp/architecture/utils/prompt_box.dart';
import 'package:vnoteapp/rpc.dart';
import 'state.dart';

class LoginGatewayController extends FControllerBase {
  final state = LoginGatewayState();

  void onSubmit() async {
    try {
      final uri = Uri.parse(state.gateway);
      rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
      rpc.clearCache();
      PromptBox.success("保存成功");
    } catch (e) {
      PromptBox.error("保存失败");
    }
  }

  @override
  void onInit() {
    state.gateway = rpc.currentHostAddress;
    super.onInit();
  }

  @override
  void onReady() {
    //
    super.onReady();
  }

  @override
  void onClose() {
    _doDispose();
    super.onClose();
  }

  void _doDispose() {}
}
