Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusnl committed Dec 17, 2023
2 parents 5183489 + 13e26bb commit c10ed51
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 54 deletions.
16 changes: 10 additions & 6 deletions CollapseLauncher/Classes/EventsManagement/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ internal static class LauncherUpdateWatcher
private static LauncherUpdateInvoker invoker = new LauncherUpdateInvoker();
public static void GetStatus(LauncherUpdateProperty e) => invoker.GetStatus(e);
public static bool isUpdateCooldownActive;
public static bool isMetered = true;
public static bool isMetered
{
get
{
NetworkCostType currentNetCostType = NetworkInformation.GetInternetConnectionProfile()?.GetConnectionCost().NetworkCostType ?? NetworkCostType.Fixed;
return !(currentNetCostType == NetworkCostType.Unrestricted || currentNetCostType == NetworkCostType.Unknown);
}
}

public static async void StartCheckUpdate(bool forceUpdate)
{
NetworkCostType currentNetCostType = NetworkInformation.GetInternetConnectionProfile()?.GetConnectionCost().NetworkCostType ?? NetworkCostType.Fixed;
isMetered = !(currentNetCostType == NetworkCostType.Unrestricted || currentNetCostType == NetworkCostType.Unknown);

UpdateChannelName = IsPreview ? "preview" : "stable";
while (true)
{
Expand Down Expand Up @@ -78,8 +82,8 @@ public static async void StartCheckUpdate(bool forceUpdate)
LogWriteLine($"Update check has failed! Will retry in 15 mins.\r\n{ex}", LogType.Error, true);
}
}
// Delay for 15 minutes
await Task.Delay(900 * 1000);
// Delay for 15 to 60 minutes depending on metered
await Task.Delay((isMetered ? 3600 : 900) * 1000);
// Reset isUpdateRecentlyInvoked to release the lock
isUpdateCooldownActive = false;
}
Expand Down
2 changes: 0 additions & 2 deletions CollapseLauncher/Classes/RegionManagement/RegionManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ public static async ValueTask<string> GetCachedSpritesAsync(string URL, Cancella
if (!IsFileCompletelyDownloaded(fInfo))
{
await TryDownloadToCompleteness(URL, fInfo, token);
return URL;
}

return cachePath;
}

