Skip to content

Commit

Permalink
Merge pull request #380 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Dec 4, 2022
2 parents 4279ae7 + bcac459 commit a2dcb91
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Source/Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.14.0"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="3.15.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
12 changes: 12 additions & 0 deletions Source/Monitorian.Core/AppControllerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -92,6 +93,8 @@ public virtual async Task InitiateAsync()
Update(instanceName, brightness);
},
async (message) => await Recorder.RecordAsync(message));

await CleanAsync();
}

public virtual void End()
Expand Down Expand Up @@ -472,5 +475,14 @@ protected virtual void EnsureUnisonWorkable(MonitorViewModel monitor)
public Task SaveArgumentsAsync(string content) => _keeper.SaveArgumentsAsync(content);

#endregion

#region Clean

protected virtual Task CleanAsync()
{
return Task.Run(() => File.Delete(Path.Combine(Path.GetTempPath(), "License.html")));
}

#endregion
}
}
44 changes: 39 additions & 5 deletions Source/Monitorian.Core/Models/DocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static string ReadEmbeddedFile(string fileName)
if (resourceName is null)
return null;

using (var s = assembly.GetManifestResourceStream(resourceName))
using (var sr = new StreamReader(s))
return sr.ReadToEnd();
using var s = assembly.GetManifestResourceStream(resourceName);
using var sr = new StreamReader(s);
return sr.ReadToEnd();
}
catch (Exception ex)
{
Expand All @@ -33,9 +33,12 @@ public static string ReadEmbeddedFile(string fileName)
}
}

private static string GetTempFilePath(string fileName) =>
Path.Combine(Path.GetTempPath(), $"monitorian_{Path.GetFileNameWithoutExtension(fileName).ToLower()}.html");

public static string SaveTempFileAsHtml(string fileName, string title, string body)
{
var filePath = Path.Combine(Path.GetTempPath(), $"{Path.GetFileNameWithoutExtension(fileName)}.html");
var filePath = GetTempFilePath(fileName);
SaveFileAsHtml(filePath, title, body);
return filePath;
}
Expand All @@ -50,8 +53,16 @@ public static void SaveFileAsHtml(string filePath, string title, string body)

var html = BuildHtml(title, body);

using (var sw = new StreamWriter(filePath, false, Encoding.UTF8)) // BOM will be emitted.
try
{
using var sw = new StreamWriter(filePath, false, Encoding.UTF8); // BOM will be emitted.
sw.Write(html);
}
catch (Exception ex)
{
Debug.WriteLine("Failed to save a file." + Environment.NewLine
+ ex);
}
}

private static string BuildHtml(string title, string body)
Expand Down Expand Up @@ -86,5 +97,28 @@ private static string BuildHtml(string title, string body)
</body>
</html>";
}

public static bool DeleteTempFile(string fileName, TimeSpan validDuration = default)
{
var filePath = GetTempFilePath(fileName);
var fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
return false;

if ((validDuration == default) || (fileInfo.LastWriteTime < DateTime.Now.Add(-validDuration)))
{
try
{
fileInfo.Delete();
return false;
}
catch (Exception ex)
{
Debug.WriteLine("Failed to delete a file." + Environment.NewLine
+ ex);
}
}
return true;
}
}
}
1 change: 1 addition & 0 deletions Source/Monitorian.Core/Monitorian.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="Views\Behaviors\ItemSelectorBehavior.cs" />
<Compile Include="Views\Behaviors\ItemSliderBehavior.cs" />
<Compile Include="Views\Behaviors\MouseDownParentAction.cs" />
<Compile Include="Views\Behaviors\MouseHorizontalWheelBehavior.cs" />
<Compile Include="Views\Controls\Sliders\CompoundSlider.cs" />
<Compile Include="Views\Controls\Sliders\EnhancedSlider.cs" />
<Compile Include="Views\Controls\Sliders\RangeSlider.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Source/Monitorian.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.14.0.0")]
[assembly: AssemblyFileVersion("3.14.0.0")]
[assembly: AssemblyVersion("3.15.0.0")]
[assembly: AssemblyFileVersion("3.15.0.0")]
[assembly: NeutralResourcesLanguage("en-US")]

