Skip to content

Commit

Permalink
Improve Logger and Add DisplayMode Option
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Oct 14, 2023
1 parent 5947b1b commit b8a1070
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 30 deletions.
5 changes: 2 additions & 3 deletions dev/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class App : Application
public static Window currentWindow = Window.Current;
public IServiceProvider Services { get; }
public new static App Current => (App)Application.Current;
public string AppVersion { get; set; } = VersionHelper.GetVersion();
public string AppVersion { get; set; } = ApplicationHelper.GetAppVersion();
public string AppName { get; set; } = "TvTime";

public static T GetService<T>() where T : class
Expand Down Expand Up @@ -88,8 +88,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)

currentWindow.Activate();

AppCenter.Start(Constants.AppCenterKey,
typeof(Analytics), typeof(Crashes));
AppCenter.Start(Constants.AppCenterKey, typeof(Analytics), typeof(Crashes));

if (Settings.UseDeveloperMode)
{
Expand Down
9 changes: 5 additions & 4 deletions dev/Tools/Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace TvTime.Common;
public class Constants
public static class Constants
{
public static readonly string AppName = ApplicationHelper.GetProjectNameAndVersion();
public static readonly string RootDirectoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppName);

public static readonly string AppName = ApplicationHelper.GetAppNameAndVersion().NameAndVersion;
public static readonly string RootDirectoryPath = Path.Combine(ApplicationHelper.GetLocalFolderPath(), AppName);
public static readonly string LogDirectoryPath = Path.Combine(RootDirectoryPath, "Log");
public static readonly string LogFilePath = Path.Combine(LogDirectoryPath, "Log.txt");
public static readonly string AppConfigPath = Path.Combine(RootDirectoryPath, "AppConfig.json");

public const string FileNameRegex = @"(?:hd(?:tv|cam|r)|-|/720p/|/480p/|/1080p/|- -|- -|/|EmpireBestTv|AceMovies|AvaMovie|@Parsi_Ser|mp4|mkv|@Gemovies|GM|AvaMovie|FB|M3|\.)";
Expand Down
9 changes: 3 additions & 6 deletions dev/Tools/Common/LoggerSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ public static class LoggerSetup

public static void ConfigureLogger()
{
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var logFileDirPath = Path.Combine(desktopPath, Constants.AppName);
var logFilePath = Path.Combine(logFileDirPath, "Log.txt");
if (!Directory.Exists(logFileDirPath))
if (!Directory.Exists(Constants.LogDirectoryPath))
{
Directory.CreateDirectory(logFileDirPath);
Directory.CreateDirectory(Constants.LogDirectoryPath);
}

Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", App.Current.AppVersion)
.WriteTo.File(logFilePath, rollingInterval: RollingInterval.Day)
.WriteTo.File(Constants.LogFilePath, rollingInterval: RollingInterval.Day)
.WriteTo.Debug()
.CreateLogger();
}
Expand Down
18 changes: 9 additions & 9 deletions dev/TvTime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<Version>4.4.0</Version>
<Version>4.5.0</Version>
<ImplicitUsings>true</ImplicitUsings>
<LangVersion>Latest</LangVersion>
<AccelerateBuildsInVisualStudio>False</AccelerateBuildsInVisualStudio>
Expand All @@ -24,22 +24,22 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
<PackageReference Include="WinUICommunity.Components" Version="5.2.0" />
<PackageReference Include="WinUICommunity.Core" Version="5.2.0" />
<PackageReference Include="WinUICommunity.LandingPages" Version="5.2.0" />
<PackageReference Include="WinUICommunity.Components" Version="5.3.0" />
<PackageReference Include="WinUICommunity.Core" Version="5.3.1" />
<PackageReference Include="WinUICommunity.LandingPages" Version="5.3.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.53" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.11" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.12" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Segmented" Version="8.0.230907" />
<PackageReference Include="CommunityToolkit.Labs.WinUI.TokenView" Version="0.1.230830" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.3" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Markdown" Version="7.1.2" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions dev/ViewModels/Media/MediaViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CommunityToolkit.Labs.WinUI;
using CommunityToolkit.WinUI.UI;

using HtmlAgilityPack;

using Microsoft.EntityFrameworkCore;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Media.Animation;
Expand Down
2 changes: 1 addition & 1 deletion dev/Views/HomeLandingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
HeaderText="{x:Bind AppInfo}">
<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="OnItemClick">

<ic:EventTriggerBehavior.Actions>
<ic:InvokeCommandAction Command="{x:Bind ViewModel.ItemClickCommand}" />
</ic:EventTriggerBehavior.Actions>
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>
</wuc:AllLandingPage>
</Page>

21 changes: 21 additions & 0 deletions dev/Views/HomeLandingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ public sealed partial class HomeLandingPage : Page
{
public string AppInfo { get; set; }
public HomeLandingViewModel ViewModel { get; }
public static HomeLandingPage Instance { get; set; }
public HomeLandingPage()
{
ViewModel = App.GetService<HomeLandingViewModel>();
this.InitializeComponent();
Instance = this;
AppInfo = $"{App.Current.AppName} v{App.Current.AppVersion}";
UpdateHomeLandingPageCornerRadius();
}

protected override void OnNavigatedTo(NavigationEventArgs e)
Expand All @@ -17,5 +20,23 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
allLandingPage.GetData(ViewModel.JsonNavigationViewService.DataSource);
allLandingPage.OrderBy(i => i.Title);
}

public void UpdateHomeLandingPageCornerRadius()
{
switch (Settings.NavigationViewPaneDisplayMode)
{
case NavigationViewPaneDisplayMode.Auto:
case NavigationViewPaneDisplayMode.Left:
allLandingPage.HeaderGridCornerRadius = new CornerRadius(8, 0, 0, 0);
break;
case NavigationViewPaneDisplayMode.Top:
case NavigationViewPaneDisplayMode.LeftCompact:
allLandingPage.HeaderGridCornerRadius = new CornerRadius(0);
break;

case NavigationViewPaneDisplayMode.LeftMinimal:
break;
}
}
}

