diff --git a/src/main/Constants.cs b/src/main/Constants.cs index 6f490d6..887ccfd 100644 --- a/src/main/Constants.cs +++ b/src/main/Constants.cs @@ -6,14 +6,24 @@ namespace BrikInstaller; public static class Constants { public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; - public static readonly string os = OsHelper.getOperatingSystem(); - public static readonly string arch = OsHelper.getArchitecture(); + public static readonly string Os = OsHelper.getOperatingSystem(); + public static readonly string Arch = OsHelper.getArchitecture(); - public static readonly string env = "DEV"; - public static readonly string __dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; + public static readonly string Env = "DEV"; public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory; + public static readonly string CurrentWorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; public static class URLs { - public static readonly string basePoint = "https://brik.azures.fr/products"; + public static readonly string ApiPoint = "https://brik.azures.fr"; + public static class Endpoints { + public static string Manifest(string softName, string os, string arch) + => $"{ApiPoint}/products/{softName}/{os}-{arch}/manifest"; + + public static string Download(string softName, string os, string arch) + => $"{ApiPoint}/products/{softName}/{os}-{arch}/download/"; + + public static string Metadata() + => $"{ApiPoint}/metadata"; + } } } \ No newline at end of file diff --git a/src/main/Program.cs b/src/main/Program.cs index 0e0309e..e03f819 100644 --- a/src/main/Program.cs +++ b/src/main/Program.cs @@ -14,10 +14,10 @@ class Program{ } public static PhotinoWindow CreateMainWindow() { - BrikPackage bpkg = new BrikPackage(Path.Combine(Constants.__dirname, "root.dat"), 66); + BrikPackage bpkg = new BrikPackage(Path.Combine(Constants.CurrentWorkingDirectory, "root.dat"), 66); List entries = bpkg.ListEntries(); foreach (string entry in entries) { - Console.WriteLine(entry); + Console.WriteLine($"[File] > entry"); } var window = new PhotinoWindow() .SetTitle("Brik Installer") @@ -122,7 +122,7 @@ class Program{ case "installer::install": if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) { try { - await GenericFilesService.SyncFilesAsync($"{Constants.URLs.basePoint}/{softName}/{Constants.os}-{Constants.arch}/download/", $"{Constants.URLs.basePoint}/{softName}/{Constants.os}-{Constants.arch}/manifest", softInstallPath.ToString()); + await GenericFilesService.SyncFilesAsync(Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), softInstallPath.ToString()); responsePayload = new { success = true }; } catch (Exception) { responsePayload = new { success = false }; @@ -147,6 +147,17 @@ class Program{ } } break; + case "brik::metadata": + try { + HttpMethod httpMethod = HttpMethod.Get; + var response = await HttpHelper.FetchAsync(Constants.URLs.Endpoints.Metadata(), httpMethod); + string content = await response.Content.ReadAsStringAsync(); + Console.WriteLine(content); + responsePayload = new { success = true, content = content.ToString() }; + } catch (Exception) { + responsePayload = new { success = false }; + } + break; } var finalResponse = new { requestId, payload = responsePayload }; @@ -159,7 +170,7 @@ class Program{ } public static void LoadPage(PhotinoWindow window, string url) { - if (Constants.env == "PROD") { + if (Constants.Env == "PROD") { window.Load($"http://internal/{url}"); } else { window.Load($"src/resources/renderer/{url}"); diff --git a/src/main/services/Requirements.cs b/src/main/services/Requirements.cs index 62642e5..cd3a48b 100644 --- a/src/main/services/Requirements.cs +++ b/src/main/services/Requirements.cs @@ -10,7 +10,7 @@ namespace BrikInstaller.Services; public static class RequirementsService { public static async Task CheckRequirementsAsync(PhotinoWindow window, string softName) { try { - string requirementsUrl = $"https://brik.azures.fr/products/{softName}/{Constants.os}-{Constants.arch}/requirements"; + string requirementsUrl = $"https://brik.azures.fr/products/{softName}/{Constants.Os}-{Constants.Arch}/requirements"; var response = await HttpHelper.FetchAsync(requirementsUrl, HttpMethod.Get); diff --git a/src/resources/renderer/assets/css/index.css b/src/resources/renderer/assets/css/index.css index 8b01fe0..9b541ba 100644 --- a/src/resources/renderer/assets/css/index.css +++ b/src/resources/renderer/assets/css/index.css @@ -15,7 +15,7 @@ details.language { margin-top: 10px; } -aside > article.frame > section.author { +aside > article.frame > section.source { display: inline-flex; align-items: center; position: fixed; @@ -23,14 +23,14 @@ aside > article.frame > section.author { left: 10px; } -aside > article.frame > section.author > img { +aside > article.frame > section.source > img { width: 25px; height: 25px; margin-right: 5px; border-radius: 5px; } -aside > article.frame > section.author > p { +aside > article.frame > section.source > p { font-size: 12px; } diff --git a/src/resources/renderer/assets/js/index.js b/src/resources/renderer/assets/js/index.js index 6d907b3..7f9b890 100644 --- a/src/resources/renderer/assets/js/index.js +++ b/src/resources/renderer/assets/js/index.js @@ -198,7 +198,33 @@ async function quit() { await system.call("installer::quit", finishState) } -onFrameShowed("onboarding", () => { +function setSourceLogo(url) { + const sourceSection = document.querySelector("section.source") + const sourceLogo = sourceSection.querySelector("img") + sourceLogo.src = url +} + +function setSourceName(name) { + const sourceSection = document.querySelector("section.source") + const sourceName = sourceSection.querySelector("p") + sourceName.innerText = name +} + +async function setupMetadata() { + const metadata = await system.call("brik::metadata") + if (metadata.success) { + try { + const parsed = JSON.parse(metadata.content) + setSourceName(parsed.name) + setSourceLogo(parsed.logo) + } catch (error) { + console.error(error) + } + } +} + +onFrameShowed("onboarding", async () => { + await setupMetadata() const languageDropdown = document.querySelector("details.language") if (languageDropdown.getAttribute("value") == null) { hideFrameNavigationButtons() diff --git a/src/resources/renderer/index.html b/src/resources/renderer/index.html index 57ba554..67e26dc 100644 --- a/src/resources/renderer/index.html +++ b/src/resources/renderer/index.html @@ -142,7 +142,7 @@ -
+

azures04