Skip to content

Commit e40e9eb

Browse files
committed
Sync backgroud color (fix #9 & #11)
1 parent 1b9286d commit e40e9eb

File tree

5 files changed

+132
-108
lines changed

5 files changed

+132
-108
lines changed

Plugin.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ public void Init() { }
1818

1919
public void Prepare(string path, ContextObject context) {
2020
context.Title = Path.GetFileName(path);
21-
context.TitlebarOverlap = false;
22-
context.FullWindowDragging = true;
23-
context.TitlebarBlurVisibility = false;
24-
context.TitlebarColourVisibility = false;
2521
context.PreferredSize = new Size { Width = 750, Height = 450 };
2622

2723
tempApk = createTempApk(path);

QuickLook.Plugin.ApkViewer.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
</ItemGroup>
7272
<ItemGroup>
7373
<Compile Include="Plugin.cs" />
74-
<Compile Include="ThemeHelper.cs" />
7574
<Compile Include="Properties\AssemblyInfo.cs" />
7675
<Compile Include="ViewerPane.xaml.cs">
7776
<DependentUpon>ViewerPane.xaml</DependentUpon>

ThemeHelper.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

ViewerPane.xaml

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,58 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:local="clr-namespace:QuickLook.Plugin.ApkViewer"
7-
mc:Ignorable="d" d:DesignWidth="450" Height="auto" Width="auto" FontFamily="Segoe UI" HorizontalAlignment="Center" VerticalAlignment="Center">
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
Background="{DynamicResource MainWindowBackground}"
7+
mc:Ignorable="d" d:DesignWidth="450" FontFamily="Segoe UI">
88

99
<UserControl.Resources>
10-
<SolidColorBrush x:Key="TextForeground" Color="Black"/>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<ResourceDictionary Source="/QuickLook.Common;component/Styles/MainWindowStyles.xaml" />
13+
</ResourceDictionary.MergedDictionaries>
1114

12-
<Style x:Key="CommonStyle" TargetType="Control">
13-
<Setter Property="Height" Value="30"/>
14-
<Setter Property="FontSize" Value="14"/>
15-
<Setter Property="FontFamily" Value="Segoe UI"/>
16-
<Setter Property="Foreground" Value="{DynamicResource TextForeground}"/>
17-
</Style>
15+
<Style x:Key="CommonStyle" TargetType="Control">
16+
<Setter Property="Height" Value="30"/>
17+
<Setter Property="FontSize" Value="14"/>
18+
<Setter Property="FontFamily" Value="Segoe UI"/>
19+
<Setter Property="Foreground" Value="{DynamicResource WindowTextForeground}"/>
20+
</Style>
1821

19-
<Style x:Key="StaticLabel" TargetType="Label" BasedOn="{StaticResource CommonStyle}">
20-
<Setter Property="Width" Value="130"/>
21-
<Setter Property="FontWeight" Value="Bold"/>
22-
<Setter Property="HorizontalAlignment" Value="Left"/>
23-
<Setter Property="VerticalAlignment" Value="Center"/>
24-
</Style>
22+
<Style x:Key="StaticLabel" TargetType="Label" BasedOn="{StaticResource CommonStyle}">
23+
<Setter Property="Width" Value="130"/>
24+
<Setter Property="FontWeight" Value="Bold"/>
25+
<Setter Property="HorizontalAlignment" Value="Left"/>
26+
<Setter Property="VerticalAlignment" Value="Center"/>
27+
</Style>
2528

26-
<Style x:Key="SelectableLabel" TargetType="TextBox" BasedOn="{StaticResource CommonStyle}">
27-
<Setter Property="BorderThickness" Value="0"/>
28-
<Setter Property="Background" Value="Transparent"/>
29-
<Setter Property="SelectionBrush" Value="#007BFF"/>
30-
<Setter Property="SelectionOpacity" Value="0.3"/>
31-
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
32-
<Setter Property="TextWrapping" Value="NoWrap"/>
33-
<Setter Property="IsReadOnly" Value="True"/>
34-
<Setter Property="VerticalAlignment" Value="Center"/>
35-
<Setter Property="VerticalContentAlignment" Value="Center"/>
36-
<Setter Property="HorizontalContentAlignment" Value="Left"/>
37-
</Style>
29+
<Style x:Key="SelectableLabel" TargetType="TextBox" BasedOn="{StaticResource CommonStyle}">
30+
<Setter Property="BorderThickness" Value="0"/>
31+
<Setter Property="Background" Value="Transparent"/>
32+
<Setter Property="SelectionBrush" Value="#007BFF"/>
33+
<Setter Property="SelectionOpacity" Value="0.3"/>
34+
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
35+
<Setter Property="TextWrapping" Value="NoWrap"/>
36+
<Setter Property="IsReadOnly" Value="True"/>
37+
<Setter Property="VerticalAlignment" Value="Center"/>
38+
<Setter Property="VerticalContentAlignment" Value="Center"/>
39+
<Setter Property="HorizontalContentAlignment" Value="Left"/>
40+
</Style>
3841

39-
<Style x:Key="HoverableLabel" TargetType="TextBox" BasedOn="{StaticResource SelectableLabel}">
40-
<Setter Property="Width" Value="Auto" />
41-
<Style.Triggers>
42-
<Trigger Property="IsMouseOver" Value="True">
43-
<Setter Property="Background" Value="#FF333333"/>
44-
<Setter Property="Foreground" Value="#FFFFFFFF"/>
45-
</Trigger>
46-
</Style.Triggers>
47-
</Style>
48-
49-
<BitmapImage x:Key="DarkSwImage" UriSource="pack://application:,,,/QuickLook.Plugin.ApkViewer;component/images/black_btn.png"/>
50-
<BitmapImage x:Key="LightSwImage" UriSource="pack://application:,,,/QuickLook.Plugin.ApkViewer;component/images/white_btn.png"/>
51-
<BitmapImage x:Key="DefaultIcon" UriSource="pack://application:,,,/QuickLook.Plugin.ApkViewer;component/images/default_icon.png"/>
42+
<Style x:Key="HoverableLabel" TargetType="TextBox" BasedOn="{StaticResource SelectableLabel}">
43+
<Setter Property="Width" Value="Auto" />
44+
<Style.Triggers>
45+
<Trigger Property="IsMouseOver" Value="True">
46+
<Setter Property="Background" Value="{DynamicResource CaptionButtonHoverBackground}"/>
47+
<Setter Property="Foreground" Value="{DynamicResource CaptionButtonIconForeground}"/>
48+
</Trigger>
49+
</Style.Triggers>
50+
</Style>
5251

52+
<BitmapImage x:Key="DefaultIcon" UriSource="images/default_icon.png"/>
53+
</ResourceDictionary>
5354
</UserControl.Resources>
5455

55-
<Grid>
56+
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
5657
<Grid.RowDefinitions>
5758
<RowDefinition Height="Auto"/>
5859
<RowDefinition Height="Auto"/>
@@ -65,10 +66,13 @@
6566
</Grid.ColumnDefinitions>
6667

6768
<Grid>
68-
<Image x:Name="image" Source="{StaticResource DefaultIcon}" Cursor="Hand" Height="210" Width="210" VerticalAlignment="Center" HorizontalAlignment="Center"/>
69+
<Image x:Name="image" Source="{StaticResource DefaultIcon}"
70+
Cursor="Hand" Height="210" Width="210"
71+
VerticalAlignment="Center" HorizontalAlignment="Center" />
6972
</Grid>
7073

71-
<StackPanel Name="labels" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,0">
74+
<StackPanel Name="labels" Grid.Column="1" Margin="5,0"
75+
HorizontalAlignment="Left" VerticalAlignment="Top">
7276
<Label Content="Application name:" Style="{StaticResource StaticLabel}"/>
7377
<Label Content="Package name:" Style="{StaticResource StaticLabel}"/>
7478
<Label Content="Version name:" Style="{StaticResource StaticLabel}"/>
@@ -92,14 +96,40 @@
9296
<TextBox x:Name="tbPckSize" Text="..." Width="auto" Style="{StaticResource SelectableLabel}" MouseDoubleClick="SelectableLabel_MouseDoubleClick" VerticalAlignment="Center" HorizontalAlignment="Left"/>
9397
</StackPanel>
9498

95-
<Image x:Name="btnSwTheme" Height="20" Width="20" Source="{StaticResource DarkSwImage}" Cursor="Hand" ToolTip="Switch theme" Grid.Column="3" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10"/>
99+
<Image x:Name="btnSwTheme" Height="20" Width="20" Margin="10"
100+
Cursor="Hand" ToolTip="Switch theme" Grid.Column="3"
101+
HorizontalAlignment="Left" VerticalAlignment="Top">
102+
<Image.Style>
103+
<Style>
104+
<Style.Triggers>
105+
<DataTrigger Binding="{Binding ElementName=ViewerPanel,Path=Theme}" Value="Light">
106+
<!-- Black image on light theme -->
107+
<Setter Property="Image.Source">
108+
<Setter.Value>
109+
<BitmapImage UriSource="images/black_btn.png" />
110+
</Setter.Value>
111+
</Setter>
112+
</DataTrigger>
113+
<DataTrigger Binding="{Binding ElementName=ViewerPanel,Path=Theme}" Value="Dark">
114+
<Setter Property="Image.Source">
115+
<Setter.Value>
116+
<BitmapImage UriSource="images/white_btn.png" />
117+
</Setter.Value>
118+
</Setter>
119+
</DataTrigger>
120+
</Style.Triggers>
121+
</Style>
122+
</Image.Style>
123+
</Image>
96124

97-
<GroupBox x:Name="panelPermission" Header="Permissions" BorderBrush="{DynamicResource TextForeground}" Foreground="{DynamicResource TextForeground}" BorderThickness="1" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="4" Margin="10" Height="150" VerticalAlignment="Top">
125+
<GroupBox x:Name="panelPermission" Header="Permissions" VerticalAlignment="Top"
126+
BorderBrush="{DynamicResource WindowTextForeground}"
127+
Foreground="{DynamicResource WindowTextForeground}"
128+
BorderThickness="1" Margin="10" Height="150"
129+
Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="4">
98130
<ScrollViewer Focusable="False">
99131
<StackPanel x:Name="permissionStack"/>
100132
</ScrollViewer>
101133
</GroupBox>
102-
103134
</Grid>
104-
105135
</UserControl>

ViewerPane.xaml.cs

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,76 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Diagnostics;
4+
using System.Runtime.CompilerServices;
35
using System.Windows;
46
using System.Windows.Controls;
57
using System.Windows.Input;
6-
using System.Windows.Media;
78
using System.Windows.Media.Imaging;
89
using AAPTForNet.Models;
10+
using QuickLook.Common.Annotations;
911
using QuickLook.Common.ExtensionMethods;
12+
using QuickLook.Common.Helpers;
1013
using QuickLook.Common.Plugin;
1114

1215
namespace QuickLook.Plugin.ApkViewer {
1316

14-
public partial class ViewerPane : UserControl {
17+
public partial class ViewerPane : UserControl, INotifyPropertyChanged {
18+
private const string SETTING_THEME_ID = "Theme";
19+
1520
private ApkInfo _apkInfo = null;
1621
private ContextObject _quickLook = null;
1722

23+
public event PropertyChangedEventHandler PropertyChanged;
24+
1825
public ApkInfo ApkInfo {
1926
get => _apkInfo;
2027
set {
2128
_apkInfo = value;
22-
initGUI();
29+
InitGUI();
2330
}
2431
}
2532

26-
public ViewerPane() {
27-
InitializeComponent();
33+
public Themes Theme {
34+
get => _quickLook?.Theme ?? Themes.Dark;
35+
set {
36+
_quickLook.Theme = value;
37+
OnPropertyChanged();
38+
}
39+
}
2840

29-
btnSwTheme.MouseLeftButtonDown += (sender, e) => {
30-
var temp = _quickLook.Theme == Themes.Dark ?
31-
Themes.Light : Themes.Dark;
41+
public bool IsDark => Theme == Themes.Dark;
3242

33-
ThemeHelper.Set(temp);
34-
_quickLook.Theme = temp;
35-
};
43+
public ViewerPane() {
44+
InitializeComponent();
45+
btnSwTheme.MouseLeftButtonDown += SwitchTheme;
3646
}
3747

3848
public ViewerPane(ContextObject ql) : this() {
3949
_quickLook = ql;
40-
_quickLook.PropertyChanged += (sender, e) => {
41-
if (e.PropertyName != nameof(_quickLook.Theme))
42-
return;
50+
_quickLook.PropertyChanged += AfterThemeChanged;
4351

44-
if (_quickLook.Theme == Themes.Dark) {
45-
Resources["TextForeground"] = Brushes.White;
46-
btnSwTheme.Source = Resources["LightSwImage"] as BitmapImage;
47-
}
48-
else {
49-
Resources["TextForeground"] = Brushes.Black;
50-
btnSwTheme.Source = Resources["DarkSwImage"] as BitmapImage;
51-
}
52-
};
53-
_quickLook.Theme = ThemeHelper.TryGet();
52+
Theme = (Themes) SettingHelper.Get(SETTING_THEME_ID, 1, GetType().Namespace);
53+
}
54+
55+
private void SwitchTheme(object sender, MouseButtonEventArgs e) {
56+
Theme = IsDark ? Themes.Light : Themes.Dark;
57+
SettingHelper.Set(SETTING_THEME_ID, (int) Theme, GetType().Namespace);
5458
}
5559

56-
private void initGUI() {
60+
private void AfterThemeChanged(object sender, PropertyChangedEventArgs e) {
61+
if (e.PropertyName != nameof(Theme))
62+
return;
63+
64+
var resourceUri = "/QuickLook.Common;component/Styles" +
65+
$"/MainWindowStyles{(IsDark ? ".Dark" : "")}.xaml";
66+
67+
Resources.MergedDictionaries.Clear();
68+
Resources.MergedDictionaries.Add(new ResourceDictionary {
69+
Source = new Uri(resourceUri, UriKind.Relative)
70+
});
71+
}
72+
73+
private void InitGUI() {
5774
tbAppName.Text = ApkInfo.AppName;
5875
tbPckName.Text = ApkInfo.PackageName;
5976
tbVerName.Text = ApkInfo.VersionName;
@@ -93,7 +110,7 @@ private void initGUI() {
93110
var uri = new Uri(ApkInfo.Icon.RealPath);
94111

95112
image.ToolTip = "Open image";
96-
image.Source = loadBitmapImage(uri);
113+
image.Source = LoadBitmapImage(uri);
97114
image.MouseLeftButtonDown += (sender, e) => {
98115
Process.Start("explorer.exe", ApkInfo.Icon.RealPath);
99116
};
@@ -103,7 +120,7 @@ private void initGUI() {
103120
}
104121
}
105122

106-
private BitmapImage loadBitmapImage(Uri source) {
123+
private BitmapImage LoadBitmapImage(Uri source) {
107124
var bitmap = new BitmapImage();
108125
bitmap.BeginInit();
109126
// Ignore previous image in cache
@@ -115,16 +132,22 @@ private BitmapImage loadBitmapImage(Uri source) {
115132
return bitmap;
116133
}
117134

135+
[NotifyPropertyChangedInvocator]
136+
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {
137+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
138+
}
139+
118140
private void SelectableLabel_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
119141
var ctrl = sender as TextBox;
120142
ctrl?.SelectAll();
121143
}
122144

123145
private class HoverableLabel : TextBox {
124-
public HoverableLabel(string text, Style style, MouseButtonEventHandler dbClickHandler) {
125-
this.Text = text;
126-
this.Style = style;
127-
this.MouseDoubleClick += dbClickHandler;
146+
public HoverableLabel(string text, Style style,
147+
MouseButtonEventHandler dbClickHandler) {
148+
Text = text;
149+
Style = style;
150+
MouseDoubleClick += dbClickHandler;
128151
}
129152
}
130153
}

0 commit comments

Comments
 (0)