Skip to content

Commit

Permalink
Edit widget entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 11, 2024
1 parent 0995ada commit 82a9f11
Show file tree
Hide file tree
Showing 42 changed files with 492 additions and 252 deletions.
23 changes: 23 additions & 0 deletions Corathing.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corathing.Widgets.Basics",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.UI.WPF", "src\Shared\Corathing.UI.WPF\Corathing.UI.WPF.csproj", "{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Corathing.Widget.Templates", "src\Widgets\Corathing.Widget.Templates\Corathing.Widget.Templates.csproj", "{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -221,6 +223,26 @@ Global
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x64.Build.0 = Release|Any CPU
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x86.ActiveCfg = Release|Any CPU
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB}.Release|x86.Build.0 = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|ARM.ActiveCfg = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|ARM.Build.0 = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|ARM64.Build.0 = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|x64.ActiveCfg = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|x64.Build.0 = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|x86.ActiveCfg = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Debug|x86.Build.0 = Debug|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|Any CPU.Build.0 = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|ARM.ActiveCfg = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|ARM.Build.0 = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|ARM64.ActiveCfg = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|ARM64.Build.0 = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|x64.ActiveCfg = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|x64.Build.0 = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|x86.ActiveCfg = Release|Any CPU
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -234,6 +256,7 @@ Global
{B07D1162-D70E-4CCB-8F13-2E21611B9214} = {89CC8AAB-466A-47B6-98B9-93EB379F55A7}
{8BB7B29E-4684-4F2F-9932-698FDAD2FCDA} = {B32F5E62-3357-4FE1-BEB3-7CDED236BA66}
{F0AF90D5-5E28-4FC1-8DBD-8B3F68A285DB} = {89CC8AAB-466A-47B6-98B9-93EB379F55A7}
{3CED3EA9-D293-44BD-9838-FC1AF1FFC626} = {B32F5E62-3357-4FE1-BEB3-7CDED236BA66}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FC027A8C-0C58-494B-BE76-F403F0336A74}
Expand Down
2 changes: 0 additions & 2 deletions src/Apps/Corathing.Organizer/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Secondary/MaterialDesignColor.Indigo.xaml" />
<ResourceDictionary Source="pack://application:,,,/Corathing.Dashboards.WPF;component/Themes/Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/Corathing.Dashboards.WPF;component/Styles/CustomStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/Corathing.Dashboards.WPF;component/Widgets/WidgetDataTemplates.xaml" />
<ResourceDictionary Source="pack://application:,,,/Corathing.Widgets.Basics;component/Widgets/DataTemplates.xaml" />
<ui:ThemesDictionary Theme="Light" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
Expand Down
2 changes: 0 additions & 2 deletions src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows;

using Corathing.Contracts.Services;
using Corathing.Dashboards.Services;
using Corathing.Dashboards.WPF.Services;
using Corathing.Organizer.Resources;
using Corathing.Organizer.Services;
Expand Down Expand Up @@ -109,7 +108,6 @@ protected override void OnStartup(StartupEventArgs e)
// Available Widgets
// --------------------------------------------------------------------------
IPackageService widgetService = Services.GetService<IPackageService>();
widgetService.LoadWidgetsFromDLL("Corathing.Dashboards.WPF.dll");
widgetService.LoadWidgetsFromDLL("Corathing.Widgets.Basics.dll");
//widgetService.LoadWidgetsFromDLL("DDT.Core.WidgetSystems.DefaultWidgets.dll");
//widgetService.RegisterWidgets(new List<WidgetGenerator> { new WidgetGenerator() });
Expand Down
45 changes: 38 additions & 7 deletions src/Apps/Corathing.Organizer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,51 @@
using System.Windows.Navigation;
using System.Windows.Shapes;

using Corathing.Organizer.ViewModels;

using MahApps.Metro.Controls;

using Wpf.Ui.Controls;

namespace Corathing.Organizer
namespace Corathing.Organizer;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
public MainViewModel ViewModel;

public MainWindow()
{
public MainWindow()
InitializeComponent();

DataContext = ViewModel = new MainViewModel();

MouseDown += Window_MouseDown;
MouseDoubleClick += Window_MouseDoubleClick;
}

private void Window_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (e.GetPosition(this).Y >= 64)
return;

if (e.ChangedButton == MouseButton.Left)
{
InitializeComponent();
if (WindowState == WindowState.Normal)
WindowState = WindowState.Maximized;
else
WindowState = WindowState.Normal;
}
}

private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.GetPosition(this).Y >= 64)
return;

if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using Corathing.Contracts.Attributes;
using Corathing.Contracts.Bases;
using Corathing.Contracts.Entries;

using Corathing.Contracts.Services;

namespace Corathing.Dashboards.Services;
namespace Corathing.Organizer.Services;


