Adjust ViewModels in desktop apps.

This commit is contained in:
Jared Goodwin 2019-12-22 14:20:29 -08:00
parent b6432d1981
commit 4943eaef57
3 changed files with 23 additions and 27 deletions

View File

@ -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 () =>

View File

@ -75,6 +75,8 @@
VerticalContentAlignment="Stretch"
HorizontalContentAlignment="Stretch"
Margin="10,5"
Command="{Binding OpenOptionsMenu}"
CommandParameter="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}"
>
<Button.ContextMenu>
<ContextMenu>

View File

@ -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();