Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	update/DesktopMagic.zip
#	update/updateInfo.json
  • Loading branch information
Stone-Red-Code committed Nov 6, 2021
1 parent 921d6df commit ed84fe3
Show file tree
Hide file tree
Showing 50 changed files with 1,721 additions and 1,324 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ obj/
*.user
*.userosscache
*.sln.docstates
*GPUCache/

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
Binary file modified src/DesktopMagic.Installer/DesktopMagic-Installer.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion src/DesktopMagic.Installer/Installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "DesktopMagic"
#define MyAppVersion "0.0.3.0"
#define MyAppVersion "0.0.3.1"
#define MyAppPublisher "Stone_Red"
#define MyAppExeName "DesktopMagic.exe"

Expand Down
28 changes: 22 additions & 6 deletions src/DesktopMagic/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Stone_Red_Utilities.Logging;

using System;
using System.IO;
using System.Threading;
using System.Windows;

Expand All @@ -18,7 +19,7 @@ public partial class App : Application
#if DEBUG
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
#else
private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
#endif

public const string AppName = "Desktop Magic";
Expand All @@ -33,11 +34,11 @@ public App()
// Try to grab mutex
_mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew);

//check if creating new was succesfull
//check if creating new was successful
if (!createdNew)
{
Logger.Log("Shutting down because other instance already running.", "Setup");
//Shutdown Aplication
//Shutdown Application
Current.Shutdown();
}
else
Expand All @@ -59,7 +60,7 @@ private void Updater_UpdateAvailible(string version, string additionalInformatio

private void Updater_NoUpdateAvailible()
{
Logger.Log("No update avalible.", "Updater");
Logger.Log("No update available.", "Updater");
}

private void Updater_OnException(Exception exception)
Expand Down Expand Up @@ -104,7 +105,7 @@ private void Setup()
InfoConfig = new OutputConfig()
{
Color = ConsoleColor.White,
LogTarget = LogTarget.Console | LogTarget.File,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
DebugConfig = new OutputConfig()
Expand All @@ -114,9 +115,24 @@ private void Setup()
},
FormatConfig = new FormatConfig()
{
DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n> at {{{LogFormatType.LineNumber},3}} | {{{LogFormatType.FilePath}}}"
DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
}
};

try
{
if (!Directory.Exists(ApplicationDataPath))
{
_ = Directory.CreateDirectory(ApplicationDataPath);
}
Logger.Log("Created ApplicationData Folder", "Main");
}
catch (Exception ex)
{
Logger.Log(ex.Message, "Setup", LogSeverity.Error);
_ = MessageBox.Show(ex.ToString());
}

Logger.ClearLogFile(LogSeverity.Info);
Logger.Log("Log setup complete.", "Setup");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
x:Name="window">
<Grid>
<Rectangle x:Name="panel" Fill="#4CBAFFEF" Stroke="White" Margin="0,0,0,0" Visibility="Collapsed" />
<Viewbox StretchDirection="DownOnly" Stretch="Uniform">
<TextBlock x:Name="textBlock" FontSize="999" Foreground="White" Text="CPU: 000%" IsHitTestVisible="False" />
<Border x:Name="border"/>
<Viewbox x:Name="viewBox" StretchDirection="Both" Stretch="Uniform">
<Viewbox.Clip>
<RectangleGeometry x:Name="rectangleGeometry" RadiusX="{Binding ElementName=border, Path=CornerRadius.TopLeft}" RadiusY="{Binding ElementName=border, Path=CornerRadius.TopLeft}" Rect="{Binding ElementName=border}"/>
</Viewbox.Clip>
<DockPanel x:Name="dockPanel">
<TextBlock x:Name="textBlock" Foreground="White" FontSize="100" Text="CPU: " IsHitTestVisible="False" />
<TextBlock x:Name="valueTextBlock" TextAlignment="Right" FontSize="100" Foreground="White" Text="000%" IsHitTestVisible="False" />
</DockPanel>
</Viewbox>
</Grid>
<WindowChrome.WindowChrome>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.Win32;
using DesktopMagic.Helpers;

using Microsoft.Win32;

using System;
using System.Diagnostics;
using System.Timers;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;

namespace DesktopMagic
{
/// <summary>
/// Interaktionslogik für TimeWindow.xaml
/// </summary>
public partial class CpuUsageWindow : Window
{
private RegistryKey key;
Expand Down Expand Up @@ -41,7 +41,7 @@ public CpuUsageWindow()

Timer t = new Timer();
t.Interval = 100;
t.Elapsed += T_Elapsed;
t.Elapsed += UpdateTimer_Elapsed;
t.Start();

Timer valueTimer = new Timer();
Expand All @@ -68,23 +68,37 @@ protected override void OnSourceInitialized(EventArgs e)
WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE);
}

private void T_Elapsed(object sender, ElapsedEventArgs e)
private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(() =>
{
if (MainWindow.EditMode)
{
panel.Visibility = Visibility.Visible;
tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10;
WindowPos.SetIsLocked(this, false);
ResizeMode = ResizeMode.CanResize;
}
else
{
panel.Visibility = Visibility.Collapsed;
tileBar.CaptionHeight = 0;
WindowPos.SetIsLocked(this, true);
ResizeMode = ResizeMode.NoResize;
}

textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont);
textBlock.Foreground = MainWindow.GlobalColor;
rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight);
border.Background = MainWindow.Theme.BackgroundBrush;
border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius);
viewBox.Margin = new Thickness(MainWindow.Theme.Margin);
border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2;
border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2;
textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
textBlock.Foreground = MainWindow.Theme.PrimaryBrush;
valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font);
valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush;

ClculateWidth();
});
}

Expand All @@ -93,13 +107,24 @@ private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e)
string cpuUsage = GetCpuUsage();
Dispatcher.Invoke(() =>
{
textBlock.Text = cpuUsage;
valueTextBlock.Text = cpuUsage;
});
}

private void ClculateWidth()
{
string template = "CPU: ###%";
double lenght = 0;
for (int i = 0; i < 9; i++)
{
lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght);
}
dockPanel.Width = lenght;
}

private string GetCpuUsage()
{
return "CPU: " + ((int)cpuCounter.NextValue()).ToString().PadLeft(3, '0') + "%";
return $"{(int)cpuCounter.NextValue()}%";
}

private void Window_LocationChanged(object sender, EventArgs e)
Expand Down
50 changes: 50 additions & 0 deletions src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using DesktopMagicPluginAPI;

using System;
using System.Drawing;
using System.Drawing.Text;

namespace DesktopMagic.BuiltInWindowElements
{
internal class DatePlugin : Plugin
{
public override int UpdateInterval => 1000;

private DateTime oldDateTime = new DateTime();
private Color oldColor = Color.White;
private string oldFont;

public override Bitmap Main()
{
if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font)
{
return null;
}

oldDateTime = DateTime.Now;
oldColor = Application.Theme.PrimaryColor;
oldFont = Application.Theme.Font;

string date = DateTime.Now.ToLongDateString();

Font font = new Font(Application.Theme.Font, 200);

Bitmap bmp = new Bitmap(1, 1);
bmp.SetResolution(100, 100);
using Graphics tmpGr = Graphics.FromImage(bmp);
tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias;

SizeF size = tmpGr.MeasureString(date, font);

bmp = new Bitmap((int)size.Width, (int)size.Height);
bmp.SetResolution(100, 100);

using Graphics gr = Graphics.FromImage(bmp);

gr.TextRenderingHint = TextRenderingHint.AntiAlias;
gr.DrawString(date, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0);

return bmp;
}
}
}
Loading

0 comments on commit ed84fe3

Please sign in to comment.