// For unit test
Expand Down
39 changes: 27 additions & 12 deletions Source/Monitorian.Core/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,51 +117,63 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Arguments" xml:space="preserve">
<value>命令行参数</value>
</data>
<data name="ChangeContrast" xml:space="preserve">
<value>调节对比度</value>
</data>
<data name="ChangeRange" xml:space="preserve">
<value>设置可调节范围</value>
<value>设置调节范围</value>
</data>
<data name="ChangeUnison" xml:space="preserve">
<value>多屏亮度调节</value>
<value>同步调节亮度</value>
</data>
<data name="Close" xml:space="preserve">
<value>关闭</value>
</data>
<data name="CopyOperation" xml:space="preserve">
<value>复制操作记录</value>
<value>复制运行日志</value>
</data>
<data name="CopySaveOperationMessage" xml:space="preserve">
<value>是否将操作记录保存到桌面?</value>
<value>是否将运行日志保存到桌面?</value>
</data>
<data name="CopyWaitOperationMessage" xml:space="preserve">
<value>请等待运行日志记录更多信息</value>
</data>
<data name="DeferChange" xml:space="preserve">
<value>松开滑块后调节亮度</value>
</data>
<data name="EnableContrast" xml:space="preserve">
<value>开启对比度调节</value>
<value>启用对比度调节</value>
</data>
<data name="EnableRange" xml:space="preserve">
<value>开启设置可调节范围</value>
<value>启用调节范围</value>
</data>
<data name="EnableUnison" xml:space="preserve">
<value>开启多屏亮度调节</value>
<value>启用同步亮度调节</value>
</data>
<data name="MakeOperation" xml:space="preserve">
<value>生成操作记录</value>
<value>生成运行日志</value>
</data>
<data name="OrderArrangement" xml:space="preserve">
<value>以显示器顺序进行排列</value>
<value>按显示器顺序排列</value>
</data>
<data name="Probe" xml:space="preserve">
<value>检测显示器</value>
</data>
<data name="RecordExceptionMessage" xml:space="preserve">
<value>程序出现了意外问题。是否将异常记录保存到桌面?</value>
<value>程序出现了意外问题。将错误信息保存到</value>
</data>
<data name="RecordProbeMessage" xml:space="preserve">
<value>是否将检测记录保存到桌面?</value>
<value>是否将检测日志保存到桌面?</value>
</data>
<data name="Rescan" xml:space="preserve">
<value>重新扫描显示器</value>
</data>
<data name="RestoreReconnection" xml:space="preserve">
<value>再次连接时恢复亮度</value>
</data>
<data name="Settings" xml:space="preserve">
<value>设置</value>
</data>
Expand All @@ -175,14 +187,17 @@
<value>开机时启动</value>
</data>
<data name="StatusNotControllable" xml:space="preserve">
<value>无法控制屏幕。</value>
<value>无法控制显示器。</value>
</data>
<data name="StatusReasonDdcFailing" xml:space="preserve">
<value>DDC/CI 调用失败多次。</value>
</data>
<data name="StatusReasonDdcNotEnabled" xml:space="preserve">
<value>DDC/CI 不受支持或未启用。</value>
</data>
<data name="UseAccentColor" xml:space="preserve">
<value>亮度滑块使用系统主题色</value>
</data>
<data name="UseLargeElements" xml:space="preserve">
<value>使用大滑块</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions Source/Monitorian.Core/ViewModels/MenuWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ public class MenuWindowViewModel : ViewModelBase
public MenuWindowViewModel(AppControllerCore controller)
{
this._controller = controller ?? throw new ArgumentNullException(nameof(controller));

CleanLicense();
}

