Skip to content

Commit

Permalink
Dependency updates, added export of SynchronizationContext.Current as…
Browse files Browse the repository at this point in the history
… "ui" typeof(SynchronizationContext)

[release]
  • Loading branch information
Lakritzator committed May 3, 2017
1 parent 6b3b8f2 commit 62b2fdd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 26 deletions.
2 changes: 0 additions & 2 deletions Application.Demo/Application.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ foreach (var item in filesToCleanup)
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.0.6\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.6\build\dotnet\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion Application.Demo/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
8 changes: 7 additions & 1 deletion Application.Demo/UseCases/ContextMenu/ExitMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#region using

using System.ComponentModel.Composition;
using System.Threading;
using System.Windows;
using System.Windows.Media;
using Application.Demo.Languages;
Expand All @@ -40,7 +41,12 @@ namespace Application.Demo.UseCases.ContextMenu
public sealed class ExitMenuItem : MenuItem
{
[ImportingConstructor]
public ExitMenuItem(IContextMenuTranslations contextMenuTranslations)
public ExitMenuItem(
IContextMenuTranslations contextMenuTranslations,
// Test for the exporting SynchronizationContext
[Import("ui", typeof(SynchronizationContext))]
SynchronizationContext uiSynchronizationContext
)
{
// automatically update the DisplayName
contextMenuTranslations.CreateDisplayNameBinding(this, nameof(IContextMenuTranslations.Exit));
Expand Down
5 changes: 0 additions & 5 deletions Application.Demo/UseCases/Menu/SaveAsMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public sealed class SaveAsMenuItem : MenuItem
[Import]
private IMenuTranslations MenuTranslations { get; set; }

public override void Click(IMenuItem clickedItem)
{
// Method intentionally left empty.
}

public override void Initialize()
{
Id = "A_SaveAs";
Expand Down
2 changes: 1 addition & 1 deletion Application.Demo/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<packages>
<package id="Caliburn.Micro" version="3.0.3" targetFramework="net452" />
<package id="Caliburn.Micro.Core" version="3.0.3" targetFramework="net452" />
<package id="Costura.Fody" version="1.4.0" targetFramework="net452" developmentDependency="true" />
<package id="Costura.Fody" version="1.4.1" targetFramework="net452" developmentDependency="true" />
<package id="Dapplo.Addons" version="0.4.7" targetFramework="net452" />
<package id="Dapplo.Ini" version="0.5.17" targetFramework="net452" />
<package id="Dapplo.InterfaceImpl" version="0.2.7" targetFramework="net452" />
Expand Down
5 changes: 5 additions & 0 deletions Dapplo.CaliburnMicro.Dapp/Dapplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#region using

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
Expand Down Expand Up @@ -114,6 +115,10 @@ protected override async void OnStartup(StartupEventArgs startupEventArgs)
// Prepare the bootstrapper
await _bootstrapper.InitializeAsync();

// Export the UI SynchronizationContext, this can be retrieved by specifying:
// [Import("ui", typeof(SynchronizationContext))] on a SynchronizationContext property / constructor argument
_bootstrapper.Export("ui", SynchronizationContext.Current);

// The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works
var caliburnBootstrapper = _bootstrapper.GetExport<CaliburnMicroBootstrapper>().Value;
caliburnBootstrapper.Initialize();
Expand Down
31 changes: 18 additions & 13 deletions Dapplo.CaliburnMicro.NotifyIconWpf/TrayIconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,26 @@ await Execute.OnUIThreadAsync(() =>
/// <returns>Task</returns>
public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
{
await Execute.OnUIThreadAsync(() =>
await Execute.OnUIThreadAsync(InitializeTrayIconViewModels);
}

/// <summary>
/// Do the initialization
/// </summary>
private void InitializeTrayIconViewModels()
{
foreach (var trayIconViewModel in _trayIconViewModels.Select(x => x.Value))
{
foreach (var trayIconViewModel in _trayIconViewModels.Select(x => x.Value))
// Get the view, to store it as ITrayIcon
trayIconViewModel.ViewAttached += (sender, e) =>
{
// Get the view, to store it as ITrayIcon
trayIconViewModel.ViewAttached += (sender, e) =>
{
var popup = e.View as Popup;
var contentControl = e.View as ContentControl;
var trayIcon = popup?.Child as ITrayIcon ?? contentControl?.Content as ITrayIcon ?? e.View as ITrayIcon;
_trayIcons.Add(new WeakReference<ITrayIconViewModel>(trayIconViewModel), new WeakReference<ITrayIcon>(trayIcon));
};
_windowsManager.ShowPopup(trayIconViewModel);
}
});
var popup = e.View as Popup;
var contentControl = e.View as ContentControl;
var trayIcon = popup?.Child as ITrayIcon ?? contentControl?.Content as ITrayIcon ?? e.View as ITrayIcon;
_trayIcons.Add(new WeakReference<ITrayIconViewModel>(trayIconViewModel), new WeakReference<ITrayIcon>(trayIcon));
};
_windowsManager.ShowPopup(trayIconViewModel);
}
}

/// <summary>
Expand Down
12 changes: 10 additions & 2 deletions Dapplo.CaliburnMicro/Dapplo.CaliburnMicro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@
<HintPath>..\packages\Dapplo.Log.1.0.29\lib\net45\Dapplo.Log.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Windows, Version=0.3.37.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Windows.0.3.37\lib\net45\Dapplo.Windows.dll</HintPath>
<Reference Include="Dapplo.Windows, Version=0.4.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Windows.0.4.13\lib\net45\Dapplo.Windows.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Windows.Dpi, Version=0.4.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Windows.Dpi.0.4.13\lib\net45\Dapplo.Windows.Dpi.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Windows.Messages, Version=0.4.13.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Windows.Messages.0.4.13\lib\net45\Dapplo.Windows.Messages.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
4 changes: 3 additions & 1 deletion Dapplo.CaliburnMicro/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<package id="Caliburn.Micro.Core" version="3.0.3" targetFramework="net45" />
<package id="Dapplo.Addons" version="0.4.7" targetFramework="net45" />
<package id="Dapplo.Log" version="1.0.29" targetFramework="net45" />
<package id="Dapplo.Windows" version="0.3.37" targetFramework="net45" />
<package id="Dapplo.Windows" version="0.4.13" targetFramework="net45" />
<package id="Dapplo.Windows.Dpi" version="0.4.13" targetFramework="net45" />
<package id="Dapplo.Windows.Messages" version="0.4.13" targetFramework="net45" />
<package id="System.Reactive.Core" version="3.1.1" targetFramework="net45" />
<package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net45" />
<package id="System.Reactive.Linq" version="3.1.1" targetFramework="net45" />
Expand Down

0 comments on commit 62b2fdd

Please sign in to comment.