Skip to content

Commit

Permalink
Store Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 26, 2023
1 parent 599db00 commit e9f3041
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 36 deletions.
8 changes: 8 additions & 0 deletions src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
<ui:ProgressRing IsIndeterminate="True" Width="160" Height="160" />
</Grid>

<Grid x:Name="Warn" Visibility="Hidden">
<Grid.Background>
<SolidColorBrush Color="{DynamicResource ApplicationBackgroundColor}" Opacity="0.5" />
</Grid.Background>

<ui:ProgressRing IsIndeterminate="False" Foreground="Crimson" Progress="100" Width="160" Height="160" />
</Grid>

<Grid x:Name="Card" Visibility="Hidden">
<Grid.Background>
<ImageBrush x:Name="Imagine" Stretch="UniformToFill" ImageSource="{x:Null}" />
Expand Down
86 changes: 54 additions & 32 deletions src/Portal/Sucrose.Portal/Views/Controls/StoreCard.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void MenuInstall_Click(object sender, RoutedEventArgs e)
Start();
}

private async void DownloadCache()
private async Task<bool> DownloadCache()
{
if (SPMI.StoreDownloader.ContainsKey(Theme))
{
Expand All @@ -112,19 +112,31 @@ private async void DownloadCache()
}

Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo));

return true;
}
else
{
SPMI.StoreDownloader[Theme] = true;
SPMI.StoreDownloader[Theme] = false;

SSSHD.Cache(Wallpaper, Theme, Agent, Key);
SPMI.StoreDownloader[Theme] = SSSHD.Cache(Wallpaper, Theme, Agent, Key);

while (!SPMI.StoreDownloading.ContainsKey(Theme) || !SPMI.StoreDownloading[Theme])
if (SPMI.StoreDownloader[Theme])
{
await Task.Delay(100);
}
while (!SPMI.StoreDownloading.ContainsKey(Theme) || !SPMI.StoreDownloading[Theme])
{
await Task.Delay(100);
}

Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo));
Info = SSTHI.ReadJson(Path.Combine(Theme, SMR.SucroseInfo));

return true;
}
else
{
SPMI.StoreDownloader.Remove(Theme);
return false;
}
}
}

Expand Down Expand Up @@ -230,48 +242,58 @@ private void ContextMenu_Opened(object sender, RoutedEventArgs e)

private async void StoreCard_Loaded(object sender, RoutedEventArgs e)
{
await Task.Run(DownloadCache);
bool Result = await Task.Run(DownloadCache);

try
{
ToolTip TitleTip = new()
if (Result)
{
Content = Info.Title
};
ToolTip TitleTip = new()
{
Content = Info.Title
};

ToolTip DescriptionTip = new()
{
Content = Info.Description
};
ToolTip DescriptionTip = new()
{
Content = Info.Description
};

ThemeTitle.ToolTip = TitleTip;
ThemeDescription.ToolTip = DescriptionTip;
ThemeTitle.ToolTip = TitleTip;
ThemeDescription.ToolTip = DescriptionTip;

ThemeTitle.Text = Info.Title.Length > SMMM.TitleLength ? $"{SHA.Cut(Info.Title, SMMM.TitleLength)}..." : Info.Title;
ThemeDescription.Text = Info.Description.Length > SMMM.DescriptionLength ? $"{SHA.Cut(Info.Description, SMMM.DescriptionLength)}..." : Info.Description;
ThemeTitle.Text = Info.Title.Length > SMMM.TitleLength ? $"{SHA.Cut(Info.Title, SMMM.TitleLength)}..." : Info.Title;
ThemeDescription.Text = Info.Description.Length > SMMM.DescriptionLength ? $"{SHA.Cut(Info.Description, SMMM.DescriptionLength)}..." : Info.Description;

string ImagePath = Path.Combine(Theme, Info.Thumbnail);
string ImagePath = Path.Combine(Theme, Info.Thumbnail);

if (File.Exists(ImagePath))
{
Imagine.ImageSource = await Loader.LoadOptimalAsync(ImagePath);
}
if (File.Exists(ImagePath))
{
Imagine.ImageSource = await Loader.LoadOptimalAsync(ImagePath);
}

if (Info.AppVersion.CompareTo(SHV.Entry()) > 0)
{
DownloadSymbol.Visibility = Visibility.Hidden;
IncompatibleVersion.Visibility = Visibility.Visible;
}
if (Info.AppVersion.CompareTo(SHV.Entry()) > 0)
{
DownloadSymbol.Visibility = Visibility.Hidden;
IncompatibleVersion.Visibility = Visibility.Visible;
}

await Task.Delay(100);
await Task.Delay(100);

Card.Visibility = Visibility.Visible;
Progress.Visibility = Visibility.Collapsed;
Card.Visibility = Visibility.Visible;
Progress.Visibility = Visibility.Collapsed;
}
else
{
Warn.Visibility = Visibility.Visible;
Progress.Visibility = Visibility.Collapsed;
}

Dispose();
}
catch
{
Warn.Visibility = Visibility.Visible;
Progress.Visibility = Visibility.Collapsed;
Dispose();
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/Shared/Sucrose.Shared.Store/Helper/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,18 @@ public static bool Cache(KeyValuePair<string, SSSIW> Wallpaper, string Theme, st

InitializeClient(Agent, Key);

using HttpResponseMessage ResponseInfo = SSSMI.Client.GetAsync($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{SMR.SucroseInfo}").Result;
using HttpResponseMessage ResponseCover = SSSMI.Client.GetAsync($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{Wallpaper.Value.Cover}").Result;
using HttpResponseMessage ResponseInfo = SSSMI.Client.GetAsync(EncodeSpacesOnly($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{SMR.SucroseInfo}")).Result;
using HttpResponseMessage ResponseCover = SSSMI.Client.GetAsync(EncodeSpacesOnly($"{SMR.RawWebsite}/{Wallpaper.Value.Source}/{Wallpaper.Key}/{Wallpaper.Value.Cover}")).Result;

ResponseInfo.EnsureSuccessStatusCode();
ResponseCover.EnsureSuccessStatusCode();
try
{
ResponseInfo.EnsureSuccessStatusCode();
ResponseCover.EnsureSuccessStatusCode();
}
catch
{
return false;
}

if (ResponseInfo.IsSuccessStatusCode && ResponseCover.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -176,6 +183,11 @@ public static async Task<bool> Theme(string Source, string Output, string Agent,
return await DownloadFolder(Source, Output, Agent, Keys, Key, Sub);
}

private static string EncodeSpacesOnly(string Source)
{
return Source.Replace(" ", "%20");
}

private static void InitializeClient(string Agent, string Key)
{
SSSHS.Apply();
Expand Down

0 comments on commit e9f3041

Please sign in to comment.