generated from azures04/Photino-Boilerplate
Compare commits
No commits in common. "e9958306d1e55f6fbf1e3305d63cebc835bdf5d0" and "f1511f1d3d4f9e9a423f8631b9be7ead34a01072" have entirely different histories.
e9958306d1
...
f1511f1d3d
@ -4,22 +4,15 @@ using BrikInstaller.Utils;
|
|||||||
|
|
||||||
namespace BrikInstaller;
|
namespace BrikInstaller;
|
||||||
|
|
||||||
public class Constants {
|
public static class Constants {
|
||||||
public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||||
|
|
||||||
public static readonly string Os = OsHelper.getOperatingSystem();
|
public static readonly string Os = OsHelper.getOperatingSystem();
|
||||||
public static readonly string Arch = OsHelper.getArchitecture();
|
public static readonly string Arch = OsHelper.getArchitecture();
|
||||||
|
|
||||||
public static readonly string Env = "DEV";
|
public static readonly string Env = "DEV";
|
||||||
|
|
||||||
public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
public static readonly string CurrentWorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
public static readonly string CurrentWorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||||
|
|
||||||
public static class ProductMetadata {
|
|
||||||
public static string Name = "";
|
|
||||||
public static string InstallPath = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class URLs {
|
public static class URLs {
|
||||||
public static readonly string ApiPoint = "https://brik.azures.fr";
|
public static readonly string ApiPoint = "https://brik.azures.fr";
|
||||||
public static class Endpoints {
|
public static class Endpoints {
|
||||||
@ -31,9 +24,6 @@ public class Constants {
|
|||||||
|
|
||||||
public static string Metadata()
|
public static string Metadata()
|
||||||
=> $"{ApiPoint}/metadata";
|
=> $"{ApiPoint}/metadata";
|
||||||
|
|
||||||
public static string Configuration(string softName, string os, string arch)
|
|
||||||
=> $"{ApiPoint}/products/{softName}/{os}-{arch}/configuration";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4,9 +4,6 @@ using System.Text.Json;
|
|||||||
using BrikInstaller.Utils;
|
using BrikInstaller.Utils;
|
||||||
using BrikInstaller.Schemas;
|
using BrikInstaller.Schemas;
|
||||||
using BrikInstaller.Services;
|
using BrikInstaller.Services;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Reflection.Metadata;
|
|
||||||
|
|
||||||
namespace BrikInstaller;
|
namespace BrikInstaller;
|
||||||
|
|
||||||
@ -27,8 +24,6 @@ class Program{
|
|||||||
.SetUseOsDefaultLocation(false)
|
.SetUseOsDefaultLocation(false)
|
||||||
.SetUseOsDefaultSize(false)
|
.SetUseOsDefaultSize(false)
|
||||||
.SetChromeless(true)
|
.SetChromeless(true)
|
||||||
.SetDevToolsEnabled(false)
|
|
||||||
.SetContextMenuEnabled(false)
|
|
||||||
.RegisterCustomSchemeHandler("http", (object sender, string scheme, string url, out string contentType) =>{
|
.RegisterCustomSchemeHandler("http", (object sender, string scheme, string url, out string contentType) =>{
|
||||||
Uri uri = new Uri(url);
|
Uri uri = new Uri(url);
|
||||||
switch (uri.Host){
|
switch (uri.Host){
|
||||||
@ -63,7 +58,7 @@ class Program{
|
|||||||
string requestId = json.RootElement.GetProperty("requestId").GetString()!;
|
string requestId = json.RootElement.GetProperty("requestId").GetString()!;
|
||||||
string method = json.RootElement.GetProperty("functionName").GetString()!;
|
string method = json.RootElement.GetProperty("functionName").GetString()!;
|
||||||
var jsonPayload = json.RootElement.GetProperty("payload");
|
var jsonPayload = json.RootElement.GetProperty("payload");
|
||||||
|
|
||||||
object? responsePayload = null;
|
object? responsePayload = null;
|
||||||
var pw = (PhotinoWindow)sender!;
|
var pw = (PhotinoWindow)sender!;
|
||||||
|
|
||||||
@ -127,28 +122,24 @@ class Program{
|
|||||||
case "installer::install":
|
case "installer::install":
|
||||||
if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) {
|
if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) {
|
||||||
try {
|
try {
|
||||||
Constants.ProductMetadata.Name = softName.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());
|
||||||
Constants.ProductMetadata.InstallPath = softInstallPath.ToString();
|
|
||||||
await GenericFilesService.SyncFilesAsync(Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), Constants.URLs.Endpoints.Manifest(softName.ToString(), Constants.Os, Constants.Arch), softInstallPath.ToString());
|
|
||||||
responsePayload = new { success = true };
|
responsePayload = new { success = true };
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
responsePayload = new { success = false };
|
responsePayload = new { success = false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "installer::finalize":
|
case "installer::quit":
|
||||||
if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) {
|
if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) {
|
||||||
try {
|
try {
|
||||||
HttpMethod httpMethod = HttpMethod.Get;
|
|
||||||
var response = await HttpHelper.FetchAsync(Constants.URLs.Endpoints.Configuration(Constants.ProductMetadata.Name, Constants.Os, Constants.Arch), httpMethod);
|
|
||||||
var productConfig = await response.Content.ReadFromJsonAsync<ProductConfig>(Constants._jsonOptions);
|
|
||||||
Console.WriteLine(productConfig!.Executable);
|
|
||||||
InstallationFinish installationFinish = jsonPayload.Deserialize<InstallationFinish>(Constants._jsonOptions)!;
|
InstallationFinish installationFinish = jsonPayload.Deserialize<InstallationFinish>(Constants._jsonOptions)!;
|
||||||
if (installationFinish.CreateShortcut) {
|
if (installationFinish.CreateShortcut) {
|
||||||
ShortcutService.CreateShortcut(Constants.ProductMetadata.Name, Path.Combine(Constants.ProductMetadata.InstallPath, productConfig.Executable!));
|
//TO-DO : Fetch executable path from remote
|
||||||
|
// Create a shortcut with it
|
||||||
}
|
}
|
||||||
if (installationFinish.LaunchAfterExit) {
|
if (installationFinish.LaunchAfterExit) {
|
||||||
InstallationService.LaunchApplication(Path.Combine(Constants.ProductMetadata.InstallPath, productConfig.Executable!));
|
//TO-DO : Fetch executable path from remote
|
||||||
|
// Launch it
|
||||||
}
|
}
|
||||||
responsePayload = new { success = true };
|
responsePayload = new { success = true };
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
@ -156,9 +147,6 @@ class Program{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "installer::kill":
|
|
||||||
window.Close();
|
|
||||||
break;
|
|
||||||
case "brik::metadata":
|
case "brik::metadata":
|
||||||
try {
|
try {
|
||||||
HttpMethod httpMethod = HttpMethod.Get;
|
HttpMethod httpMethod = HttpMethod.Get;
|
||||||
|
|||||||
@ -7,8 +7,4 @@ public class ProductRequirement {
|
|||||||
public string? ExpectedOutputPattern { get; set; }
|
public string? ExpectedOutputPattern { get; set; }
|
||||||
public string? InstallationMode { get; set; }
|
public string? InstallationMode { get; set; }
|
||||||
public string? InstallationUrl { get; set; }
|
public string? InstallationUrl { get; set; }
|
||||||
}
|
|
||||||
|
|
||||||
public class ProductConfig {
|
|
||||||
public string? Executable { get; set; }
|
|
||||||
}
|
}
|
||||||
@ -8,7 +8,6 @@ public static class GenericFilesService {
|
|||||||
private static readonly HttpClient _httpClient = new();
|
private static readonly HttpClient _httpClient = new();
|
||||||
|
|
||||||
public static async Task SyncFilesAsync(string rootEndpoint, string apiUrl, string destinationDir) {
|
public static async Task SyncFilesAsync(string rootEndpoint, string apiUrl, string destinationDir) {
|
||||||
Console.WriteLine(rootEndpoint);
|
|
||||||
try {
|
try {
|
||||||
var index = await _httpClient.GetFromJsonAsync<BrikFilesIndex>(apiUrl);
|
var index = await _httpClient.GetFromJsonAsync<BrikFilesIndex>(apiUrl);
|
||||||
if (index?.Root == null) return;
|
if (index?.Root == null) return;
|
||||||
|
|||||||
@ -75,47 +75,32 @@ public static class InstallationService {
|
|||||||
return final;
|
return final;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LaunchApplication(string executablePath) {
|
|
||||||
try {
|
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
|
||||||
startInfo.FileName = executablePath;
|
|
||||||
startInfo.UseShellExecute = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
BashUtils.GetCommandOutput($"chmod +x \"{executablePath}\"");
|
|
||||||
|
|
||||||
startInfo.FileName = executablePath;
|
|
||||||
startInfo.UseShellExecute = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
startInfo.WorkingDirectory = Path.GetDirectoryName(executablePath);
|
|
||||||
|
|
||||||
Process.Start(startInfo);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Console.WriteLine($"[Launch Error] Unable to start : {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ShortcutService {
|
public static class ShortcutService {
|
||||||
public static void CreateShortcut(string appName, string targetExePath) {
|
public static void CreateShortcut(string appName, string targetExePath, bool createDesktop, bool autoStart) {
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||||
CreateWindowsShortcut(appName, targetExePath);
|
CreateWindowsShortcut(appName, targetExePath);
|
||||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
|
|
||||||
CreateLinuxShortcut(appName, targetExePath);
|
|
||||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
|
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
|
||||||
CreateMacShortcut(appName, targetExePath);
|
CreateMacShortcut(appName, targetExePath);
|
||||||
|
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
|
||||||
|
CreateLinuxShortcut(appName, targetExePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CreateMacShortcut(string appName, string targetExePath) {
|
||||||
|
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
||||||
|
string shortcutPath = Path.Combine(desktopPath, appName);
|
||||||
|
|
||||||
|
BashUtils.GetCommandOutput($"ln -sf \"{targetExePath}\" \"{shortcutPath}\"");
|
||||||
|
}
|
||||||
|
|
||||||
private static void CreateWindowsShortcut(string appName, string targetExePath) {
|
private static void CreateWindowsShortcut(string appName, string targetExePath) {
|
||||||
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||||
string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk");
|
string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk");
|
||||||
string cmd = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()";
|
|
||||||
BashUtils.GetCommandOutput($"powershell -Command \"{cmd}\"");
|
string script = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()";
|
||||||
|
Process.Start(new ProcessStartInfo("powershell", $"-Command \"{script}\"") { CreateNoWindow = true });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateLinuxShortcut(string appName, string targetExePath) {
|
private static void CreateLinuxShortcut(string appName, string targetExePath) {
|
||||||
@ -126,16 +111,8 @@ Name={appName}
|
|||||||
Exec=""{targetExePath}""
|
Exec=""{targetExePath}""
|
||||||
Terminal=false
|
Terminal=false
|
||||||
";
|
";
|
||||||
|
|
||||||
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
||||||
string filePath = Path.Combine(desktopPath, $"{appName}.desktop");
|
File.WriteAllText(Path.Combine(desktopPath, $"{appName}.desktop"), desktopEntry);
|
||||||
File.WriteAllText(filePath, desktopEntry);
|
Process.Start("chmod", $"+x \"{Path.Combine(desktopPath, $"{appName}.desktop")}\"");
|
||||||
BashUtils.GetCommandOutput($"chmod +x \"{filePath}\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateMacShortcut(string appName, string targetExePath) {
|
|
||||||
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
|
||||||
string shortcutPath = Path.Combine(desktopPath, appName);
|
|
||||||
BashUtils.GetCommandOutput($"ln -sf \"{targetExePath}\" \"{shortcutPath}\"");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14,7 +14,6 @@ main {
|
|||||||
right: 0px;
|
right: 0px;
|
||||||
bottom: 0px;
|
bottom: 0px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: #212121;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aside {
|
aside {
|
||||||
@ -23,7 +22,6 @@ aside {
|
|||||||
}
|
}
|
||||||
|
|
||||||
aside > article.frame {
|
aside > article.frame {
|
||||||
position: fixed;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
|
|||||||
@ -194,12 +194,8 @@ async function quit() {
|
|||||||
createShortcut: createShortcut["checked"],
|
createShortcut: createShortcut["checked"],
|
||||||
launchAfterExit: launchAfterExit["checked"]
|
launchAfterExit: launchAfterExit["checked"]
|
||||||
}
|
}
|
||||||
const finalized = await system.call("installer::finalize", finishState)
|
console.log(finishState)
|
||||||
if (!finalized.success) {
|
await system.call("installer::quit", finishState)
|
||||||
alert("Erreur")
|
|
||||||
await sleep(1000)
|
|
||||||
}
|
|
||||||
await system.call("installer::kill")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSourceLogo(url) {
|
function setSourceLogo(url) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user