Skip to content

Commit

Permalink
Make Project Packagable
Browse files Browse the repository at this point in the history
Drop support for Win7
  • Loading branch information
GetGet99 committed Sep 4, 2022
1 parent 0b60962 commit 07538de
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 184 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Failed Experiments/Mica Discord WinUI 3/bin
Failed Experiments/Mica Discord WinUI 3/obj
Failed Experiments/SettingsBuilder/bin
Failed Experiments/SettingsBuilder/obj
Mica Discord Packager/bin
Mica Discord Packager/obj
Mica Discord Packager/Package.StoreAssociation.xml
Mica Discord Packager/AppPackages
Mica Discord Packager/BundleArtifacts
Future/Mica Browser/bin
Future/Mica Browser/obj
Future/Mica Window/bin
Expand Down
2 changes: 2 additions & 0 deletions Mica Discord WPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Forms;
using WPFApplication = System.Windows.Application;
using WV2::Microsoft.Web.WebView2.Core;
using System.IO;
#if WINDOWS10_0_17763_0_OR_GREATER
using Microsoft.Windows.ApplicationModel.DynamicDependency;
#endif
Expand All @@ -32,6 +33,7 @@ protected override void OnStartup(StartupEventArgs e)
{
try
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) ?? throw new NullReferenceException());
base.OnStartup(e);
NotifyIcon.Click += (_, _) => OpenMenu();
//var mainwindow = (MainWindow)MainWindow;
Expand Down
28 changes: 15 additions & 13 deletions Mica Discord WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
using Color = System.Windows.Media.Color;
using Button = System.Windows.Controls.Button;
using Control = System.Windows.Forms.Control;

namespace MicaDiscord;

