mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Working on desktop app.
This commit is contained in:
parent
68dd3b7dcf
commit
7eff414f0d
@ -1,6 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@ -2,7 +2,7 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Remotely_Desktop"
|
||||
StartupUri="MainWindow.xaml">
|
||||
StartupUri="MainWindow.xaml" Exit="Application_Exit">
|
||||
<Application.Resources>
|
||||
<Style x:Key="TitlebarButton" TargetType="Button">
|
||||
<Setter Property="DockPanel.Dock" Value="Right"></Setter>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Remotely_Desktop.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
@ -13,5 +14,12 @@ namespace Remotely_Desktop
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
private void Application_Exit(object sender, ExitEventArgs e)
|
||||
{
|
||||
if (MainWindowViewModel.Current?.ScreenCasterProcess?.HasExited == false)
|
||||
{
|
||||
MainWindowViewModel.Current.ScreenCasterProcess.Kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
Remotely_Desktop/Controls/HostNamePrompt.xaml
Normal file
18
Remotely_Desktop/Controls/HostNamePrompt.xaml
Normal file
@ -0,0 +1,18 @@
|
||||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Remotely_Desktop.Controls"
|
||||
xmlns:ViewModels="clr-namespace:Remotely_Desktop.ViewModels" x:Name="PromptWindow" x:Class="Remotely_Desktop.Controls.HostNamePrompt"
|
||||
mc:Ignorable="d"
|
||||
Title="Remotely Host Name" Height="150" Width="350" Icon="/Remotely_Desktop;component/favicon.ico" WindowStartupLocation="CenterOwner">
|
||||
<Window.DataContext>
|
||||
<ViewModels:HostNamePromptViewModel/>
|
||||
</Window.DataContext>
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock Margin="0,0,0,5" Style="{StaticResource SectionHeader}"><Run Text="Enter the server URL:"/></TextBlock>
|
||||
<TextBox x:Name="HostTextBox" Height="25" Text="{Binding Host, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Button Style="{StaticResource NormalButton}" HorizontalAlignment="Right" Width="40" Height="30" Margin="0,5,0,0" IsDefault="True" Click="OKButton_Click" Content="OK"/>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
34
Remotely_Desktop/Controls/HostNamePrompt.xaml.cs
Normal file
34
Remotely_Desktop/Controls/HostNamePrompt.xaml.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Remotely_Desktop.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Remotely_Desktop.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for HostNamePrompt.xaml
|
||||
/// </summary>
|
||||
public partial class HostNamePrompt : Window
|
||||
{
|
||||
public HostNamePrompt()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new HostNamePromptViewModel();
|
||||
}
|
||||
|
||||
private void OKButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,47 +6,57 @@
|
||||
xmlns:local="clr-namespace:Remotely_Desktop"
|
||||
xmlns:ViewModels="clr-namespace:Remotely_Desktop.ViewModels" x:Class="Remotely_Desktop.MainWindow"
|
||||
mc:Ignorable="d"
|
||||
Title="Remotely" Height="350" Width="400" MouseLeftButtonDown="Window_MouseLeftButtonDown" WindowStyle="None" ResizeMode="NoResize" Icon="favicon.ico">
|
||||
Title="Remotely" Height="250" Width="350" MouseLeftButtonDown="Window_MouseLeftButtonDown" WindowStyle="None" ResizeMode="NoResize" Icon="favicon.ico" Loaded="Window_Loaded">
|
||||
<Window.DataContext>
|
||||
<ViewModels:MainWindowViewModel/>
|
||||
</Window.DataContext>
|
||||
<StackPanel>
|
||||
<Border Height="50" Background="#FF535353">
|
||||
<DockPanel Margin="10,0,0,0">
|
||||
<StackPanel>
|
||||
<TextBlock Foreground="DeepSkyBlue" FontWeight="Bold" FontSize="20" Margin="0,2,0,0">Remotely</TextBlock>
|
||||
<TextBlock Foreground="White" FontSize="10"><Run Text="Do IT Remotely"/></TextBlock>
|
||||
</StackPanel>
|
||||
<Button Style="{StaticResource TitlebarButton}" Click="CloseButton_Click" Content="X"/>
|
||||
<Button Style="{StaticResource TitlebarButton}" Click="MinimizeButton_Click" Content="_"/>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
<Grid Margin="10,15,10,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" Margin="0,0,15,0">
|
||||
<TextBlock Style="{StaticResource SectionHeader}"><Run Text="Share Screen"/></TextBlock>
|
||||
<TextBlock FontSize="16" Margin="0,10,0,5"><Run Text="Your Session ID:"/></TextBlock>
|
||||
<TextBox FontSize="16" Text="{Binding SessionID}" IsReadOnly="True"/>
|
||||
<Grid Margin="0,10,0,0">
|
||||
<TextBlock VerticalAlignment="Center">
|
||||
<Grid>
|
||||
<StackPanel>
|
||||
<Border Height="50" Background="#FF535353">
|
||||
<DockPanel Margin="10,0,0,0">
|
||||
<StackPanel>
|
||||
<TextBlock Foreground="DeepSkyBlue" FontWeight="Bold" FontSize="20" Margin="0,2,0,0">Remotely</TextBlock>
|
||||
<TextBlock Foreground="White" FontSize="10"><Run Text="Do IT Remotely"/></TextBlock>
|
||||
</StackPanel>
|
||||
<Button Style="{StaticResource TitlebarButton}" Click="CloseButton_Click" Content="X"/>
|
||||
<Button Style="{StaticResource TitlebarButton}" Click="MinimizeButton_Click" Content="_"/>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
<Grid Margin="10,15,10,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Grid.Column="0" Margin="0,0,15,0">
|
||||
<TextBlock Style="{StaticResource SectionHeader}"><Run Text="Share Screen"/></TextBlock>
|
||||
<TextBlock FontSize="16" Margin="0,10,0,5"><Run Text="Your Session ID:"/></TextBlock>
|
||||
<TextBox FontSize="16" Text="{Binding SessionID}" IsReadOnly="True"/>
|
||||
<Grid Margin="0,10,0,0">
|
||||
<TextBlock VerticalAlignment="Center">
|
||||
Invite Link:
|
||||
</TextBlock>
|
||||
<Button HorizontalAlignment="Right" Style="{StaticResource NormalButton}" Width="50" Height="25">
|
||||
Copy
|
||||
</Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Margin="15,0,0,0">
|
||||
<TextBlock Style="{StaticResource SectionHeader}"><Run Text="Viewers"/></TextBlock>
|
||||
<ListBox Height="200" Margin="0,5,0,0" ItemsSource="{Binding Viewers}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate/>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</TextBlock>
|
||||
<Button HorizontalAlignment="Right" Style="{StaticResource NormalButton}" Width="50" Height="25" Click="CopyLinkButton_Click">
|
||||
Copy
|
||||
</Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Margin="15,0,0,0">
|
||||
<TextBlock Style="{StaticResource SectionHeader}"><Run Text="Viewers"/></TextBlock>
|
||||
<ListBox Height="90" Margin="0,5,0,0" ItemsSource="{Binding Viewers}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate/>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<DockPanel VerticalAlignment="Bottom" Margin="10,5">
|
||||
<TextBlock FontSize="10">
|
||||
<Run>Connected to: </Run>
|
||||
<Hyperlink Click="HostHyperlink_Click">
|
||||
<TextBlock Text="{Binding Host}"></TextBlock>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@ -6,10 +6,12 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
@ -32,11 +34,6 @@ namespace Remotely_Desktop
|
||||
DragMove();
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Current.Shutdown();
|
||||
@ -46,5 +43,33 @@ namespace Remotely_Desktop
|
||||
{
|
||||
this.WindowState = WindowState.Minimized;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
(DataContext as MainWindowViewModel).Init();
|
||||
}
|
||||
|
||||
private void HostHyperlink_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MainWindowViewModel.Current.PromptForHostName();
|
||||
MainWindowViewModel.Current.Init();
|
||||
}
|
||||
|
||||
private async void CopyLinkButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MainWindowViewModel.Current.CopyLink();
|
||||
var tooltip = new ToolTip();
|
||||
tooltip.PlacementTarget = sender as Button;
|
||||
tooltip.Placement = PlacementMode.Bottom;
|
||||
tooltip.VerticalOffset = 5;
|
||||
tooltip.Content = "Copied to clipboard!";
|
||||
tooltip.HasDropShadow = true;
|
||||
tooltip.StaysOpen = false;
|
||||
tooltip.IsOpen = true;
|
||||
|
||||
await Task.Delay(750);
|
||||
var animation = new DoubleAnimation(0, TimeSpan.FromMilliseconds(750));
|
||||
tooltip.BeginAnimation(OpacityProperty, animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,9 +72,18 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Controls\HostNamePrompt.xaml.cs">
|
||||
<DependentUpon>HostNamePrompt.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Services\Config.cs" />
|
||||
<Compile Include="Services\IPC.cs" />
|
||||
<Compile Include="Services\Logger.cs" />
|
||||
<Compile Include="ViewModels\HostNamePromptViewModel.cs" />
|
||||
<Compile Include="ViewModels\MainWindowViewModel.cs" />
|
||||
<Page Include="Controls\HostNamePrompt.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
@ -125,7 +134,12 @@
|
||||
<ItemGroup>
|
||||
<Resource Include="favicon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Remotely_ScreenCast\Remotely_ScreenCast.csproj">
|
||||
<Project>{2dcea1f5-9b64-4edb-9cd0-4d6675d96709}</Project>
|
||||
<Name>Remotely_ScreenCast</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
|
||||
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -13,17 +13,16 @@ namespace Remotely_Desktop.Services
|
||||
{
|
||||
private static string ConfigFolder => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Remotely");
|
||||
private static string ConfigFile => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Remotely", "Config.json");
|
||||
|
||||
|
||||
public static Config GetConfig()
|
||||
{
|
||||
if (Directory.Exists(ConfigFolder))
|
||||
if (!Directory.Exists(ConfigFolder))
|
||||
{
|
||||
return new Config();
|
||||
}
|
||||
|
||||
if (File.Exists(ConfigFile))
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(Config));
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<Config>(File.ReadAllText(ConfigFile));
|
||||
@ -36,11 +35,12 @@ namespace Remotely_Desktop.Services
|
||||
return new Config();
|
||||
}
|
||||
|
||||
public static void SaveConfig(Config config)
|
||||
public void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(ConfigFile, JsonConvert.SerializeObject(config));
|
||||
Directory.CreateDirectory(ConfigFolder);
|
||||
File.WriteAllText(ConfigFile, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
23
Remotely_Desktop/Services/IPC.cs
Normal file
23
Remotely_Desktop/Services/IPC.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace Remotely_Desktop.Services
|
||||
{
|
||||
public class IPC
|
||||
{
|
||||
internal void OutputDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal void ErrorDataReceived(object sender, DataReceivedEventArgs e)
|
||||
{
|
||||
MessageBox.Show(e.Data, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Remotely_Desktop/ViewModels/HostNamePromptViewModel.cs
Normal file
21
Remotely_Desktop/ViewModels/HostNamePromptViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Remotely_Desktop.ViewModels
|
||||
{
|
||||
public class HostNamePromptViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public static HostNamePromptViewModel Current { get; private set; }
|
||||
public HostNamePromptViewModel()
|
||||
{
|
||||
Current = this;
|
||||
}
|
||||
public string Host { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
@ -1,27 +1,128 @@
|
||||
using Remotely_Desktop.Models;
|
||||
using Remotely_Desktop.Controls;
|
||||
using Remotely_Desktop.Models;
|
||||
using Remotely_Desktop.Services;
|
||||
using Remotely_ScreenCast.Models;
|
||||
using Remotely_ScreenCast.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Viewer = Remotely_Desktop.Models.Viewer;
|
||||
|
||||
namespace Remotely_Desktop.ViewModels
|
||||
{
|
||||
public class MainWindowViewModel
|
||||
public class MainWindowViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public ObservableCollection<Viewer> Viewers { get; set; }
|
||||
public string SessionID { get; set; } = "Retrieving...";
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
Current = this;
|
||||
}
|
||||
|
||||
private Process LaunchScreenCaster()
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public static MainWindowViewModel Current { get; private set; }
|
||||
public Config Config { get; private set; }
|
||||
public string Host
|
||||
{
|
||||
get
|
||||
{
|
||||
return Config?.Host;
|
||||
}
|
||||
}
|
||||
|
||||
public IPC IPC { get; set; } = new IPC();
|
||||
public Process ScreenCasterProcess { get; set; }
|
||||
public string SessionID { get; set; } = "Retrieving...";
|
||||
public ObservableCollection<Viewer> Viewers { get; set; }
|
||||
public void FirePropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var filePath = ExtractScreenCasterEXE();
|
||||
return Process.Start(filePath, $"-mode Normal -host {Config.GetConfig().Host}");
|
||||
Config = Config.GetConfig();
|
||||
while (string.IsNullOrWhiteSpace(Config.Host))
|
||||
{
|
||||
PromptForHostName();
|
||||
}
|
||||
var psi = new ProcessStartInfo()
|
||||
{
|
||||
FileName = filePath,
|
||||
Arguments = $"-mode Normal -host {Config.Host}",
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
MessageHandlers.SessionIDChanged += SessionIDChanged;
|
||||
MessageHandlers.ViewerRemoved += ViewerRemoved;
|
||||
MessageHandlers.ViewerAdded += ViewerAdded;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
Remotely_ScreenCast.Program.Main(new string[] { "-mode", "Normal", "-host", Config.Host });
|
||||
});
|
||||
//ScreenCasterProcess = new Process();
|
||||
//ScreenCasterProcess.StartInfo = psi;
|
||||
//ScreenCasterProcess.OutputDataReceived += IPC.OutputDataReceived;
|
||||
//ScreenCasterProcess.ErrorDataReceived += IPC.ErrorDataReceived;
|
||||
//ScreenCasterProcess.Exited += ScreenCasterProcess_Exited;
|
||||
//ScreenCasterProcess.Start();
|
||||
}
|
||||
|
||||
private void ViewerAdded(object sender, Remotely_ScreenCast.Models.Viewer viewer)
|
||||
{
|
||||
Viewers.Add(new Viewer()
|
||||
{
|
||||
ConnectionId = viewer.ViewerConnectionID,
|
||||
HasControl = true,
|
||||
Name = viewer.Name
|
||||
});
|
||||
}
|
||||
|
||||
private void ViewerRemoved(object sender, string viewerID)
|
||||
{
|
||||
var viewer = Viewers.FirstOrDefault(x => x.ConnectionId == viewerID);
|
||||
if (viewer != null)
|
||||
{
|
||||
Viewers.Remove(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
internal void CopyLink()
|
||||
{
|
||||
Clipboard.SetText($"{Host}/RemoteControl?sessionID={SessionID.Replace(" ", "")}");
|
||||
}
|
||||
|
||||
public void PromptForHostName()
|
||||
{
|
||||
var prompt = new HostNamePrompt();
|
||||
if (!string.IsNullOrWhiteSpace(Config.Host))
|
||||
{
|
||||
HostNamePromptViewModel.Current.Host = Config.Host;
|
||||
}
|
||||
prompt.Owner = App.Current?.MainWindow;
|
||||
prompt.ShowDialog();
|
||||
var result = HostNamePromptViewModel.Current.Host.TrimEnd("/".ToCharArray());
|
||||
if (result != Config.Host)
|
||||
{
|
||||
Config.Host = result;
|
||||
Config.Save();
|
||||
FirePropertyChanged("Host");
|
||||
}
|
||||
}
|
||||
|
||||
private string ExtractScreenCasterEXE()
|
||||
{
|
||||
// Cleanup old files.
|
||||
@ -53,5 +154,21 @@ namespace Remotely_Desktop.ViewModels
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private void ScreenCasterProcess_Exited(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("The screen sharing process has stopped unexpectedly. Remotely will now close.", "Sharing Stopped", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
App.Current.Shutdown();
|
||||
}
|
||||
|
||||
private void SessionIDChanged(object sender, string sessionID)
|
||||
{
|
||||
var formattedSessionID = "";
|
||||
for (var i = 0; i < sessionID.Length; i += 3)
|
||||
{
|
||||
formattedSessionID += sessionID.Substring(i, 3) + " ";
|
||||
}
|
||||
SessionID = formattedSessionID.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ namespace Remotely_ScreenCast.Capture
|
||||
DisconnectRequested = false,
|
||||
Name = requesterName,
|
||||
ViewerConnectionID = viewerID,
|
||||
HasControl = Program.Mode == Enums.AppMode.Unattended,
|
||||
HasControl = true,
|
||||
ImageQuality = 1
|
||||
};
|
||||
|
||||
|
||||
@ -32,18 +32,21 @@ namespace Remotely_ScreenCast
|
||||
public static string CurrentDesktopName { get; set; }
|
||||
public static ConcurrentDictionary<string, Viewer> Viewers { get; } = new ConcurrentDictionary<string, Viewer>();
|
||||
|
||||
static void Main(string[] args)
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
var argDict = ProcessArgs(args);
|
||||
Mode = (AppMode)Enum.Parse(typeof(AppMode), argDict["mode"]);
|
||||
RequesterID = argDict["requester"];
|
||||
Host = argDict["host"];
|
||||
CurrentDesktopName = argDict["desktop"];
|
||||
ServiceID = argDict["serviceid"];
|
||||
|
||||
if (Mode == AppMode.Unattended)
|
||||
{
|
||||
RequesterID = argDict["requester"];
|
||||
CurrentDesktopName = argDict["desktop"];
|
||||
ServiceID = argDict["serviceid"];
|
||||
}
|
||||
|
||||
Connection = new HubConnectionBuilder()
|
||||
.WithUrl($"{Host}/RCDeviceHub")
|
||||
@ -54,50 +57,59 @@ namespace Remotely_ScreenCast
|
||||
|
||||
OutgoingMessages = new OutgoingMessages(Connection);
|
||||
|
||||
OutgoingMessages.SendServiceID(ServiceID).Wait();
|
||||
|
||||
var desktopName = Win32Interop.GetCurrentDesktop();
|
||||
if (desktopName.ToLower() != CurrentDesktopName.ToLower())
|
||||
{
|
||||
CurrentDesktopName = desktopName;
|
||||
Logger.Write($"Setting initial desktop to {desktopName}.");
|
||||
argDict["desktop"] = desktopName;
|
||||
var openProcessString = Assembly.GetExecutingAssembly().Location;
|
||||
foreach (var arg in argDict)
|
||||
{
|
||||
openProcessString += $" -{arg.Key} {arg.Value}";
|
||||
}
|
||||
var result = Win32Interop.OpenInteractiveProcess(openProcessString, desktopName, true, out _);
|
||||
if (!result)
|
||||
{
|
||||
Logger.Write($"Desktop relaunch to {desktopName} failed.");
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
MessageHandlers.ApplyConnectionHandlers(Connection, OutgoingMessages);
|
||||
|
||||
CursorIconWatcher.Current.OnChange += CursorIconWatcher_OnChange;
|
||||
|
||||
if (argDict.ContainsKey("relaunch"))
|
||||
if (Mode == AppMode.Unattended)
|
||||
{
|
||||
Logger.Write($"Resuming after relaunch in desktop {desktopName}.");
|
||||
var viewersString = argDict["viewers"];
|
||||
var viewerIDs = viewersString.Split(",".ToCharArray());
|
||||
OutgoingMessages.NotifyViewersRelaunchedScreenCasterReady(viewerIDs).Wait();
|
||||
OutgoingMessages.SendServiceID(ServiceID).Wait();
|
||||
|
||||
var desktopName = Win32Interop.GetCurrentDesktop();
|
||||
if (desktopName.ToLower() != CurrentDesktopName.ToLower())
|
||||
{
|
||||
CurrentDesktopName = desktopName;
|
||||
Logger.Write($"Setting initial desktop to {desktopName}.");
|
||||
argDict["desktop"] = desktopName;
|
||||
var openProcessString = Assembly.GetExecutingAssembly().Location;
|
||||
foreach (var arg in argDict)
|
||||
{
|
||||
openProcessString += $" -{arg.Key} {arg.Value}";
|
||||
}
|
||||
var result = Win32Interop.OpenInteractiveProcess(openProcessString, desktopName, true, out _);
|
||||
if (!result)
|
||||
{
|
||||
Logger.Write($"Desktop relaunch to {desktopName} failed.");
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
if (argDict.ContainsKey("relaunch"))
|
||||
{
|
||||
Logger.Write($"Resuming after relaunch in desktop {CurrentDesktopName}.");
|
||||
var viewersString = argDict["viewers"];
|
||||
var viewerIDs = viewersString.Split(",".ToCharArray());
|
||||
OutgoingMessages.NotifyViewersRelaunchedScreenCasterReady(viewerIDs).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
OutgoingMessages.NotifyRequesterUnattendedReady(RequesterID).Wait();
|
||||
}
|
||||
|
||||
StartWaitForViewerTimer();
|
||||
}
|
||||
else
|
||||
else if (Mode == AppMode.Normal)
|
||||
{
|
||||
OutgoingMessages.NotifyRequesterUnattendedReady(RequesterID).Wait();
|
||||
OutgoingMessages.GetSessionID().Wait();
|
||||
}
|
||||
|
||||
StartWaitForViewerTimer();
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (Mode == AppMode.Unattended)
|
||||
{
|
||||
desktopName = Win32Interop.GetCurrentDesktop();
|
||||
var desktopName = Win32Interop.GetCurrentDesktop();
|
||||
if (desktopName.ToLower() != CurrentDesktopName.ToLower() && Viewers.Count > 0)
|
||||
{
|
||||
CurrentDesktopName = desktopName;
|
||||
@ -114,12 +126,8 @@ namespace Remotely_ScreenCast
|
||||
OutgoingMessages.SendConnectionFailedToViewers(Viewers.Keys.ToList()).Wait();
|
||||
}
|
||||
}
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Read();
|
||||
}
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -152,6 +160,10 @@ namespace Remotely_ScreenCast
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Logger.Write((Exception)e.ExceptionObject);
|
||||
if (Console.IsErrorRedirected)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ProcessArgs(string[] args)
|
||||
|
||||
@ -69,6 +69,9 @@
|
||||
<Reference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNetCore.SignalR.Protocols.MessagePack.1.1.0\lib\netstandard2.0\Microsoft.AspNetCore.SignalR.Protocols.MessagePack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Expression.Encoder, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86">
|
||||
<HintPath>..\packages\Microsoft.Expression.Encoder.4.0.4276.3\lib\net45\Microsoft.Expression.Encoder.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
@ -182,8 +185,10 @@
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent>if $(ConfigurationName) == Debug (
|
||||
copy /y "$(TargetPath)" "$(SolutionDir)Remotely_Agent\Resources\"
|
||||
copy /y "$(TargetPath)" "$(SolutionDir)Remotely_Desktop\Resources\"
|
||||
)</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\packages\Fody.4.0.2\build\Fody.targets" Condition="Exists('..\packages\Fody.4.0.2\build\Fody.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@ -12,6 +12,7 @@ using Win32;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using Remotely_ScreenCast.Models;
|
||||
|
||||
namespace Remotely_ScreenCast.Sockets
|
||||
{
|
||||
@ -31,6 +32,10 @@ namespace Remotely_ScreenCast.Sockets
|
||||
try
|
||||
{
|
||||
ScreenCaster.BeginScreenCasting(viewerID, requesterName, outgoingMessages);
|
||||
if (Program.Viewers.TryGetValue(viewerID, out var viewer))
|
||||
{
|
||||
ViewerAdded?.Invoke(null, viewer);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -168,6 +173,8 @@ namespace Remotely_ScreenCast.Sockets
|
||||
viewer.DisconnectRequested = true;
|
||||
}
|
||||
await hubConnection.InvokeAsync("ViewerDisconnected", viewerID);
|
||||
ViewerRemoved?.Invoke(null, viewerID);
|
||||
|
||||
});
|
||||
hubConnection.On("LatencyUpdate", (double latency, string viewerID) =>
|
||||
{
|
||||
@ -178,18 +185,6 @@ namespace Remotely_ScreenCast.Sockets
|
||||
}
|
||||
});
|
||||
|
||||
hubConnection.On("SessionID", (string sessionID) =>
|
||||
{
|
||||
var formattedSessionID = "";
|
||||
for (var i = 0; i < sessionID.Length; i += 3)
|
||||
{
|
||||
formattedSessionID += sessionID.Substring(i, 3) + " ";
|
||||
}
|
||||
|
||||
// TODO: Send to desktop app.
|
||||
formattedSessionID.Trim();
|
||||
});
|
||||
|
||||
hubConnection.On("SelectScreen", (int screenIndex, string viewerID) =>
|
||||
{
|
||||
if (Program.Viewers.TryGetValue(viewerID, out var viewer))
|
||||
@ -264,6 +259,14 @@ namespace Remotely_ScreenCast.Sockets
|
||||
Process.Start("explorer.exe", dirPath);
|
||||
});
|
||||
});
|
||||
|
||||
hubConnection.On("SessionID", (string sessionID) =>
|
||||
{
|
||||
SessionIDChanged?.Invoke(null, sessionID);
|
||||
});
|
||||
}
|
||||
public static EventHandler<string> SessionIDChanged { get; set; }
|
||||
public static EventHandler<string> ViewerRemoved { get; set; }
|
||||
public static EventHandler<Viewer> ViewerAdded { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,5 +56,10 @@ namespace Remotely_ScreenCast.Sockets
|
||||
{
|
||||
await Connection.SendAsync("SendConnectionFailedToViewers", viewerIDs);
|
||||
}
|
||||
|
||||
internal async Task GetSessionID()
|
||||
{
|
||||
await Connection.SendAsync("GetSessionID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
<package id="Microsoft.AspNetCore.SignalR.Common" version="1.1.0" targetFramework="net472" />
|
||||
<package id="Microsoft.AspNetCore.SignalR.Protocols.Json" version="1.1.0" targetFramework="net472" />
|
||||
<package id="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" version="1.1.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Expression.Encoder" version="4.0.4276.3" targetFramework="net472" />
|
||||
<package id="Microsoft.Extensions.Configuration" version="2.2.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Extensions.Configuration.Abstractions" version="2.2.0" targetFramework="net472" />
|
||||
<package id="Microsoft.Extensions.Configuration.Binder" version="2.2.0" targetFramework="net472" />
|
||||
|
||||
Loading…
Reference in New Issue
Block a user