Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Merge branch 'daily' into stable
Browse files Browse the repository at this point in the history
Signed-off-by: MATRIX-feather <[email protected]>
  • Loading branch information
MATRIX-feather committed Mar 17, 2023
2 parents 09afbcb + 664314f commit 599aacc
Show file tree
Hide file tree
Showing 259 changed files with 5,419 additions and 1,680 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<EmbeddedResource Include="Resources\**\*.*" />
</ItemGroup>
<ItemGroup Label="Code Analysis">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" />
</ItemGroup>
<PropertyGroup Label="Code Analysis">
Expand Down
74 changes: 44 additions & 30 deletions M.DBus/DBusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void Dispose()
{
//Disconnect();

currentConnection.Dispose();

isDisposed = true;
GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -171,25 +173,20 @@ public async Task RegisterNewObject(IDBusObject dbusObject, string targetName =
if (string.IsNullOrEmpty(targetName))
targetName = dbusObject.ObjectPath.ToServiceName();

//添加物件与其目标名称添加到词典
registerDictionary[dbusObject] = targetName;
lock (registerDictionary)
{
//添加物件与其目标名称添加到词典
registerDictionary[dbusObject] = targetName;
}

if (connectionState == ConnectionState.Connected)
await registerToConection(dbusObject).ConfigureAwait(false);
}

public async Task RegisterNewObjects(IDBusObject[] objects)
{
//添加物件到列表
foreach (var obj in objects)
registerDictionary[obj] = obj.ObjectPath.ToServiceName();

if (connectionState == ConnectionState.Connected)
{
//注册物件和DBus服务
foreach (var dBusObject in registerDictionary.Keys)
await registerToConection(dBusObject).ConfigureAwait(false);
}
foreach (var dBusObject in objects)
await RegisterNewObject(dBusObject).ConfigureAwait(false);
}

//bug: 注册的服务/物件在错误的dbus-send后会直接Name Lost,无法恢复
Expand All @@ -199,26 +196,34 @@ private async Task registerObjects()

//递归注册DBus服务
foreach (var dBusObject in registerDictionary.Keys)
await registerToConection(dBusObject).ConfigureAwait(false);
await RegisterNewObject(dBusObject).ConfigureAwait(false);
}

private readonly List<string> registeredServices = new List<string>();

