This repository was archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
68 lines (56 loc) · 2.07 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Linq;
using ElectronNET.API;
using ElectronNET.API.Entities;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Nimbus.Interfaces;
using Nimbus.Services;
using Nimbus.Services.Encryption;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseElectron(args);
// Add services to the container.
DotNetEnv.Env.TraversePath().Load();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSingleton<ITDLibRepository, TDLibRepository>(provider =>
{
int? API_ID = int.TryParse(Environment.GetEnvironmentVariable("API_ID"), out var apiId) ? apiId : (int?)null;
string? API_HASH = Environment.GetEnvironmentVariable("API_HASH");
string? PHONE_NUMBER = Environment.GetEnvironmentVariable("PHONE_NUMBER");
return new TDLibRepository(API_ID, API_HASH, PHONE_NUMBER);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
await app.StartAsync();
// Open the Electron-Window here
await Electron.WindowManager.CreateWindowAsync();
//handle open folder dialog box using system's file explorer
await Electron.IpcMain.On("open-folder", async (args) =>
{
var window = Electron.WindowManager.BrowserWindows.First();
var folderPaths = await Electron.Dialog.ShowOpenDialogAsync(window, new OpenDialogOptions
{
Title = "Select a folder",
Properties = new OpenDialogProperty[] { OpenDialogProperty.openDirectory },
});
if (folderPaths != null && folderPaths.Length > 0)
{
var selectedFolderPath = folderPaths[0];
Electron.IpcMain.Send(window, "folder-selected", selectedFolderPath);
}
});
app.WaitForShutdown();
app.Run();