public ConnectedViewModel(Action OnDisconnect) { homeTab = new(); imagesTab = new(); profileTab = new(); postTab = new(() => VM = profileTab); settingsTab = new(OnDisconnect); _vm = homeTab; HomeTab = new RelayCommand((object?_) => { VM = homeTab; }); PostTab = new RelayCommand((object?_) => { VM = postTab; }); ImagesTab = new RelayCommand((object?_) => { VM = imagesTab; }); ProfileTab = new RelayCommand((object?_) => { VM = profileTab; }); SettingsTab = new RelayCommand((object?_) => { VM = settingsTab; }); }
public async void OnConnect(string folder, IPEndPoint endpoint) { var file = Path.Combine(folder, "client.identity"); PrivateIdentity identity; if (!Env.CheckFile(file)) { if (!Env.Confirm($"No identity was found at {file}. Do you want to create a new one?")) { return; } identity = PrivateIdentity.Create(); var hex = Transcoder.HexFromBytes(PrivateIdentity.Export(identity)); await Env.WriteFile(file, hex); } else { var hex = Transcoder.BytesFromHex(await Env.ReadFile(file)); var result = PrivateIdentity.Import(hex); if (result.IsError) { Env.Alert("Could not load identity!!"); return; } identity = result.Value; } APITranslatorClient nodeConnection; try { nodeConnection = await APITranslatorClient.CreateAndConnect(new APITranslatorClient.ConnectionArgs { Self = identity, ServerID = identity.ID, Address = endpoint.Address, Port = endpoint.Port }); } catch { Env.Alert("Unable to connect to your node!"); return; } Resources = new ResourceManager(identity, nodeConnection, OnDisconnect); VM = new ConnectedViewModel(OnDisconnect); }
public void OnDisconnect() { VM = startup; Resources.Dispose(); }
public ViewModel() { _vm = startup = new StartupViewModel(OnConnect, OnQuit); }