private async Task registerToConection(IDBusObject dBusObject)
{
string targetName = registerDictionary[dBusObject];
await currentConnection.RegisterObjectAsync(dBusObject).ConfigureAwait(false);

await currentConnection.RegisterObjectAsync(dBusObject).ConfigureAwait(false);
await currentConnection.RegisterServiceAsync(targetName).ConfigureAwait(false);

if (!registeredServices.Contains(targetName))
bool alreadyRegistered = false;

lock (registeredServices)
{
alreadyRegistered = registeredServices.Contains(targetName);

if (!alreadyRegistered)
registeredServices.Add(targetName);
}

if (!alreadyRegistered)
{
await currentConnection.ResolveServiceOwnerAsync(
targetName,
onServiceNameChanged,
e => onServiceError(e, dBusObject)).ConfigureAwait(false);

registeredServices.Add(targetName);
}

Logger.Log($"为{dBusObject.ObjectPath}注册{targetName}");
Expand All @@ -230,25 +235,32 @@ await currentConnection.ResolveServiceOwnerAsync(

public void RemoveObject(IDBusObject dBusObject)
{
var target = registerDictionary.FirstOrDefault(o => o.Key.ObjectPath.Equals(dBusObject.ObjectPath)).Key;

if (target != null)
try
{
Logger.Log($"反注册{dBusObject.ObjectPath}");
Task.Run(() =>
var target = registerDictionary.FirstOrDefault(o => o.Key.ObjectPath.Equals(dBusObject.ObjectPath)).Key;

if (target != null)
{
unRegisterFromConnection(target).ConfigureAwait(false);
registerDictionary.Remove(target);
});
Logger.Log($"反注册{dBusObject.ObjectPath}");

string serviceName = registerDictionary[target];

lock (registerDictionary)
registerDictionary.Remove(target);

Task.Run(() => unRegisterFromConnection(target, serviceName).ConfigureAwait(false));
}
}
catch (Exception e)
{
Logger.Error(e, $"移除DBus对象时遇到异常");
}
else
throw new InvalidOperationException($"尝试反注册一个不存在的DBus物件: {dBusObject.ObjectPath}");
}

private async Task unRegisterFromConnection(IDBusObject dBusObject)
private async Task unRegisterFromConnection(IDBusObject dBusObject, string serviceName)
{
currentConnection.UnregisterObject(dBusObject);
await currentConnection.UnregisterServiceAsync(registerDictionary[dBusObject]).ConfigureAwait(false);
await currentConnection.UnregisterServiceAsync(serviceName).ConfigureAwait(false);
}

#endregion
Expand Down Expand Up @@ -302,9 +314,11 @@ private async Task connectTask(string target)
//设置连接状态
connectionState = ConnectionState.Connected;

//注册对象
await registerObjects().ConfigureAwait(false);

OnConnected?.Invoke();
GreetService.SwitchState(true, "");
GreetService.SwitchState(true, "Initial connect");
break;

//case ConnectionState.Connected:
Expand Down
5 changes: 3 additions & 2 deletions M.DBus/IDBusManagerContainer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using M.DBus.Services.Notifications;
using M.DBus.Tray;
using Tmds.DBus;
Expand All @@ -9,8 +10,8 @@ public interface IDBusManagerContainer<T>
{
void Add(T obj);
void Remove(T obj);
void AddRange(T[] objects);
void RemoveRange(T[] objects);
void AddRange(IEnumerable<T> objects);
void RemoveRange(IEnumerable<T> objects);
void PostSystemNotification(SystemNotification notification);
void AddTrayEntry(SimpleEntry entry);
void RemoveTrayEntry(SimpleEntry entry);
Expand Down
3 changes: 1 addition & 2 deletions M.DBus/ServiceUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public static Dictionary<string, object> GetMembers(object target)
{
var dictionary = new Dictionary<string, object>();

foreach (var memberInfo in target.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public |
BindingFlags.GetProperty | BindingFlags.SetProperty))
foreach (var memberInfo in target.GetType().GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty))
dictionary[memberInfo.Name] = memberInfo;

return dictionary;
Expand Down
2 changes: 1 addition & 1 deletion M.DBus/Tray/SeparatorEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class SeparatorEntry : SimpleEntry
{
public SeparatorEntry()
{
Type = EntryType.SSeparator;
Type = EntryType.Separator;
}
}
}
15 changes: 11 additions & 4 deletions M.DBus/Tray/SimpleEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ namespace M.DBus.Tray
/// </summary>
public class SimpleEntry
{
public int ChildId { get; internal set; } = -2;
public SimpleEntry()
{
this.ChildId = ChildId == -1 ? Cid++ : ChildId;
}

public static int Cid = 1;

public int ChildId { get; protected set; } = -1;

public Action OnPropertyChanged;

Expand All @@ -35,7 +42,7 @@ public string Type
}
}

private string type = EntryType.SStandard;
private string type = EntryType.Standard;

/// <summary>
/// 该项目的文本,但是:<br/>
Expand Down Expand Up @@ -192,7 +199,7 @@ public string ToggleType
}
}

private string toggleType = Utils.Canonical.DBusMenuFlags.ToggleType.SIndependentToggleable;
private string toggleType = Utils.Canonical.DBusMenuFlags.ToggleType.IndependentToggleable;

/// <summary>
/// 描述“可切换”项目的当前状态。 可以是以下之一:<br/>
Expand Down Expand Up @@ -235,7 +242,7 @@ public string ChildrenDisplay
}
}

private string childrenDisplay = ChildrenDisplayType.SNone;
private string childrenDisplay = ChildrenDisplayType.None;