Expand Down
17 changes: 15 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public void InitializeWindowSettings()
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
incps.SetRegionRects(NonClientRegionKind.Close, null);
incps.SetRegionRects(NonClientRegionKind.Minimize, null);
var safeArea = new RectInt32[] { new(m_appWindow.Size.Width - (int)((144 + 12) * m_appDPIScale), 0, (int)((144 + 12) * m_appDPIScale), (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
EnableNonClientArea();
}
else
{
Expand All @@ -173,6 +172,20 @@ public void InitializeWindowSettings()
m_oldWndProc = SetWindowLongPtr(m_windowHandle, GWLP_WNDPROC, pWndProc);
}

public void EnableNonClientArea()
{
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
var safeArea = new RectInt32[] { new(m_appWindow.Size.Width - (int)((144 + 12) * m_appDPIScale), 0, (int)((144 + 12) * m_appDPIScale), (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
}

public void DisableNonClientArea()
{
var incps = InputNonClientPointerSource.GetForWindowId(m_windowID);
var safeArea = new RectInt32[] { new(0, 0, m_appWindow.Size.Width, (int)(48 * m_appDPIScale)) };
incps.SetRegionRects(NonClientRegionKind.Passthrough, safeArea);
}

private delegate IntPtr WndProcDelegate(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam);

private IntPtr WndProc(IntPtr hwnd, uint msg, UIntPtr wParam, IntPtr lParam)
Expand Down
6 changes: 1 addition & 5 deletions CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,8 @@ private void LaunchUpdater(string ChannelName)

private async void CheckUpdate(object sender, RoutedEventArgs e)
{
var isMetered = true;
NetworkCostType currentNetCostType = NetworkInformation.GetInternetConnectionProfile()?.GetConnectionCost().NetworkCostType ?? NetworkCostType.Fixed;
if (currentNetCostType == NetworkCostType.Unrestricted || currentNetCostType == NetworkCostType.Unknown)
isMetered = false;

if (isMetered)
if (LauncherUpdateWatcher.isMetered)
{
switch (await Dialog_MeteredConnectionWarning(Content))
{
Expand Down
40 changes: 30 additions & 10 deletions CollapseLauncher/XAMLs/MainApp/Pages/UpdatePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using System.Threading.Tasks;
using static CollapseLauncher.InnerLauncherConfig;
using static CollapseLauncher.Dialogs.SimpleDialogs;
using static Hi3Helper.Locale;
using static Hi3Helper.Shared.Region.LauncherConfig;

Expand Down Expand Up @@ -49,7 +50,6 @@ private async void LoadedAsyncRoutine(object sender, RoutedEventArgs e)

try
{
// Wait for countdown
await WaitForCountdown();
await StartUpdateRoutine();
}
Expand All @@ -68,15 +68,22 @@ private async Task StartUpdateRoutine()
{
try
{
// Hide/Show progress
UpdateCountdownPanel.Visibility = Visibility.Collapsed;
UpdateBox.Visibility = Visibility.Collapsed;
CancelUpdateCountdownBox.Visibility = Visibility.Collapsed;
AskUpdateCheckbox.Visibility = Visibility.Collapsed;
UpdateProgressBox.Visibility = Visibility.Visible;

// Start Squirrel update routine
await GetSquirrelUpdate();
if (LauncherUpdateWatcher.isMetered)
{
switch (await Dialog_MeteredConnectionWarning(Content))
{
case ContentDialogResult.Primary:
await _StartUpdateRoutine();
break;
case ContentDialogResult.None:
CancelUpdateCountdownBox.Visibility = Visibility.Collapsed;
UpdateCountdownPanel.Visibility = Visibility.Collapsed;
UpdateBox.Visibility = Visibility.Visible;
return;
}
}

await _StartUpdateRoutine();
}
catch (OperationCanceledException)
{
Expand All @@ -91,6 +98,19 @@ private async Task StartUpdateRoutine()
}
}

private async Task _StartUpdateRoutine()
{
// Hide/Show progress
UpdateCountdownPanel.Visibility = Visibility.Collapsed;
UpdateBox.Visibility = Visibility.Collapsed;
CancelUpdateCountdownBox.Visibility = Visibility.Collapsed;
AskUpdateCheckbox.Visibility = Visibility.Collapsed;
UpdateProgressBox.Visibility = Visibility.Visible;

// Start Squirrel update routine
await GetSquirrelUpdate();
}

private async Task GetSquirrelUpdate()
{
string ChannelName = IsPreview ? "Preview" : "Stable";
Expand Down
49 changes: 27 additions & 22 deletions CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,36 @@
<StackPanel x:Name="MenuPanel" CornerRadius="16"
Margin="0,32,64,32" Padding="32" Shadow="{ThemeResource SharedShadow}" Background="{ThemeResource DialogAcrylicBrush}">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Select your language"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectLang}"
TextAlignment="Left"
HorizontalAlignment="Left" Margin="0,0,0,8"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
<TextBlock Text="Please select your language to start this launcher for the first time!"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectLangDesc}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap"/>
<ComboBox PlaceholderText="Select your language"
<ComboBox Name="SelectLang" SelectedIndex="{x:Bind SelectedLangIndex, Mode=TwoWay}"
Margin="0,16"
HorizontalAlignment="Left" VerticalAlignment="Center"
SelectionChanged="ComboBox_SelectionChanged" ItemsSource="{x:Bind LangList, Mode=OneTime}"/>
ItemsSource="{x:Bind LangList}"
MaxDropDownHeight="1000"
DropDownOpened="SelectLang_OnDropDownOpened"
DropDownClosed="SelectLang_OnDropDownClosed"/>
</StackPanel>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock Text="Select your preferred window size"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectWindowSize}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
<ComboBox SelectedIndex="{x:Bind SelectedWindowSizeProfile, Mode=TwoWay}"
Margin="0,16">
<ComboBoxItem Content="Normal"/>
<ComboBoxItem Content="Small"/>
<ComboBox SelectedIndex="{x:Bind SelectedWindowSizeProfile, Mode=TwoWay}"
Margin="0,16" Name="SelectWindowSize">
<ComboBoxItem Content="{x:Bind helper:Locale.Lang._SettingsPage.AppWindowSize_Normal}"/>
<ComboBoxItem Content="{x:Bind helper:Locale.Lang._SettingsPage.AppWindowSize_Small}"/>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Select your preferred CDN"
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.SelectCDN}"
TextAlignment="Left"
HorizontalAlignment="Left"
TextWrapping="Wrap" Style="{ThemeResource BodyStrongTextBlockStyle}" FontSize="18"/>
Expand All @@ -61,18 +64,20 @@
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<StackPanel MaxWidth="380">
<TextBlock>
<Run Text="What is a CDN?" FontWeight="Bold" FontSize="20"/>
<Run Text="short for" FontSize="12"/>
<Run Text="Content Delivery Network" FontWeight="Bold" FontSize="12"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_1}" FontWeight="Bold" FontSize="20"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_2}" FontSize="12"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_3}" FontWeight="Bold" FontSize="12"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpTitle_4}" FontSize="12"/>
</TextBlock>
<TextBlock TextWrapping="Wrap" MaxWidth="380" Margin="0,8,0,0">
<Run Text="CDN" FontWeight="Bold"/>
<Run Text="is a system used to make launcher files available to a larger audience, quickly and efficiently." TextDecorations="None"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_1}"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_2}" FontWeight="Bold"/><!--
--><Run Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_3}"/>
</TextBlock>
<TextBlock Text="Collapse selects GitHub as the default provider."/>
<TextBlock Text="CDNs available:" FontWeight="Bold" FontSize="20" Margin="0,12,0,0"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.CDNHelpDetail_4}"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._StartupPage.CDNsAvailable}" FontWeight="Bold" FontSize="20" Margin="0,12,0,0"/>
<ItemsControl ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxWidth="380" Margin="0,0,0,-8">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="innerConfig:CDNURLProperty">
Expand All @@ -88,7 +93,7 @@
</Button.Flyout>
</Button>
</StackPanel>
<RadioButtons SelectedIndex="{x:Bind SelectedCDN, Mode=TwoWay}" ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxColumns="3">
<RadioButtons Name="SelectCDN" SelectedIndex="{x:Bind SelectedCDN, Mode=TwoWay}" ItemsSource="{x:Bind innerConfig:LauncherConfig.CDNList}" MaxColumns="3">
<RadioButtons.ItemTemplate>
<DataTemplate x:DataType="innerConfig:CDNURLProperty">
<RadioButton>
Expand All @@ -100,14 +105,14 @@
</RadioButtons.ItemTemplate>
</RadioButtons>
</StackPanel>
<Button x:Name="NextBtn" Content="Next" HorizontalAlignment="Left" IsEnabled="False" Width="128" Margin="0,16,0,0"
<Button x:Name="NextBtn" Content="{x:Bind helper:Locale.Lang._Misc.Next}" HorizontalAlignment="Left" Width="128" Margin="0,16,0,0"
VerticalAlignment="Bottom" Style="{ThemeResource AccentButtonStyle}" Click="NextBtn_Click"/>
</StackPanel>
</StackPanel>
<TextBlock Grid.Column="1" Margin="8" VerticalAlignment="Bottom" TextAlignment="Right"
HorizontalAlignment="Right" Opacity="0.50" Foreground="{ThemeResource DefaultFGColorAccentBrush}">
<Run Text="The splash art is a property of"/><LineBreak/>
<Run Text="miHoYo / HoYoverse" FontSize="18" FontWeight="Medium"/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.SplashArt_1}"/><LineBreak/>
<Run Text="{x:Bind helper:Locale.Lang._StartupPage.SplashArt_2}" FontSize="18" FontWeight="Medium"/>
</TextBlock>
</Grid>
</Page>
81 changes: 75 additions & 6 deletions CollapseLauncher/XAMLs/StartUp/StartupLanguageSelect.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using static CollapseLauncher.InnerLauncherConfig;
using static CollapseLauncher.WindowSize.WindowSize;
Expand Down Expand Up @@ -31,12 +32,79 @@ public StartupLanguageSelect()
}
}

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
private static Dictionary<string, string> LangFallbackDict = new()
{
string LangID = LanguageIDIndex[(sender as ComboBox).SelectedIndex];
SetAppConfigValue("AppLanguage", LangID);
LoadLocale(LangID);
NextBtn.IsEnabled = true;
{ "en", "en-us" },
{ "zh", "zh-cn" },
{ "de", "de-de" },
{ "es", "es-419" },
{ "id", "id-id" },
{ "ja", "ja-jp" },
{ "ko", "ko-kr" },
{ "pl", "pl-pl" },
{ "pt", "pt-br" },
{ "ru", "ru-ru" },
{ "th", "th-th" },
{ "vi", "vi-vn" },
};

