Skip to content

Commit

Permalink
Added code for the new extension store
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev committed Feb 22, 2022
1 parent c37e756 commit 7525dfa
Show file tree
Hide file tree
Showing 55 changed files with 2,191 additions and 557 deletions.
1 change: 0 additions & 1 deletion ActionButton/ActionButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ private void UpdateBindingState(Variables.Variable variable)

public event EventHandler StateChanged;
public event EventHandler IconChanged;
public long ButtonId { get; set; }

private bool _state = false;
public bool State
Expand Down
17 changes: 17 additions & 0 deletions Extension/IMacroDeckExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SuchByte.MacroDeck.ExtensionStore;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuchByte.MacroDeck.Extension
{
public interface IMacroDeckExtension
{
public ExtensionType ExtensionType { get; }
public string ExtensionTypeDisplayName { get; }
public object ExtensionObject { get; }
public bool Configurable { get; }
public void Uninstall();

}
}
27 changes: 27 additions & 0 deletions Extension/IconPackExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using SuchByte.MacroDeck.ExtensionStore;
using SuchByte.MacroDeck.Icons;
using SuchByte.MacroDeck.Language;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuchByte.MacroDeck.Extension
{
public class IconPackExtension : IMacroDeckExtension
{
public ExtensionType ExtensionType => ExtensionType.IconPack;
public string ExtensionTypeDisplayName => LanguageManager.Strings.IconPack;
public object ExtensionObject { get; set; }
public bool Configurable => false;

public IconPackExtension(IconPack iconPack)
{
this.ExtensionObject = iconPack;
}

public void Uninstall()
{

}
}
}
28 changes: 28 additions & 0 deletions Extension/PluginExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using SuchByte.MacroDeck.ExtensionStore;
using SuchByte.MacroDeck.Language;
using SuchByte.MacroDeck.Plugins;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuchByte.MacroDeck.Extension
{
public class PluginExtension : IMacroDeckExtension
{
public ExtensionType ExtensionType => ExtensionType.Plugin;
public string ExtensionTypeDisplayName => LanguageManager.Strings.Plugin;
public object ExtensionObject { get; set; }

public bool Configurable => this.ExtensionObject != null && (this.ExtensionObject as MacroDeckPlugin).CanConfigure;

public PluginExtension(MacroDeckPlugin macroDeckPlugin)
{
this.ExtensionObject = macroDeckPlugin;
}

public void Uninstall()
{

}
}
}
108 changes: 108 additions & 0 deletions ExtensionStore/ExtensionStoreHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using SuchByte.MacroDeck.GUI.Dialogs;
using SuchByte.MacroDeck.Icons;
using SuchByte.MacroDeck.Model;
using SuchByte.MacroDeck.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace SuchByte.MacroDeck.ExtensionStore
{
public class ExtensionStoreHelper
{
public static event EventHandler OnUpdateCheckFinished;

private static ExtensionStoreDownloader extensionStoreDownloader;

public static void InstallPluginById(string packageId)
{
InstallPackages(new List<ExtensionStoreDownloaderPackageInfoModel> { new ExtensionStoreDownloaderPackageInfoModel() { PackageId = packageId, ExtensionType = ExtensionType.Plugin } });
}

public static void InstallIconPackById(string packageId)
{
InstallPackages(new List<ExtensionStoreDownloaderPackageInfoModel> { new ExtensionStoreDownloaderPackageInfoModel() { PackageId = packageId, ExtensionType = ExtensionType.IconPack } });
}

public static void InstallPackages(List<ExtensionStoreDownloaderPackageInfoModel> packages)
{
extensionStoreDownloader = new ExtensionStoreDownloader(packages)
{
Owner = MacroDeck.MainWindow,
};
extensionStoreDownloader.Show();
}

public static string GetPackageId(IconPack iconPack)
{
return $"{iconPack.Author.Replace(" ", "")}.{iconPack.Name.Replace(" ", "")}";
}

public static string GetPackageId(MacroDeckPlugin macroDeckPlugin)
{
return new DirectoryInfo(PluginManager.PluginDirectories[macroDeckPlugin]).Name;
}

public static void SearchUpdatesAsync()
{
PluginManager.PluginsUpdateAvailable.Clear();
IconManager.IconPacksUpdateAvailable.Clear();
Task.Run(() =>
{
foreach (MacroDeckPlugin plugin in PluginManager.Plugins.Values)
{
PluginManager.SearchUpdate(plugin);
}
foreach (MacroDeckPlugin plugin in PluginManager.PluginsNotLoaded.Values)
{
PluginManager.SearchUpdate(plugin);
}
foreach (IconPack iconPack in IconManager.IconPacks.FindAll(iP => iP.PackageManagerManaged && !iP.Hidden))
{
IconManager.SearchUpdate(iconPack);
}

if (OnUpdateCheckFinished != null)
{
OnUpdateCheckFinished(null, EventArgs.Empty);
}
});
}

public static string InstalledIconPacksAsString
{
get
{
string installedPlugins = "";
foreach (var iconPack in IconManager.IconPacks.FindAll(x => x.PackageManagerManaged))
{
installedPlugins += $"{GetPackageId(iconPack).ToLower()}%20";
}

return installedPlugins;
}
}

public static string InstalledPluginsAsString
{
get
{
string installedPlugins = "";
foreach (var path in PluginManager.PluginDirectories.Values)
{
installedPlugins += $"{new DirectoryInfo(path).Name.ToLower()}%20";
}

return installedPlugins;
}
}
}

public enum ExtensionType
{
Plugin,
IconPack,
}
}
4 changes: 3 additions & 1 deletion GUI/Colors.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Windows.UI.ViewManagement;

namespace SuchByte.MacroDeck.GUI
{
public static class Colors
public class Colors : UserControl
{

static readonly UISettings uISettings = new UISettings();
Expand Down
2 changes: 0 additions & 2 deletions GUI/CustomControls/DialogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ private void Btn_close_Click(object sender, EventArgs e)
private void DialogForm_Load(object sender, EventArgs e)
{
this.btnClose.Location = new Point(this.Width - this.btnClose.Width - 2, 2);
CenterToScreen();
CenterToParent();
}

private void DialogForm_MouseDown(object sender, MouseEventArgs e)
Expand Down
Loading

0 comments on commit 7525dfa

Please sign in to comment.