5 changes: 4 additions & 1 deletion dev/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:TvTime"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:settings="using:TvTime.Common"
xmlns:wuc="using:WinUICommunity"
mc:Ignorable="d">
<Grid>
Expand Down Expand Up @@ -59,8 +60,10 @@
</wuc:TitleBar>
<NavigationView x:Name="NavView"
Grid.Row="1"
DisplayModeChanged="NavView_DisplayModeChanged"
IsBackButtonVisible="Collapsed"
IsPaneToggleButtonVisible="False">
IsPaneToggleButtonVisible="False"
PaneDisplayMode="{x:Bind settings:AppHelper.Settings.NavigationViewPaneDisplayMode, Mode=OneWay}">

<Frame x:Name="NavFrame"
Navigated="NavFrame_Navigated" />
Expand Down
17 changes: 17 additions & 0 deletions dev/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public void RefreshNavigationViewPaneDisplayMode()
NavView.PaneDisplayMode = Settings.NavigationViewPaneDisplayMode;
}

private void NavView_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
{
if (NavView.PaneDisplayMode == NavigationViewPaneDisplayMode.Top)
{
appTitleBar.IsPaneButtonVisible = false;
}
else
{
appTitleBar.IsPaneButtonVisible = true;
}
}

private void NavViewPaneDisplayModeButton_Click(object sender, RoutedEventArgs e)
{
switch (NavView.PaneDisplayMode)
Expand All @@ -119,6 +131,11 @@ private void NavViewPaneDisplayModeButton_Click(object sender, RoutedEventArgs e
}

Settings.NavigationViewPaneDisplayMode = NavView.PaneDisplayMode;

if (HomeLandingPage.Instance != null)
{
HomeLandingPage.Instance.UpdateHomeLandingPageCornerRadius();
}
}
}

14 changes: 10 additions & 4 deletions dev/Views/Settings/GeneralSettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@
</ComboBox>
</wuc:SettingsCard>

<wuc:SettingsCard Description="By activating this option, if an error or crash occurs, its information will be saved in a file called Log{YYYYMMDD}.txt on A folder named TvTimeVx.x.x, on the desktop"
Header="Developer Mode (Restart Required)"
HeaderIcon="{wuc:BitmapIcon Source=Assets/Fluent/devMode.png}">
<wuc:SettingsExpander Description="By activating this option, if an error or crash occurs, its information will be saved in a file called Log{YYYYMMDD}.txt"
Header="Developer Mode (Restart Required)"
HeaderIcon="{wuc:BitmapIcon Source=Assets/Fluent/devMode.png}">
<ToggleSwitch IsOn="{x:Bind local:AppHelper.Settings.UseDeveloperMode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</wuc:SettingsCard>
<wuc:SettingsExpander.ItemsHeader>
<HyperlinkButton HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left"
Click="NavigateToLogPath_Click"
Content="{x:Bind local:Constants.LogDirectoryPath}" />
</wuc:SettingsExpander.ItemsHeader>
</wuc:SettingsExpander>

<wuc:SettingsExpander Description="following keywords will be removed from movie\series file name, if you see a word that can not be removed from file name you can add your keywords here"
Header="Use Default Regex"
Expand Down
10 changes: 10 additions & 0 deletions dev/Views/Settings/GeneralSettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);
BreadCrumbBarItemText = e.Parameter as string;
}

private async void NavigateToLogPath_Click(object sender, RoutedEventArgs e)
{
string folderPath = (sender as HyperlinkButton).Content.ToString();
if (Directory.Exists(folderPath))
{
Windows.Storage.StorageFolder folder = await Windows.Storage.StorageFolder.GetFolderFromPathAsync(folderPath);
await Windows.System.Launcher.LaunchFolderAsync(folder);
}
}
}

0 comments on commit b8a1070

Please sign in to comment.