Skip to content

Commit

Permalink
update theming, save log on exit, allow log saving in mainwindow, cle…
Browse files Browse the repository at this point in the history
…an up code
  • Loading branch information
Dyvinia committed Oct 24, 2024
1 parent 8f622b7 commit 613bd1d
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 48 deletions.
10 changes: 6 additions & 4 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using DiscordRPC;
using DiscordRPC.Logging;
Expand All @@ -14,7 +12,6 @@
using Plex.ServerApi.PlexModels.OAuth;
using DyviniaUtils;
using DyviniaUtils.Dialogs;
using System.Collections.Generic;

namespace PlexampRPC {

Expand Down Expand Up @@ -107,6 +104,11 @@ protected override async void OnStartup(StartupEventArgs e) {

protected override void OnExit(ExitEventArgs e) {
DiscordClient.Dispose();

try {
File.WriteAllText(Path.Combine(Path.GetDirectoryName(Config.FilePath)!, "log.txt"), Log?.ToString());
}
catch { }
}

private static void DiscordInit() {
Expand Down
5 changes: 4 additions & 1 deletion PlexampRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>

<AssemblyName>PlexampRPC</AssemblyName>
<Version>1.5.1</Version>
<Version>1.5.2</Version>
<Copyright>Copyright © 2024 Dyvinia</Copyright>
<Company>Dyvinia</Company>
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>

<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=$(MSBuildProjectName)\</PathMap>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Themes/DarkTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2">
<!-- Window Colours. Background, Border and TitleBar colours. -->
<SolidColorBrush x:Key="BackgroundColour" Color="#FF2D2D2D" />
<SolidColorBrush x:Key="BackgroundColour" Color="#FF141414" />
<SolidColorBrush x:Key="WindowBorderColour" Color="#FF000000" />
<SolidColorBrush x:Key="WindowTitleColour" Color="#FF000000" />
<!-- Control colour themes. dont mess with em okay unless youre good at styles -->
Expand Down
2 changes: 1 addition & 1 deletion Windows/LogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="Log" Height="500" Width="750"
Style="{DynamicResource CustomWindowStyle}" ResizeMode="CanResize">
<Grid>
<ListBox x:Name="LogBox" Background="#FF141414" Margin="5" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2">
<ListBox x:Name="LogBox" Background="#FF141414" Margin="4" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
Expand Down
56 changes: 31 additions & 25 deletions Windows/LogWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using Microsoft.Win32;

namespace PlexampRPC {
/// <summary>
/// Interaction logic for LogWindow.xaml
/// </summary>
public partial class LogWindow : Window {
private LogWriter writer;

public LogWindow(LogWriter logWriter) {
InitializeComponent();
LogBox.ItemsSource = logWriter.Log;
LogBox.ScrollIntoView(logWriter.Log.Last());

((INotifyCollectionChanged)LogBox.ItemsSource).CollectionChanged += (_, _) => LogBox.ScrollIntoView(logWriter.Log.Last());
writer = logWriter;

LogBox.ItemsSource = writer.Log;
//if (writer.Log.Count > 0)
LogBox.ScrollIntoView(writer.Log.Last());

((INotifyCollectionChanged)LogBox.ItemsSource).CollectionChanged += (_, _) => LogBox.ScrollIntoView(writer.Log.Last());
}

protected override void OnKeyDown(KeyEventArgs e) {
Expand All @@ -29,7 +32,7 @@ protected override void OnKeyDown(KeyEventArgs e) {
CopyToClipboard();

if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
SaveToFile();
writer.SaveAs();
}

private void CopyToClipboard() {
Expand All @@ -41,22 +44,6 @@ private void CopyToClipboard() {
}
Clipboard.SetDataObject(sb.ToString());
}

private void SaveToFile() {
SaveFileDialog dlg = new() {
FileName = "log",
DefaultExt = ".txt",
Filter = "Text (.txt)|*.txt"
};

if (dlg.ShowDialog() == true) {
StringBuilder sb = new();
foreach (LogWriter.LogItem item in LogBox.Items) {
sb.AppendLine($"[{item.Timestamp.ToString("HH:mm:ss")}] {item.Message}");
}
File.WriteAllText(dlg.FileName, sb.ToString());
}
}
}

public class LogWriter : TextWriter {
Expand Down Expand Up @@ -129,5 +116,24 @@ private static string RemoveTags(string text) {
}
return text;
}

public void SaveAs() {
SaveFileDialog dlg = new() {
FileName = "log",
DefaultExt = ".txt",
Filter = "Text (.txt)|*.txt"
};

if (dlg.ShowDialog() == true)
File.WriteAllText(dlg.FileName, ToString());
}

public override string ToString() {
StringBuilder sb = new();
foreach (LogItem item in Log) {
sb.AppendLine($"[{item.Timestamp.ToString("HH:mm:ss")}] {item.Message}");
}
return sb.ToString();
}
}
}
4 changes: 2 additions & 2 deletions Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PlexampRPC"
mc:Ignorable="d"
Title="PlexampRPC" Width="320" SizeToContent="Height" UseLayoutRounding="True"
Title="PlexampRPC" Width="310" SizeToContent="Height" UseLayoutRounding="True"
WindowStartupLocation="CenterScreen"
Icon="/Resources/Icon.ico"
Style="{DynamicResource CustomWindowStyle}" ResizeMode="CanMinimize">
Expand All @@ -16,7 +16,7 @@
</Window.Resources>
<Grid>

<Grid Background="#FF141414" Margin="5">
<Grid Background="#FF141414" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="15"/>
<RowDefinition Height="96"/>
Expand Down
15 changes: 5 additions & 10 deletions Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using DiscordRPC;
using Hardcodet.Wpf.TaskbarNotification;
using Button = DiscordRPC.Button;

namespace PlexampRPC {
/// <summary>
Expand Down Expand Up @@ -236,10 +231,7 @@ private void SetPresence(PresenceData presence) {
Assets = new() {
LargeImageKey = presence.ArtLink,
LargeImageText = presence.ImageTooltip
},
//Buttons = presence.Url != null ? [
// new() { Label = "More...", Url = presence.Url }
//] : null
}
});

PreviewArt.Source = new BitmapImage(new Uri(presence.ArtLink));
Expand Down Expand Up @@ -383,6 +375,9 @@ protected override void OnKeyDown(KeyEventArgs e) {

if (e.Key == Key.F5)
new LogWindow(App.Log!).Show();

if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Control)
App.Log?.SaveAs();
}
}
}
4 changes: 2 additions & 2 deletions Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
xmlns:local="clr-namespace:PlexampRPC"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="PlexampRPC" SizeToContent="Height" UseLayoutRounding="True" Width="200"
Title="PlexampRPC" SizeToContent="Height" UseLayoutRounding="True" Width="190"
WindowStartupLocation="CenterScreen"
Icon="/Resources/Icon.ico"
Style="{DynamicResource CustomWindowStyle}">
<Grid>
<Grid Background="#FF141414" Margin="5">
<Grid Background="#FF141414" Margin="0">
<StackPanel Margin="20">
<StackPanel>
<TextBlock TextWrapping="Wrap" Text="Options" Foreground="#FFF1F1F1" FontSize="14" Height="20" FontWeight="Bold" VerticalAlignment="Top"/>
Expand Down
3 changes: 1 addition & 2 deletions Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
Expand Down

0 comments on commit 613bd1d

Please sign in to comment.