private string LanguageFallback(string tag)
{
tag = tag.ToLower();
// Traditional Chinese
if (tag == "zh-hant" || tag == "zh-hk" || tag == "zh-mo" || tag == "zh-tw") return "zh-tw";
// Portuguese, Portugal
if (tag == "pt-pt") return "pt-pt";
if (tag.Length < 2) return "en-us";
tag = tag.Substring(0, 2);
return LangFallbackDict.GetValueOrDefault(tag, "en-us");
}

private void RefreshSelection()
{
SelectLang.SelectedIndex = -1;
SelectLang.SelectedIndex = SelectedLangIndex;
SelectWindowSize.SelectedIndex = -1;
SelectWindowSize.SelectedIndex = SelectedWindowSizeProfile;
SelectCDN.UpdateLayout();
SelectCDN.SelectedIndex = SelectedCDN;
}

private int SelectedLangIndex
{
get
{
var langID = GetAppConfigValue("AppLanguage").ToString() ?? LanguageFallback(CultureInfo.InstalledUICulture.Name);
return LanguageNames[langID.ToLower()].LangIndex;
}
set
{
if (value < 0) return;
var langID = LanguageIDIndex[value].ToLower();
if (langID == GetAppConfigValue("AppLanguage").ToString().ToLower()) return;
SetAppConfigValue("AppLanguage", langID);
LoadLocale(langID);

// Update the view
LogWriteLine("Updating the view...");
Bindings.Update();
LogWriteLine("Update bindings done.");
RefreshSelection();
LogWriteLine("Refresh controls done.");
}
}

private void SelectLang_OnDropDownOpened(object sender, object e)
{
// The dropdown panel collides with non-client area, making the first item not clickable.
// Use this to disable whole non-client area temporarily.
(m_window as MainWindow).DisableNonClientArea();
}

private void SelectLang_OnDropDownClosed(object sender, object e)
{
// And restore the nc area to normal state.
(m_window as MainWindow).EnableNonClientArea();
}

private IEnumerable<string> LangList
Expand All @@ -55,6 +123,7 @@ private int SelectedWindowSizeProfile
}
set
{
if (value < 0) return;
CurrentWindowSizeName = WindowSizeProfilesKey[value];
}
}
Expand All @@ -69,4 +138,4 @@ private int SelectedCDN
}
}
}
}
}
Loading

0 comments on commit c10ed51

Please sign in to comment.