Skip to content

Commit c3bfd3e

Browse files
committed
up A3.2024.12.16
修复ToDo组件问题 修复浏览器支持问题 修复删除控件偶发的问题
1 parent 342bfe1 commit c3bfd3e

File tree

45 files changed

+421
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+421
-179
lines changed

src/ColorDesktop.Launcher/Manager/InstanceManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ private static void StopInstance(InstanceWindowObj instance)
225225
{
226226
LauncherHook.InstanceDisable(instance.InstanceData.Plugin, instance.InstanceData.UUID);
227227

228+
RunInstances.Remove(instance.InstanceData.UUID);
229+
228230
instance.Instance.Stop(instance.Window);
229231
instance.Window.Close();
230232

231-
RunInstances.Remove(instance.InstanceData.UUID);
232-
233233
LangSel.Remove();
234234
}
235235
catch (Exception e)

src/ColorDesktop.Launcher/Manager/PluginManager.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public static bool CheckOs(List<string> config)
219219
return true;
220220
}
221221

222+
return config.Contains(GenOs());
223+
}
224+
225+
private static string GenOs()
226+
{
222227
string system;
223228
if (SystemInfo.Os == OsType.Linux)
224229
{
@@ -242,7 +247,7 @@ public static bool CheckOs(List<string> config)
242247
system += "x86_64";
243248
}
244249

245-
return config.Contains(system);
250+
return system;
246251
}
247252

248253
/// <summary>

src/ColorDesktop.Launcher/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ColorDesktop.Launcher;
1414

