From 4943eaef579ed84c8d7c462fa2cfea164d25841f Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sun, 22 Dec 2019 14:20:29 -0800 Subject: [PATCH] Adjust ViewModels in desktop apps. --- .../ViewModels/MainWindowViewModel.cs | 40 +++++++------------ Desktop.Linux/Views/MainWindow.xaml | 2 + Desktop.Win/ViewModels/MainWindowViewModel.cs | 8 +++- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Desktop.Linux/ViewModels/MainWindowViewModel.cs b/Desktop.Linux/ViewModels/MainWindowViewModel.cs index 1977900a..42eeca3b 100644 --- a/Desktop.Linux/ViewModels/MainWindowViewModel.cs +++ b/Desktop.Linux/ViewModels/MainWindowViewModel.cs @@ -149,6 +149,14 @@ namespace Remotely.Desktop.Linux.ViewModels await Conductor.CasterSocket.GetSessionID(); } + public ICommand OpenOptionsMenu => new Executor((param) => + { + if (param is Button) + { + (param as Button).ContextMenu?.Open(param as Button); + } + }); + public async Task PromptForHostName() { var prompt = new HostNamePrompt(); @@ -158,39 +166,21 @@ namespace Remotely.Desktop.Linux.ViewModels } prompt.Owner = MainWindow.Current; await prompt.ShowDialog(MainWindow.Current); - var result = HostNamePromptViewModel.Current.Host.TrimEnd("/".ToCharArray()); + var result = HostNamePromptViewModel.Current.Host; + if (!result.StartsWith("https://") && !result.StartsWith("http://")) + { + result = $"https://{result}"; + } if (result != Host) { - Host = result; + Host = result.TrimEnd('/'); var config = Config.GetConfig(); config.Host = Host; config.Save(); } } - private void Conductor_ClipboardTransferred(object sender, string transferredText) - { - var tempPath = Path.GetTempFileName(); - File.WriteAllText(tempPath, transferredText); - try - { - var psi = new ProcessStartInfo("bash", $"-c \"cat {tempPath} | xclip -i -selection clipboard\"") - { - WindowStyle = ProcessWindowStyle.Hidden - }; - var proc = Process.Start(psi); - proc.WaitForExit(); - - } - catch (Exception ex) - { - Logger.Write(ex); - } - finally - { - File.Delete(tempPath); - } - } + private void ScreenCastRequested(object sender, ScreenCastRequest screenCastRequest) { Dispatcher.UIThread.InvokeAsync(async () => diff --git a/Desktop.Linux/Views/MainWindow.xaml b/Desktop.Linux/Views/MainWindow.xaml index e1a89e64..bd85d817 100644 --- a/Desktop.Linux/Views/MainWindow.xaml +++ b/Desktop.Linux/Views/MainWindow.xaml @@ -75,6 +75,8 @@ VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="10,5" + Command="{Binding OpenOptionsMenu}" + CommandParameter="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}" > diff --git a/Desktop.Win/ViewModels/MainWindowViewModel.cs b/Desktop.Win/ViewModels/MainWindowViewModel.cs index 6aff7e51..a9368df0 100644 --- a/Desktop.Win/ViewModels/MainWindowViewModel.cs +++ b/Desktop.Win/ViewModels/MainWindowViewModel.cs @@ -172,10 +172,14 @@ namespace Remotely.Desktop.Win.ViewModels } prompt.Owner = App.Current?.MainWindow; prompt.ShowDialog(); - var result = HostNamePromptViewModel.Current.Host.TrimEnd("/".ToCharArray()); + var result = HostNamePromptViewModel.Current.Host; + if (!result.StartsWith("https://") && !result.StartsWith("http://")) + { + result = $"https://{result}"; + } if (result != Host) { - Host = result; + Host = result.TrimEnd('/'); var config = Config.GetConfig(); config.Host = Host; config.Save();