/// <summary>
/// 该项目被激活时要执行的动作
Expand Down
14 changes: 8 additions & 6 deletions M.DBus/Tray/TrayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static (int, IDictionary<string, object>, object[]) ToDbusObject(

additionalEntries = new Dictionary<int, SimpleEntry>();

if (entry.ChildrenDisplay == ChildrenDisplayType.SSubmenu)
if (entry.ChildrenDisplay == ChildrenDisplayType.Submenu)
{
try
{
Expand All @@ -74,24 +74,24 @@ public static (int, IDictionary<string, object>, object[]) ToDbusObject(
IDictionary<int, SimpleEntry> additDict;

//如果subEntry没有被指定ChildID
if (subEntry.ChildId == -2)
if (subEntry.ChildId == -1)
{
//最大id+1
maxOrder++;

//设置subEntry的ChildID
subEntry.ChildId = maxOrder;
//subEntry.ChildId = SimpleEntry.Cid++;

//加入要返回的词典中
additionalEntries[subEntry.ChildId] = subEntry;
additionalEntries[(int)subEntry.ChildId] = subEntry;

//记录
//Logger.Log($"{subEntry} 获取了新的ChildId: {subEntry.ChildId}");
}

//添加目录
//不需要处理additonalOrders,因为已经有additDict可以用作计数了
subMenus.Add(subEntry.ToDbusObject(subEntry.ChildId, maxOrder, out additDict));
subMenus.Add(subEntry.ToDbusObject((int)subEntry.ChildId, maxOrder, out additDict));

//将循环调用返回的 额外词典 加进要返回的 词典 中

Expand All @@ -116,6 +116,8 @@ public static (int, IDictionary<string, object>, object[]) ToDbusObject(

public static (int, IDictionary<string, object>) ToDbusObject(this SimpleEntry entry)
{
int childId = entry.ChildId;

var result = new Dictionary<string, object>
{
["type"] = entry.Type,
Expand All @@ -130,7 +132,7 @@ public static (int, IDictionary<string, object>) ToDbusObject(this SimpleEntry e
["children-display"] = entry.ChildrenDisplay,
};

return (entry.ChildId, result);
return (childId, result);
}
}
}
10 changes: 3 additions & 7 deletions M.DBus/Utils/Canonical/DBusMenuFlags/ActionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ namespace M.DBus.Utils.Canonical.DBusMenuFlags
{
public class ToggleType
{
public static string SIndependentToggleable => "checkmark";
public static string SRadio => "radio";
public static string SNone => string.Empty;

public string IndependentToggleable => SIndependentToggleable;
public string Radio => SRadio;
public string None => SNone;
public static string IndependentToggleable => "checkmark";
public static string Radio => "radio";
public static string None => string.Empty;
}
}
7 changes: 2 additions & 5 deletions M.DBus/Utils/Canonical/DBusMenuFlags/ChildrenDisplayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ namespace M.DBus.Utils.Canonical.DBusMenuFlags
{
public class ChildrenDisplayType
{
public static string SSubmenu => "submenu";
public static string SNone => "";

public string Submenu => SSubmenu;
public string None => SNone;
public static string Submenu => "submenu";
public static string None => "";
}
}
7 changes: 2 additions & 5 deletions M.DBus/Utils/Canonical/DBusMenuFlags/EntryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ namespace M.DBus.Utils.Canonical.DBusMenuFlags
{
public class EntryType
{
public string Standard => SStandard;
public string Separator => SSeparator;

public static string SStandard => "standard";
public static string SSeparator => "separator";
public static string Standard => "standard";
public static string Separator => "separator";
}
}
2 changes: 1 addition & 1 deletion Mvis.Plugin.CloudMusicSupport/DBus/ILyricDBusObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Task<object> GetAsync(string prop)

public Task SetAsync(string prop, object val)
{
throw new InvalidOperationException("只读属性");
return Task.FromException(new InvalidOperationException("只读属性"));
}

public Task<IDisposable> WatchPropertiesAsync(Action<PropertyChanges> handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Text.Encodings.Web" Version="6.0.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="7.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Mvis.Plugin.CollectionSupport/CollectionHepler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public CollectionHelper()
private readonly SimpleEntry trayEntry = new SimpleEntry
{
Label = "收藏夹(未选择任何收藏夹)",
ChildrenDisplay = ChildrenDisplayType.SSubmenu
ChildrenDisplay = ChildrenDisplayType.Submenu
};

[BackgroundDependencyLoader]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Game.Rulesets.EmptyFreeform\osu.Game.Rulesets.EmptyFreeform.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Game.Rulesets.Pippidon\osu.Game.Rulesets.Pippidon.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Game.Rulesets.EmptyScrolling\osu.Game.Rulesets.EmptyScrolling.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Game.Rulesets.Pippidon\osu.Game.Rulesets.Pippidon.csproj" />
Expand Down
Loading

0 comments on commit 599aacc

Please sign in to comment.