Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
yamachu committed May 10, 2021
1 parent 5dadcd7 commit a9788eb
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 393 deletions.
2 changes: 1 addition & 1 deletion UmaMadoManager.Core/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public WindowRect UserDefinedHorizontalWindowRect
[System.Configuration.UserScopedSettingAttribute()]
public WindowFittingStandard WindowFittingStandard
{
get { return this["WindowFittingStandard"] == null ? WindowFittingStandard.LeftTop : (WindowFittingStandard)this["WindowFittingStandard"]; }
get { return this["WindowFittingStandard"] == null ? WindowFittingStandard.Unset : (WindowFittingStandard)this["WindowFittingStandard"]; }
set { this["WindowFittingStandard"] = value; }
}

Expand Down
1 change: 1 addition & 0 deletions UmaMadoManager.Core/Models/WindowFittingStandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum WindowFittingStandard
{
LeftTop,
RightTop,
Unset
}
}
9 changes: 9 additions & 0 deletions UmaMadoManager.Core/Services/IApplicationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace UmaMadoManager.Core.Services
{
public interface IApplicationService
{
void Shutdown();
}
}
42 changes: 33 additions & 9 deletions UmaMadoManager.Core/ViewModels/AxisStandardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace UmaMadoManager.Core.ViewModels
{
public class AxisStandardViewModel
public class AxisStandardViewModel : IDisposable
{
private CompositeDisposable Disposable { get; } = new CompositeDisposable();

Expand Down Expand Up @@ -45,7 +45,12 @@ private ReactiveProperty<T> BindSettings<T>(T val, string nameofParameter, React
});
}

public Action OnExit;
public void Dispose()
{
Disposable.Dispose();
}

public ReactiveCommand OnExit { get; }
public Action OnAllocateDebugConsoleClicked;

// FIXME: VMでやることじゃない
Expand All @@ -54,7 +59,8 @@ public AxisStandardViewModel(
IScreenManager screenManager,
IAudioManager audioManager,
IVersionRepository versionRepository,
ISettingService settingService)
ISettingService settingService,
IApplicationService applicationService)
{
settings = settingService.Instance();
Vertical = BindSettings(settings.Vertical, nameof(settings.Vertical));
Expand All @@ -72,7 +78,7 @@ public AxisStandardViewModel(
IsRemoveBorder = BindSettings(settings.IsRemoveBorder, nameof(settings.IsRemoveBorder));

// FIXME: PollingじゃなくてGlobalHookとかでやりたい
targetWindowHandle = Observable.Interval(TimeSpan.FromSeconds(1))
targetWindowHandle = Observable.Interval(TimeSpan.FromSeconds(5))
.CombineLatest(TargetApplicationName)
.Select(x => nativeWindowManager.GetWindowHandle(x.Second))
.Distinct()
Expand Down Expand Up @@ -183,9 +189,9 @@ public AxisStandardViewModel(
.Subscribe(x =>
{
var containsScreen = screenManager.GetScreens()
.Where(s => s.ContainsWindow(x.First.Item1))
.Cast<Screen?>()
.FirstOrDefault();
.Where(s => s.ContainsWindow(x.First.Item1))
.Cast<Screen?>()
.FirstOrDefault();
if (containsScreen == null)
{
return;
Expand Down Expand Up @@ -272,10 +278,28 @@ public AxisStandardViewModel(
nativeWindowManager.SetTopMost(handle, doTop);
}));

OnExit = () =>
OnExit = new ReactiveCommand();
OnExit.Subscribe(_ =>
{
settingService.Save();
};
applicationService.Shutdown();
});

Vertical.Subscribe(x =>
{
if (x != AxisStandard.Full)
{
WindowFittingStandard.Value = Models.WindowFittingStandard.Unset;
}
});

WindowFittingStandard.Subscribe(x =>
{
if (x != Models.WindowFittingStandard.Unset)
{
Vertical.Value = AxisStandard.Full;
}
});
}
}
}
13 changes: 13 additions & 0 deletions UmaMadoManager.Windows/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Application x:Class="UmaMadoManager.Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:UmaMadoManager.Windows"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Views/UmaMadoManagerUI.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
57 changes: 57 additions & 0 deletions UmaMadoManager.Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows;
using Hardcodet.Wpf.TaskbarNotification;
using UmaMadoManager.Windows.Services;

namespace UmaMadoManager.Windows
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private TaskbarIcon notifyIcon;
private Core.ViewModels.AxisStandardViewModel viewModel;

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var nativeWindowManager = new NativeWindowManager();
var screenManager = new ScreenManager();
var audioManager = new AudioManager();
var versionRepository = new VersionRepository();
var settingService = new SettingService();
var debugService = new DebugService();
var applicationService = new ApplicationService();
settingService.Init();

var isDebugMode = System.Environment.GetCommandLineArgs().Count(v => v == "--debug") == 1;
if (isDebugMode) {
debugService.AllocConsole();
}

viewModel = new Core.ViewModels.AxisStandardViewModel(
nativeWindowManager,
screenManager,
audioManager,
versionRepository,
settingService,
applicationService);

notifyIcon = (TaskbarIcon) FindResource("NotifyIcon");
var icon = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("UmaMadoManager.Windows.Resources.TrayIcon.ico"));
notifyIcon.Icon = icon;
notifyIcon.DataContext = viewModel;
}

protected override void OnExit(ExitEventArgs e)
{
notifyIcon.Dispose();
base.OnExit(e);
}
}
}
10 changes: 10 additions & 0 deletions UmaMadoManager.Windows/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
23 changes: 23 additions & 0 deletions UmaMadoManager.Windows/Converters/AxisStandardEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows.Data;
using UmaMadoManager.Core.Models;

namespace UmaMadoManager.Windows.Converters
{
class AxisStandardEnumBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var targetEnum = (AxisStandard)parameter;
var passedEnum = (AxisStandard)value;

return targetEnum == passedEnum;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return parameter;
}
}
}
23 changes: 23 additions & 0 deletions UmaMadoManager.Windows/Converters/MuteConditionEnumConveter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows.Data;
using UmaMadoManager.Core.Models;

namespace UmaMadoManager.Windows.Converters
{
class MuteConditionEnumConveter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var targetEnum = (MuteCondition)parameter;
var passedEnum = (MuteCondition)value;

return targetEnum == passedEnum;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return parameter;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows.Data;
using UmaMadoManager.Core.Models;

namespace UmaMadoManager.Windows.Converters
{
class WindowFittingStandardEnumConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var targetEnum = (WindowFittingStandard)parameter;
var passedEnum = (WindowFittingStandard)value;

return targetEnum == passedEnum;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return parameter;
}
}
}
45 changes: 0 additions & 45 deletions UmaMadoManager.Windows/Program.cs

This file was deleted.

14 changes: 14 additions & 0 deletions UmaMadoManager.Windows/Services/ApplicationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Windows;
using UmaMadoManager.Core.Services;

namespace UmaMadoManager.Windows.Services
{
public class ApplicationService : IApplicationService
{
public void Shutdown()
{
Application.Current.Shutdown();
}
}
}
3 changes: 3 additions & 0 deletions UmaMadoManager.Windows/UmaMadoManager.Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<Version>1.5.0-pre2</Version>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
Expand All @@ -22,6 +24,7 @@
<EmbeddedResource Include="Resources\TrayIcon.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="NAudio.Wasapi" Version="2.0.0" />
<PackageReference Include="PInvoke.Kernel32" Version="0.7.104" />
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
Expand Down
Loading

0 comments on commit a9788eb

Please sign in to comment.