public class ProxyDomain : MarshalByRefObject
{
Expand All @@ -31,7 +34,7 @@ public class PackageService : IPackageService
/// Gets or sets the available widgets.
/// </summary>
/// <value>The available widgets.</value>
private readonly List<WidgetGenerator> _availableWidgets = new List<WidgetGenerator>();
private readonly List<CoraWidgetGenerator> _availableWidgets = new List<CoraWidgetGenerator>();
private readonly IServiceProvider _services;

public PackageService(IServiceProvider services)
Expand All @@ -40,11 +43,11 @@ public PackageService(IServiceProvider services)
}


public void RegisterWidgets(List<WidgetGenerator> widgets)
public void RegisterWidgets(List<CoraWidgetGenerator> widgets)
{
_availableWidgets.AddRange(widgets);
}
public List<WidgetGenerator> GetAvailableWidgets()
public List<CoraWidgetGenerator> GetAvailableWidgets()
{
return _availableWidgets;
}
Expand All @@ -53,30 +56,35 @@ public void LoadWidgetsFromDLL(string pathDLL)
{
Assembly a = Assembly.LoadFrom(pathDLL);
var types = a.GetTypes().Where(t => typeof(WidgetContext).IsAssignableFrom(t));
List<WidgetGenerator> widgets = new List<WidgetGenerator>();
// TODO:
// 도메인 프록시 문제 해결 필요
//var setup = new AppDomainSetup
//{
// ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
// PrivateBinPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
//};

foreach (var type in types)
{
System.Reflection.MemberInfo info = type;
var attributes = info.GetCustomAttributes(true);

for (int i = 0; i < attributes.Length; i++)
{
if (attributes[i] is WidgetContextEntryAttribute)
if (attributes[i] is EntryCoraWidgetAttribute)
{
var attribute = ((WidgetContextEntryAttribute)attributes[i]);
attribute.RegisterServices(_services);
widgets.Add(attribute.WidgetGenerator);
var attribute = ((EntryCoraWidgetAttribute)attributes[i]);
attribute.Configure(_services);
_availableWidgets.Add(attribute.Generator);

App.Current.Resources.MergedDictionaries.Add(
new ResourceDictionary()
{
Source = new Uri($"pack://application:,,,/{attribute.Generator.ViewType.Assembly.GetName().Name};component/{attribute.Generator.DataTemplateSource}", UriKind.Absolute)
}
);
}
}
}

RegisterWidgets(widgets);
}
}
7 changes: 5 additions & 2 deletions src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using Corathing.Contracts.Bases;
using Corathing.Contracts.Entries;
using Corathing.Contracts.Services;

using Corathing.Dashboards.WPF.Controls;
using Corathing.Organizer.Controls;
using Corathing.Organizer.Extensions;
using Corathing.Organizer.Models;
using Corathing.Organizer.Views;

using Microsoft.Extensions.DependencyInjection;

using Wpf.Ui;
Expand Down Expand Up @@ -81,7 +84,7 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
}

[RelayCommand]
public void AddWidget(WidgetGenerator generator)
public void AddWidget(CoraWidgetGenerator generator)
{
if (SelectedProject == null)
return;
Expand Down Expand Up @@ -290,7 +293,7 @@ public Task Start(IServiceProvider services)
IPackageService packageService = services.GetService<IPackageService>();
foreach (var widget in packageService.GetAvailableWidgets())
{
var fullMenuHeader = widget.MenuPath;
var fullMenuHeader = widget.MenuInfo.MenuPath;
if (string.IsNullOrEmpty(fullMenuHeader))
continue;

Expand Down
51 changes: 51 additions & 0 deletions src/Apps/Corathing.Organizer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using CommunityToolkit.Mvvm.ComponentModel;

using Wpf.Ui.Controls;

namespace Corathing.Organizer.ViewModels;

/// <summary>
/// Extended <see cref="System.Windows.Controls.MenuItem"/> with <see cref="SymbolRegular"/> properties.
/// </summary>
public class MenuItem : System.Windows.Controls.MenuItem
{
static MenuItem()
{
IconProperty.OverrideMetadata(typeof(MenuItem), new FrameworkPropertyMetadata(null));
}

/// <summary>
/// Gets or sets displayed <see cref="IconElement"/>.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"WpfAnalyzers.DependencyProperty",
"WPF0012:CLR property type should match registered type",
Justification = "seems harmless"
)]
public new IconElement Icon
{
get => (IconElement)GetValue(IconProperty);
set => SetValue(IconProperty, value);
}
}

public partial class MainViewModel : ObservableObject
{

[ObservableProperty]
private ObservableCollection<MenuItem> _trayMenuItems = [];

public MainViewModel()
{

TrayMenuItems = [new() { Header = "Home", Tag = "tray_home" }];
}
}

This file was deleted.

15 changes: 15 additions & 0 deletions src/Shared/Corathing.Contracts/Entries/CoraWidgetGenerationInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Corathing.Contracts.Entries;

public class CoraWidgetGenerationInfo
{
public string Name { get; set; }
public string Description { get; set; }
public string MenuPath { get; set; }
public int MenuOrder { get; set; }
}
Loading

0 comments on commit 82a9f11

Please sign in to comment.