1515
public class Program
1616
{
17-
public const string Version = "A3.20241214";
17+
public const string Version = "A3.20241216";
1818
public const string ApiVersion = LauncherApi.ApiVersion;
1919

2020
private static FileStream s_lock;

src/Core/ColorDesktop.Web/CefBrowserInstance.cs

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace ColorDesktop.Web;
1313
public class CefBrowserInstance(InstanceDataObj obj) : IInstance
1414
{
1515
private AvaloniaCefBrowser _browser;
16+
private IInstanceWindow _window;
1617

1718
private bool _ok = false;
1819
private bool _reload = false;
@@ -36,11 +37,20 @@ private void Browser_LoadEnd(object sender, LoadEndEventArgs e)
3637
_ok = true;
3738
if (_reload)
3839
{
39-
_reload = false;
40+
_browser.RegisterJavascriptObject(new JsHandel(_browser, _window), "colordesktop_window");
4041
_browser.ExecuteJavaScript($"colordesktop.start()");
42+
_reload = false;
4143
}
4244
}
4345

46+
private void Reload()
47+
{
48+
_ok = false;
49+
_reload = true;
50+
_browser.UnregisterJavascriptObject("colordesktop_window");
51+
_browser.Reload();
52+
}
53+
4454
public IInstanceHandel? GetHandel()
4555
{
4656
var res = _browser.EvaluateJavaScript<bool>($"colordesktop.haveHandel()").Result;
@@ -53,7 +63,7 @@ private void Browser_LoadEnd(object sender, LoadEndEventArgs e)
5363

5464
public void RenderTick(IInstanceWindow window)
5565
{
56-
if (!_ok)
66+
if (!_ok || _reload)
5767
{
5868
return;
5969
}
@@ -140,9 +150,7 @@ protected override bool OnKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, nin
140150
}
141151
else if (keyEvent.WindowsKeyCode == 116)
142152
{
143-
avalonia._ok = false;
144-
avalonia._reload = true;
145-
avalonia._browser.Reload();
153+
avalonia.Reload();
146154
return true;
147155
}
148156
return false;

src/Core/ColorDesktop.Web/ColorDesktop.Web.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<BaseOutputPath>..\..\build_out\Debug\net8.0\WebPlugin</BaseOutputPath>
8+
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
89
<RuntimeIdentifiers>osx-x64;osx-arm64;win-x64;win-arm64;linux-x64;linux-arm64</RuntimeIdentifiers>
910
<OutputType>Library</OutputType>
1011
</PropertyGroup>

src/Core/ColorDesktop.Web/HttpWeb.cs

+59-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Concurrent;
22
using System.Net;
33
using System.Net.Sockets;
4+
using ColorDesktop.Api;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.AspNetCore.Http;
@@ -11,9 +12,10 @@
1112

1213
namespace ColorDesktop.Web;
1314

14-
public static class HttpWeb
15+
internal static class HttpWeb
1516
{
16-
private static readonly ConcurrentDictionary<string, StaticFileOptions> s_dynamicFileOptions = [];
17+
private static readonly ConcurrentDictionary<string, StaticFileOptions> s_file = [];
18+
private static readonly ConcurrentDictionary<string, IHttpRoute> s_routes = [];
1719
private static readonly FileExtensionContentTypeProvider s_typeProvider = new();
1820

1921
private static WebApplication s_app;
@@ -36,16 +38,11 @@ public static void Start()
3638

3739
var app = builder.Build();
3840

39-
//if (env.IsDevelopment())
40-
//{
41-
// app.UseDeveloperExceptionPage();
42-
//}
43-
4441
app.Use(async (context, next) =>
4542
{
4643
string path = context.Request.Path.Value!.Trim('/');
4744
string file;
48-
if (context.Request.Cookies.TryGetValue("colordesktop", out var uuid))
45+
if (context.Request.Cookies.TryGetValue("colordesktop", out var uuid) && path != uuid)
4946
{
5047
file = path;
5148
}
@@ -58,15 +55,24 @@ public static void Start()
5855
file = "index.html";
5956
}
6057
}
58+
if (uuid == null || !InstanceManager.Instances.TryGetValue(uuid, out var key))
59+
{
60+
context.Response.StatusCode = 301;
61+
await context.Response.WriteAsJsonAsync(new { msg = "uuid error" });
62+
return;
63+
}
6164

62-
if (context.Request.Method == "POST")
65+
if (s_routes.TryGetValue(key.Plugin, out var route))
6366
{
64-
if (uuid == null)
67+
context.Response.Cookies.Append("colordesktop", uuid);
68+
var res = await route.Process(context);
69+
if (res)
6570
{
66-
context.Response.StatusCode = 301;
67-
await context.Response.WriteAsJsonAsync(new { msg = "uuid error" });
6871
return;
6972
}
73+
}
74+
if (context.Request.Method == "POST")
75+
{
7076
if (file == "getConfig")
7177
{
7278
if (!context.Request.Form.TryGetValue("file", out var file1))
@@ -79,6 +85,7 @@ public static void Start()
7985

8086
context.Response.Cookies.Append("colordesktop", uuid);
8187
context.Response.ContentType = "application/json";
88+
context.Response.StatusCode = 200;
8289

8390
if (File.Exists(file2))
8491
{
@@ -118,29 +125,27 @@ public static void Start()
118125
await context.Response.WriteAsJsonAsync(new { msg = "ok" });
119126
}
120127
}
121-
else if(InstanceManager.Instances.TryGetValue(uuid, out var key))
128+
else if (s_file.TryGetValue(key.Plugin, out var options))
122129
{
123-
if (s_dynamicFileOptions.TryGetValue(key.Plugin, out var options))
124-
{
125-
var fileProvider = options.FileProvider!;
130+
var fileProvider = options.FileProvider!;
126131

127-
var fileInfo = fileProvider.GetFileInfo(file);
132+
var fileInfo = fileProvider.GetFileInfo(file);
128133

129-
if (fileInfo.Exists)
134+
if (fileInfo.Exists)
135+
{
136+
if (!s_typeProvider.TryGetContentType(fileInfo.Name, out var contentType))
130137
{
131-
if (!s_typeProvider.TryGetContentType(fileInfo.Name, out var contentType))
132-
{
133-
contentType = "application/octet-stream";
134-
}
135-
136-
context.Response.Cookies.Append("colordesktop", uuid);
137-
context.Response.ContentType = contentType;
138-
using var stream = fileInfo.CreateReadStream();
139-
await stream.CopyToAsync(context.Response.Body);
140-
return;
138+
contentType = "application/octet-stream";
141139
}
140+
141+
context.Response.Cookies.Append("colordesktop", uuid);
142+
context.Response.ContentType = contentType;
143+
using var stream = fileInfo.CreateReadStream();
144+
await stream.CopyToAsync(context.Response.Body);
145+
return;
142146
}
143147
}
148+
144149
await next();
145150
});
146151

@@ -160,7 +165,27 @@ public static void AddPlugin(string id, string dir)
160165
FileProvider = fileProvider,
161166
RequestPath = "/" + folderName
162167
};
163-
s_dynamicFileOptions.TryAdd(id, staticFileOptions);
168+
s_file.TryAdd(id, staticFileOptions);
169+
}
170+
171+
public static void AddRoute(IPlugin plugin, IHttpRoute route)
172+
{
173+
var id = LauncherApi.Hook.GetPluginId(plugin);
174+
if (id == null)
175+
{
176+
return;
177+
}
178+
s_routes[id] = route;
179+
}
180+
181+
public static void RemoveRoute(IPlugin plugin)
182+
{
183+
var id = LauncherApi.Hook.GetPluginId(plugin);
184+
if (id == null)
185+
{
186+
return;
187+
}
188+
s_routes.Remove(id, out _);
164189
}
165190

166191
private static int GetAvailablePort()
@@ -176,4 +201,9 @@ public static void Stop()
176201
{
177202
s_app.StopAsync();
178203
}
204+
205+
public static void Clear()
206+
{
207+
s_file.Clear();
208+
}
179209
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Http;
7+
8+
namespace ColorDesktop.Web;
9+
10+
public interface IHttpRoute
11+
{
12+
/// <summary>
13+
/// 处理网络路由
14+
/// </summary>
15+
/// <param name="context">这次请求</param>
16+
/// <returns>true表示处理成功</returns>
17+
Task<bool> Process(HttpContext context);
18+
}

0 commit comments

Comments
 (0)