#region License

private const string LicenseFileName = "License.txt";
private static bool _licenseFileExists = true; // Default

public void OpenLicense()
{
Expand All @@ -30,9 +33,18 @@ public void OpenLicense()
var licenseFileBody = DocumentService.ReadEmbeddedFile(LicenseFileName);
var licenseFilePath = DocumentService.SaveTempFileAsHtml(LicenseFileName, ProductInfo.Product, licenseFileBody);
Process.Start(licenseFilePath);
_licenseFileExists = true;
});
}

private void CleanLicense()
{
if (!_licenseFileExists)
return;

Task.Run(() => _licenseFileExists = DocumentService.DeleteTempFile(LicenseFileName, TimeSpan.FromHours(1)));
}

#endregion

#region Startup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Microsoft.Xaml.Behaviors;

using Monitorian.Core.Views.Input;

namespace Monitorian.Core.Views.Behaviors
{
public class MouseHorizontalWheelBehavior : Behavior<UIElement>
{
private static readonly MethodInfo _onMouseWheel;

static MouseHorizontalWheelBehavior()
{
// Get UIElement.OnMouseWheel method information.
_onMouseWheel = typeof(UIElement).GetMethod("OnMouseWheel", BindingFlags.Instance | BindingFlags.NonPublic, null, CallingConventions.Any, new Type[] { typeof(MouseWheelEventArgs) }, null);
}

protected override void OnAttached()
{
base.OnAttached();

MouseAddition.AddMouseHorizontalWheelHandler(this.AssociatedObject, OnMouseHorizontalWheel);
}

protected override void OnDetaching()
{
base.OnDetaching();

MouseAddition.RemoveMouseHorizontalWheelHandler(this.AssociatedObject, OnMouseHorizontalWheel);
}

private void OnMouseHorizontalWheel(object sender, MouseWheelEventArgs e)
{
_onMouseWheel?.Invoke(this.AssociatedObject, new object[] { e });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
EnsureUpdateSource();
}

public virtual void OnMouseWheel(object sender, MouseWheelEventArgs e) => OnMouseWheel(e);

#endregion

#region Deferral
Expand Down
18 changes: 18 additions & 0 deletions Source/Monitorian.Core/Views/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="controls:TemplateElement.Visibility" Value="Collapsed"/>
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -137,6 +138,7 @@
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="controls:TemplateElement.Visibility" Value="Collapsed"/>
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -168,6 +170,7 @@
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
Expand Down Expand Up @@ -205,6 +208,7 @@
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:MultiToggleButton}">
Expand Down Expand Up @@ -236,6 +240,7 @@
</Grid>
<!-- Upper and lower grids are divided to set the width of lower grid. -->
<Grid Grid.Row="1"
x:Name="lowerGrid"
Width="{Binding ElementName=upperGrid, Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -265,10 +270,22 @@
</Setter>
</Style>

<!-- Plain TextElement -->
<Style x:Key="PlainTextStyle" TargetType="{x:Type FrameworkElement}">
<Setter Property="TextElement.Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="TextElement.FontSize" Value="12"/>
</Style>

<!-- Invalid TextElement -->
<Style x:Key="InvalidTextStyle" TargetType="{x:Type FrameworkElement}" BasedOn="{StaticResource PlainTextStyle}">
<Setter Property="TextElement.Foreground" Value="{StaticResource App.Foreground.Invalid}"/>
</Style>

<!-- Name TextBox -->
<Style x:Key="NameTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="CaretBrush" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
Expand All @@ -295,6 +312,7 @@
<Style x:Key="PlainTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Foreground" Value="{StaticResource App.Foreground}"/>
<Setter Property="CaretBrush" Value="{StaticResource App.Foreground}"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
Expand Down
Loading

0 comments on commit a2dcb91

Please sign in to comment.