#if WINDOWS10_0_17763_0_OR_GREATER
using AppSetting = MicaDiscord.Setting;
#endif
public partial class MainWindow : Window
{
public static int WindowsMajorNumber = Environment.OSVersion.Version.Major;
public static int WindowsBuildNumber = Environment.OSVersion.Version.Build;
#if WINDOWS10_0_17763_0_OR_GREATER
static string StartupPath = "."; // Path.GetDirectoryName(typeof(MainWindow).Assembly.Location) ?? throw new NullReferenceException();
static UISettings UISettings { get; } = new();
public static bool IsNewTitleBarSupported => IsWin11; //AppWindowTitleBar.IsCustomizationSupported();
#else
Expand All @@ -46,13 +48,13 @@ public static string DefinedCSS
#if DEBUG
=> File.Exists("../../../The CSS.css") ? File.ReadAllText("../../../The CSS.css") : File.ReadAllText("The CSS.css");// Read File Every time
#else
= File.ReadAllText("./The CSS.css"); // Read only once
= File.ReadAllText($"{StartupPath}/The CSS.css"); // Read only once
#endif
public static string DefinedJavascript
#if DEBUG
=> File.Exists("../../../MicaDiscordScript.js") ? File.ReadAllText("../../../MicaDiscordScript.js") : File.ReadAllText("MicaDiscordScript.js");// Read File Every time
#else
= File.ReadAllText("./MicaDiscordScript.js"); // Read only once
= File.ReadAllText($"{StartupPath}/MicaDiscordScript.js"); // Read only once
#endif
public static bool NotSupportedBuild => !IsWin11;
public static bool IsWin11 => WindowsBuildNumber is >=22000;
Expand Down Expand Up @@ -164,7 +166,7 @@ void RefreshFrame()
HwndSource mainWindowSrc = HwndSource.FromHwnd(Handle);

#if WINDOWS10_0_17763_0_OR_GREATER
if (!NotSupportedBuild || Settings.Default.UseBackdropAnyway)
if (!NotSupportedBuild || AppSetting.UseBackdropAnyway)
{
mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
DwmApi.DwmExtendFrameIntoClientArea(Handle, new()
Expand Down Expand Up @@ -208,7 +210,7 @@ static bool IsDarkBackground(WinUIColor color)
}

//RefreshDarkMode(dark: Dark);
SetBackdrop((CustomPInvoke.BackdropType)Enum.Parse(typeof(CustomPInvoke.BackdropType), Settings.Default.BackdropType, ignoreCase: true));
SetBackdrop((CustomPInvoke.BackdropType)Enum.Parse(typeof(CustomPInvoke.BackdropType), AppSetting.BackdropType, ignoreCase: true));
#else
ThemeChanged += RefreshFrame;
#endif
Expand Down Expand Up @@ -261,7 +263,7 @@ static bool IsDarkBackground(WinUIColor color)
RefreshFrame();
};

CoreWebView2.Settings.AreDevToolsEnabled = Settings.Default.EnableDevTools;
CoreWebView2.Settings.AreDevToolsEnabled = AppSetting.EnableDevTools;
void DevToolsCheck(object _, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.I && Control.ModifierKeys == (Keys.Control | Keys.Shift))
Expand All @@ -274,9 +276,9 @@ void DevToolsCheck(object _, System.Windows.Input.KeyEventArgs e)
e.Handled = false;
return;
OK:
if (Settings.Default.EnableDevTools)
if (AppSetting.EnableDevTools)
{
if (Settings.Default.ReplaceDiscordBackground)
if (AppSetting.ReplaceDiscordBackground)
{
#if WINDOWS10_0_17763_0_OR_GREATER
WinUIColor PrimaryColor = UISettings.GetColorValue(UIColorType.AccentLight3);
Expand Down Expand Up @@ -323,7 +325,7 @@ void DevToolsCheck(object _, System.Windows.Input.KeyEventArgs e)
{

if (!WebView.Source.OriginalString.Contains("discord.com")) return;
DiscordEffectApplied = Settings.Default.ReplaceDiscordBackground;
DiscordEffectApplied = AppSetting.ReplaceDiscordBackground;
if (DiscordEffectApplied)
{
var Dark = (await WebView.CoreWebView2.ExecuteScriptAsync("document.getElementsByTagName('html')[0].classList.contains('theme-dark')")) == "true";
Expand Down Expand Up @@ -408,7 +410,7 @@ await WebView.CoreWebView2.ExecuteScriptAsync($@"

Closing += (_, e) =>
{
if (!ForceClose && Settings.Default.UseSystemTray)
if (!ForceClose && AppSetting.UseSystemTray)
{
e.Cancel = true;
Hide();
Expand Down Expand Up @@ -498,12 +500,12 @@ async void InitializeAsync()
SettingsDialog.OnSettingsChanged += () =>
{
#if WINDOWS10_0_17763_0_OR_GREATER
SetBackdrop((CustomPInvoke.BackdropType)Enum.Parse(typeof(CustomPInvoke.BackdropType), Settings.Default.BackdropType, ignoreCase: true));
SetBackdrop((CustomPInvoke.BackdropType)Enum.Parse(typeof(CustomPInvoke.BackdropType), AppSetting.BackdropType ?? "Mica", ignoreCase: true));
#endif
var w = WebView.CoreWebView2;
if (w != null)
{
w.Settings.AreDevToolsEnabled = Settings.Default.EnableDevTools;
w.Settings.AreDevToolsEnabled = AppSetting.EnableDevTools;
}
};
//Icon = ImageSourceFromBitmap(ProgramResources.Logo);
Expand Down
23 changes: 18 additions & 5 deletions Mica Discord WPF/Mica Discord WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net6.0-windows10.0.17763.0;net6.0-windows7.0</TargetFrameworks>
<!--<TargetFrameworks>net6.0-windows10.0.17763.0;net6.0-windows7.0</TargetFrameworks>-->
<TargetFramework>net6.0-windows10.0.17763.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyName>MicaDiscord</AssemblyName>
Expand All @@ -14,10 +15,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SupportedOSPlatformVersions>10.0.17763.0;7.0</SupportedOSPlatformVersions>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0-windows10.0.17763.0' ">
<!--<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0-windows10.0.17763.0' ">
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>
</PropertyGroup>-->
<ItemGroup>
<Compile Remove="Experimental\**" />
<EmbeddedResource Remove="Experimental\**" />
Expand Down Expand Up @@ -66,12 +68,14 @@
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1248-prerelease">
<Aliases>WV2</Aliases>
</PackageReference>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.3" />

<PackageReference Include="PInvoke.DwmApi" Version="0.7.104" />
<PackageReference Include="PInvoke.UxTheme" Version="0.7.104" />
<PackageReference Include="PInvoke.Win32" Version="0.7.104" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows10.0.17763.0' ">
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
Expand All @@ -88,6 +92,11 @@
<Compile Update="ModernContextMenuForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Expand All @@ -100,6 +109,10 @@
<None Update="Resources\Mica Discord.ico">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Update="The CSS - Fluent.css">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion Mica Discord WPF/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 65 additions & 23 deletions Mica Discord WPF/SettingsDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
using System;
using CustomPInvoke;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicaDiscord;
#if WINDOWS10_0_17763_0_OR_GREATER
using Windows.Storage;
#endif

namespace MicaDiscord;
#if WINDOWS10_0_17763_0_OR_GREATER
static class Setting {
static ApplicationDataContainer ApplicationSetting = ApplicationData.Current.LocalSettings;
public static void Save() { /* Do Nothing */ }
public static bool ReplaceDiscordBackground
{
get => (bool)(ApplicationSetting.Values[nameof(ReplaceDiscordBackground)] ?? false);
set => ApplicationSetting.Values[nameof(ReplaceDiscordBackground)] = value;
}
public static bool UseBackdropAnyway
{
get => (bool)(ApplicationSetting.Values[nameof(UseBackdropAnyway)] ?? false);
set => ApplicationSetting.Values[nameof(UseBackdropAnyway)] = value;
}
public static bool UseSystemTray
{
get => (bool)(ApplicationSetting.Values[nameof(UseSystemTray)] ?? true);
set => ApplicationSetting.Values[nameof(UseSystemTray)] = value;
}
public static bool EnableDevTools
{
get => (bool)(ApplicationSetting.Values[nameof(EnableDevTools)] ?? false);
set => ApplicationSetting.Values[nameof(EnableDevTools)] = value;
}
public static bool ModeAwareCSS
{
get => (bool)(ApplicationSetting.Values[nameof(ModeAwareCSS)] ?? true);
set => ApplicationSetting.Values[nameof(ModeAwareCSS)] = value;
}
public static string? BackdropType
{
get => (string?)(ApplicationSetting.Values[nameof(BackdropType)] ?? "Mica");
set => ApplicationSetting.Values[nameof(BackdropType)] = value;
}
}
#endif
/// <summary>
/// Interaction logic for SettingsDialog.xaml
/// </summary>
public partial class SettingsDialog : Grid
{
public bool RequiresReload { get; private set; } = false;
public void ResetRequiresReload() => RequiresReload = false;
#if !WINDOWS10_0_17763_0_OR_GREATER
static Settings Setting = Settings.Default;
#endif
public SettingsDialog()
{
InitializeComponent();
Expand All @@ -22,24 +65,24 @@ public SettingsDialog()
#if DEBUG
ReloadCSSButton.Visibility = Visibility.Hidden;
#endif
Backdrop.SelectedItem = Enum.Parse(typeof(CustomPInvoke.BackdropType), Settings.Default.BackdropType);
ReplaceBackgroundToggle.Content = Settings.Default.ReplaceDiscordBackground ? "Disable" : "Enable";
UseBackdropAnyway.Content = Settings.Default.UseBackdropAnyway ? "Use Solid Color" : "Enable Anyway";
Systray.IsChecked = Settings.Default.UseSystemTray;
DevTools.Content = Settings.Default.EnableDevTools ? "Disable" : "Enable";
ModeAwareCSS.IsChecked = Settings.Default.ModeAwareCSS;
Backdrop.SelectedItem = Enum.Parse(typeof(BackdropType), Settings.Default.BackdropType);
ReplaceBackgroundToggle.Content = Setting.ReplaceDiscordBackground ? "Disable" : "Enable";
UseBackdropAnyway.Content = Setting.UseBackdropAnyway ? "Use Solid Color" : "Enable Anyway";
Systray.IsChecked = Setting.UseSystemTray;
DevTools.Content = Setting.EnableDevTools ? "Disable" : "Enable";
ModeAwareCSS.IsChecked = Setting.ModeAwareCSS;
RequiresReload = false;
}
};
Backdrop.SelectionChanged += (_, _) =>
{
Settings.Default.BackdropType = Backdrop.SelectedItem.ToString();
Settings.Default.Save();
Setting.BackdropType = Backdrop.SelectedItem.ToString();
Setting.Save();
OnSettingsChanged?.Invoke();
};
ReplaceBackgroundToggle.Click += (_, _) =>
{
bool newValue = !Settings.Default.ReplaceDiscordBackground;
bool newValue = !Setting.ReplaceDiscordBackground;
if (newValue)
{
if (MessageBox.Show(
Expand All @@ -55,9 +98,9 @@ public SettingsDialog()
!= MessageBoxResult.Yes)
return;
}
Settings.Default.ReplaceDiscordBackground = newValue;
Setting.ReplaceDiscordBackground = newValue;
ReplaceBackgroundToggle.Content = newValue ? "Disable" : "Enable";
Settings.Default.Save();
Setting.Save();
OnSettingsChanged?.Invoke();
RequiresReload = true;
};
Expand All @@ -79,9 +122,9 @@ public SettingsDialog()
!= MessageBoxResult.Yes)
return;
}
Settings.Default.EnableDevTools = newValue;
Setting.EnableDevTools = newValue;
DevTools.Content = newValue ? "Disable" : "Enable";
Settings.Default.Save();
Setting.Save();
OnSettingsChanged?.Invoke();
RequiresReload = true;
};
Expand All @@ -100,9 +143,9 @@ public SettingsDialog()
!= MessageBoxResult.Yes)
return;
}
Settings.Default.UseBackdropAnyway = newValue;
Setting.UseBackdropAnyway = newValue;
UseBackdropAnyway.Content = newValue ? "Use Solid Color" : "Enable Anyway";
Settings.Default.Save();
Setting.Save();
OnSettingsChanged?.Invoke();
RequiresReload = true;
};
Expand All @@ -122,20 +165,19 @@ private void OpenAppFolder(object sender, RoutedEventArgs e)

private void SystrayToggled(object sender, RoutedEventArgs e)
{
Settings.Default.UseSystemTray = Systray.IsChecked ?? false;
Settings.Default.Save();
Setting.UseSystemTray = Systray.IsChecked ?? false;
Setting.Save();
}
private void ModeAwareCSSToggled(object sender, RoutedEventArgs e)
{
Settings.Default.ModeAwareCSS = ModeAwareCSS.IsChecked ?? false;
Settings.Default.Save();
Setting.ModeAwareCSS = ModeAwareCSS.IsChecked ?? false;
Setting.Save();
RequiresReload = true;
}

private void ReloadCSS(object sender, RoutedEventArgs e)
{
#if DEBUG
#else
#if !DEBUG
MainWindow.DefinedCSS = System.IO.File.ReadAllText("./The CSS.css");
RequiresReload = true;
#endif
Expand Down
Loading

0 comments on commit 07538de

Please sign in to comment.