Skip to content

Commit

Permalink
修改PluginMetaData
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Aug 16, 2023
1 parent 0a9894d commit 5e300b5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
18 changes: 14 additions & 4 deletions ShadowViewer.Core/Extensions/PluginExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@

public static class PluginExtension
{
public static PluginMetaData GetPluginMetaData<T>(this T plugin) where T : IPlugin
public static PluginMetaData GetPluginMetaData<T>() where T:IPlugin
{
return plugin.GetType().GetTypeInfo().GetCustomAttribute<PluginMetaData>();
return typeof(T).GetPluginMetaData();
}
public static PluginMetaData GetPluginMetaData(this Type plugin)
{
var meta = plugin.GetTypeInfo().GetCustomAttribute<PluginMetaData>();
if (meta.Logo.StartsWith("/") && meta.Logo != "/")
if (meta == null) return null;
if (!string.IsNullOrEmpty(meta.Logo))
{
meta.Logo = meta.Logo.AssetPath(plugin);
if (meta.Logo.StartsWith("/") && meta.Logo != "/")
{
meta.Logo = meta.Logo.AssetPath(plugin);
}else if (meta.Logo.StartsWith("ms-appx:///"))
{
meta.Logo = meta.Logo.Replace("ms-appx://","").AssetPath(plugin);
}else if (meta.Logo.StartsWith("ms-appx://"))
{
meta.Logo = meta.Logo.Replace("ms-appx://","/").AssetPath(plugin);
}
}
return meta;
}
Expand Down
47 changes: 41 additions & 6 deletions ShadowViewer.Core/Plugins/PluginMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,48 @@ public class PluginMetaData : Attribute
public string WebUri { get; }

/// <summary>
/// 图标
/// 图标<br/>
/// 1.本地文件,以ms-appx://开头<br/>
/// 2.FontIcon,以font://开头<br/>
/// 3.FluentIcon,以fluent://开头
/// <example>
/// 1.ms-appx:///Assets/Icons/Logo.png<br/>
/// 2.font://\uE714<br/>
/// 3.fluent://\uE714
/// </example>
/// </summary>
public string Logo { get; set; } = "/";
public string Logo { get; set; }

/// <summary>
/// 支持的插件管理器版本,该版本即为ShadowViewer.Core的发行版
/// </summary>
public int MinVersion { get; }

public int MinVersion { get; }
/// <summary>
/// 支持的语言
/// </summary>
public string[] Lang { get; }
/// <summary>
/// 插件元数据
/// </summary>
/// <param name="id">标识符(大小写不敏感)</param>
/// <param name="name">显示的名称</param>
/// <param name="description">介绍</param>
/// <param name="author">作者</param>
/// <param name="version">版本号</param>
/// <param name="webUri">项目地址</param>
/// <param name="logo">图标<br/>
/// 1.本地文件,以ms-appx://开头<br/>
/// 2.FontIcon,以font://开头<br/>
/// 3.FluentIcon,以fluent://开头
/// <example>
/// logo: 1.ms-appx:///Assets/Icons/Logo.png<br/>
/// logo: 2.font://\uE714<br/>
/// logo: 3.fluent://\uE714
/// </example></param>
/// <param name="requireVersion">支持的插件管理器版本,该版本即为ShadowViewer.Core的发行版</param>
/// <param name="lang">支持的语言</param>
public PluginMetaData(string id, string name, string description, string author, string version, string webUri,
string logo, int requireVersion,params string[] langs)
string logo, int requireVersion,params string[] lang)
{
Id = id;
Name = name;
Expand All @@ -53,6 +84,10 @@ public PluginMetaData(string id, string name, string description, string author,
if(!string.IsNullOrEmpty(logo))
Logo = logo;
MinVersion = requireVersion;
Lang = langs;
Lang = lang ;
}

public PluginMetaData()
{
}
}

0 comments on commit 5e300b5

Please sign in to comment.