Skip to content

Commit

Permalink
Re-acquire and apply branding after switching servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 18, 2021
1 parent 40176ee commit 21a9a89
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 66 deletions.
94 changes: 57 additions & 37 deletions Desktop.Linux/ViewModels/BrandedViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Microsoft.Extensions.DependencyInjection;
using ReactiveUI;
using Remotely.Desktop.Core;
using Remotely.Desktop.Core.Services;
using Remotely.Shared.Utilities;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -14,54 +17,71 @@ public class BrandedViewModelBase : ReactiveViewModel
{
public BrandedViewModelBase()
{
var deviceInit = ServiceContainer.Instance?.GetRequiredService<IDeviceInitService>();
DeviceInitService = ServiceContainer.Instance?.GetRequiredService<IDeviceInitService>();

var brandingInfo = deviceInit?.BrandingInfo ?? new Shared.Models.BrandingInfo();
ApplyBranding();
}

ProductName = "Remotely";
public Bitmap Icon { get; set; }
public string ProductName { get; set; }
public SolidColorBrush TitleBackgroundColor { get; set; }
public SolidColorBrush TitleButtonForegroundColor { get; set; }
public SolidColorBrush TitleForegroundColor { get; set; }
public WindowIcon WindowIcon { get; set; }

if (!string.IsNullOrWhiteSpace(brandingInfo?.Product))
{
ProductName = brandingInfo.Product;
}
protected IDeviceInitService DeviceInitService { get; }

TitleBackgroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleBackgroundRed ?? 70,
brandingInfo?.TitleBackgroundGreen ?? 70,
brandingInfo?.TitleBackgroundBlue ?? 70));
public void ApplyBranding()
{
try
{
var brandingInfo = DeviceInitService?.BrandingInfo ?? new Shared.Models.BrandingInfo();

TitleForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleForegroundRed ?? 29,
brandingInfo?.TitleForegroundGreen ?? 144,
brandingInfo?.TitleForegroundBlue ?? 241));
ProductName = "Remotely";

TitleButtonForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.ButtonForegroundRed ?? 255,
brandingInfo?.ButtonForegroundGreen ?? 255,
brandingInfo?.ButtonForegroundBlue ?? 255));
if (!string.IsNullOrWhiteSpace(brandingInfo?.Product))
{
ProductName = brandingInfo.Product;
}

if (brandingInfo?.Icon?.Any() == true)
{
using var imageStream = new MemoryStream(brandingInfo.Icon);
Icon = new Bitmap(imageStream);
}
else
{
using var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely.Desktop.Linux.Assets.Remotely_Icon.png");
Icon = new Bitmap(imageStream);
}
TitleBackgroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleBackgroundRed ?? 70,
brandingInfo?.TitleBackgroundGreen ?? 70,
brandingInfo?.TitleBackgroundBlue ?? 70));

WindowIcon = new WindowIcon(Icon);
}
TitleForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleForegroundRed ?? 29,
brandingInfo?.TitleForegroundGreen ?? 144,
brandingInfo?.TitleForegroundBlue ?? 241));

public Bitmap Icon { get; set; }
public string ProductName { get; set; }
public SolidColorBrush TitleBackgroundColor { get; set; }
TitleButtonForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.ButtonForegroundRed ?? 255,
brandingInfo?.ButtonForegroundGreen ?? 255,
brandingInfo?.ButtonForegroundBlue ?? 255));

public SolidColorBrush TitleButtonForegroundColor { get; set; }
if (brandingInfo?.Icon?.Any() == true)
{
using var imageStream = new MemoryStream(brandingInfo.Icon);
Icon = new Bitmap(imageStream);
}
else
{
using var imageStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely.Desktop.Linux.Assets.Remotely_Icon.png");
Icon = new Bitmap(imageStream);
}

public SolidColorBrush TitleForegroundColor { get; set; }
WindowIcon = new WindowIcon(Icon);

public WindowIcon WindowIcon { get; set; }
this.RaisePropertyChanged(nameof(ProductName));
this.RaisePropertyChanged(nameof(TitleBackgroundColor));
this.RaisePropertyChanged(nameof(TitleForegroundColor));
this.RaisePropertyChanged(nameof(TitleButtonForegroundColor));
this.RaisePropertyChanged(nameof(WindowIcon));
}
catch (Exception ex)
{
Logger.Write(ex, "Error applying branding.");
}
}
}
}
3 changes: 3 additions & 0 deletions Desktop.Linux/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ await Dispatcher.UIThread.InvokeAsync(() =>
await GetSessionID();
};

await DeviceInitService.GetInitParams();

ApplyBranding();

await _casterSocket.SendDeviceInfo(_conductor.ServiceID, Environment.MachineName, _conductor.DeviceID);
await _casterSocket.GetSessionID();
Expand Down
70 changes: 41 additions & 29 deletions Desktop.Win/ViewModels/BrandedViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using Remotely.Desktop.Core.Services;
using Remotely.Desktop.Core.ViewModels;
using Remotely.Shared.Models;
using Remotely.Shared.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;

Expand All @@ -19,45 +17,59 @@ public class BrandedViewModelBase : ViewModelBase
{
public BrandedViewModelBase()
{
var deviceInit = ServiceContainer.Instance?.GetRequiredService<IDeviceInitService>();
DeviceInitService = ServiceContainer.Instance?.GetRequiredService<IDeviceInitService>();

var brandingInfo = deviceInit?.BrandingInfo ?? new BrandingInfo();

ProductName = "Remotely";
ApplyBranding();
}

if (!string.IsNullOrWhiteSpace(brandingInfo?.Product))
public void ApplyBranding()
{
try
{
ProductName = brandingInfo.Product;
}
var brandingInfo = DeviceInitService?.BrandingInfo ?? new BrandingInfo();

ProductName = "Remotely";

TitleBackgroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleBackgroundRed ?? 70,
brandingInfo?.TitleBackgroundGreen ?? 70,
brandingInfo?.TitleBackgroundBlue ?? 70));
if (!string.IsNullOrWhiteSpace(brandingInfo?.Product))
{
ProductName = brandingInfo.Product;
}

TitleForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleForegroundRed ?? 29,
brandingInfo?.TitleForegroundGreen ?? 144,
brandingInfo?.TitleForegroundBlue ?? 241));
TitleBackgroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleBackgroundRed ?? 70,
brandingInfo?.TitleBackgroundGreen ?? 70,
brandingInfo?.TitleBackgroundBlue ?? 70));

TitleButtonForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.ButtonForegroundRed ?? 255,
brandingInfo?.ButtonForegroundGreen ?? 255,
brandingInfo?.ButtonForegroundBlue ?? 255));
TitleForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.TitleForegroundRed ?? 29,
brandingInfo?.TitleForegroundGreen ?? 144,
brandingInfo?.TitleForegroundBlue ?? 241));

Icon = GetBitmapImageIcon(brandingInfo);
TitleButtonForegroundColor = new SolidColorBrush(Color.FromRgb(
brandingInfo?.ButtonForegroundRed ?? 255,
brandingInfo?.ButtonForegroundGreen ?? 255,
brandingInfo?.ButtonForegroundBlue ?? 255));

Icon = GetBitmapImageIcon(brandingInfo);

FirePropertyChanged(nameof(ProductName));
FirePropertyChanged(nameof(TitleBackgroundColor));
FirePropertyChanged(nameof(TitleForegroundColor));
FirePropertyChanged(nameof(TitleButtonForegroundColor));
FirePropertyChanged(nameof(Icon));
}
catch (Exception ex)
{
Logger.Write(ex, "Error applying branding.");
}
}
public BitmapImage Icon { get; set; }

public BitmapImage Icon { get; set; }
public string ProductName { get; set; }

public SolidColorBrush TitleBackgroundColor { get; set; }

public SolidColorBrush TitleButtonForegroundColor { get; set; }

public SolidColorBrush TitleForegroundColor { get; set; }


protected IDeviceInitService DeviceInitService { get; }
private BitmapImage GetBitmapImageIcon(BrandingInfo bi)
{
Stream imageStream;
Expand Down
3 changes: 3 additions & 0 deletions Desktop.Win/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public async Task Init()
await GetSessionID();
};

await DeviceInitService.GetInitParams();
ApplyBranding();

await GetSessionID();
}
catch (Exception ex)
Expand Down

0 comments on commit 21a9a89

Please sign in to comment.