Skip to content

Commit

Permalink
Add services and modify dashboard hosts content template
Browse files Browse the repository at this point in the history
  • Loading branch information
dogzz9445 committed Jun 13, 2024
1 parent 5427d32 commit 524ce5c
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 54 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ Corathing is Customizable Widget Organizer. It is a WPF application that allows
| Name| Folder |Framework | Description | Version
| --- | --- | --- | --- | --- |
| Corathing.Organizer | src/Apps | WPF | 메인 앱, 데스크톱용 오거나이저 프로그램 | ```구현중```
| Corathing.Dashboards.Sample | src/Apps | WPF | 대시보드 화면 샘플 프로그램 | ```시작전```
| Corathing.Dashboards.Sample | src/Apps | WPF | 대시보드 화면 샘플 프로그램 | ```구현중```
| Corathing.Contracts | src/Shared | C# | Organizer와 Widget 구현물 간 정의 | ```구현중```
| Corathing.Dashboards | src/Shared | C# | 백그라운드 원격 제어 서버 프로그램 | ```구현중```
| Corathing.Dashboards.WPF | src/Shared | WPF | 백그라운드 원격 제어 서버 프로그램 | ```구현중```

```mermaid
graph
A[Corathing.Organizer] --> B[Corathing.Contracts]
A --> C1[Corathing.Dashboards]
A[Main App - Corathing.Organizer] --> B[Corathing.Contracts]
A --> C2[Corathing.Dashboards.WPF]
A --> C1[Corathing.Dashboards]
C2 --> C1
C2 --> B
C2 --> C1
C1 --> B
subgraph CustomWidgets
D[CustomWidgets]
E[DefaultWidgets]
D[OtherWidgets]
end
D --> B
D --> C2
A -. Import as DLL .-> CustomWidgets
A -. Import as Assembly .-> CustomWidgets
CustomWidgets --> B
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);

foreach (var widget in Widgets)
foreach (var widget in Widgets)
{
widget.EditMode = EditMode;
}
Expand Down
59 changes: 40 additions & 19 deletions src/Apps/Corathing.Organizer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,26 @@ protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

//Application.Current.DispatcherUnhandledException += (sender, args) =>
//{
// MessageBox.Show(args.Exception.Message, "Unhandled exception occured");
// //Logger.LogError(args.Exception, "Unhandled exception occured");
//};
// 오류 발생 시 처리
Application.Current.DispatcherUnhandledException += (sender, args) =>
{
MessageBox.Show(args.Exception.Message, "Unhandled exception occured");
// FIXME:
// Logger 사용
//Logger.LogError(args.Exception, "Unhandled exception occured");
};

// 같은 이름의 다른 프로세스가 실행중인지 확인하고, 실행중이면 종료
if (CheckIfProcessExists())
{
MessageBox.Show(
"Another instance of the application is already running.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
//if (CheckIfProcessExists())
//{
// MessageBox.Show(
// "Another instance of the application is already running.",
// "Error",
// MessageBoxButton.OK,
// MessageBoxImage.Error);

Shutdown();
}
// Shutdown();
//}

Services = ConfigureServices(e.Args);

Expand All @@ -69,6 +72,8 @@ protected override async void OnStartup(StartupEventArgs e)

var appSettings = appStateService.GetAppSettings();
var appPreferences = appStateService.GetAppPreferenceState();
var appPackages = appStateService.GetAppPackageState();
var appDashboards = appStateService.GetAppDashboardState();

// Set the theme
var theme = appStateService.GetAppPreferenceState().Theme ?? ApplicationTheme.Light;
Expand Down Expand Up @@ -112,6 +117,9 @@ protected override async void OnStartup(StartupEventArgs e)
LocalizationService.Instance.RegisterStringResourceManager("Corathing.Widgets.Basics",
BasicWidgetStringResources.ResourceManager);

Check failure on line 118 in src/Apps/Corathing.Organizer/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64)

'BasicWidgetStringResources' is inaccessible due to its protection level

Check failure on line 118 in src/Apps/Corathing.Organizer/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build (x64)

'BasicWidgetStringResources' is inaccessible due to its protection level

// --------------------------------------------------------------------------
// Configure authentication
// --------------------------------------------------------------------------
IAuthService authService = App.Current.Services.GetService<IAuthService>();
if (authService != null && authService.UseAuthService)
{
Expand Down Expand Up @@ -146,29 +154,42 @@ private static IServiceProvider ConfigureServices(string[] args)
{
var serviceCollection = new ServiceCollection();

// --------------------------------------------------------------------------
// Build the configuration
// --------------------------------------------------------------------------
var configuration = BuildConfiguration(args);
serviceCollection.AddSingleton<IConfiguration>(configuration);

// Wpf.Ui Service
// TODO: This should be implmented with IDialogService (Corathing.Contracts.Services)
// TODO:
// Currently, use Wpf.Ui service,
// This should be implmented with IDialogService (Corathing.Contracts.Services)
// RoadMap 3, Content Presenter (Binding using Context)
serviceCollection.AddSingleton<IContentDialogService, ContentDialogService>();

// --------------------------------------------------------------------------
// Register services
// --------------------------------------------------------------------------
serviceCollection.AddSingleton<IApplicationService, ApplicationService>();
serviceCollection.AddSingleton<ISecretService, ModelVersionSecretService>();
serviceCollection.AddSingleton<IAuthService, AuthService>();
serviceCollection.AddSingleton<IAppStateService, AppStateService>();
serviceCollection.AddSingleton<IAuthService, AuthService>();
serviceCollection.AddSingleton<IDialogService, DialogService>();
serviceCollection.AddSingleton<ILocalizationService>(LocalizationService.Instance);
serviceCollection.AddSingleton<IPackageService, PackageService>();
serviceCollection.AddSingleton<IResourceDictionaryService, ResourceDictionaryService>();
serviceCollection.AddSingleton<ISecretService, ModelVersionSecretService>();
serviceCollection.AddSingleton<IStorageService, StorageService>();
serviceCollection.AddSingleton<IThemeService, ThemeService>();
serviceCollection.AddSingleton<ILocalizationService>(LocalizationService.Instance);
serviceCollection.AddSingleton<IWidgetService, WidgetService>();

// --------------------------------------------------------------------------
// Register viewmodels
// --------------------------------------------------------------------------
serviceCollection.AddScoped<OrganizerSettingsViewModel>();
serviceCollection.AddScoped<WidgetSettingsViewModel>();
serviceCollection.AddScoped<ProjectSettingsViewModel>();

// TODO:
// Logger 및 Localizer 설정
//Logger.Configure(configuration);
//Localizer.Configure(configuration);

Expand Down
4 changes: 2 additions & 2 deletions src/Apps/Corathing.Organizer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
<Grid>
<views:DashboardView DockPanel.Dock="Bottom" />

<tray:NotifyIcon Grid.Row="0"
<!--<tray:NotifyIcon Grid.Row="0"
FocusOnLeftClick="True"
Icon="pack://application:,,,/Assets/logo_256.png"
MenuOnRightClick="True"
TooltipText="WPF UI Gallery">
<tray:NotifyIcon.Menu>
<ContextMenu ItemsSource="{Binding ViewModel.TrayMenuItems, Mode=OneWay}" />
</tray:NotifyIcon.Menu>
</tray:NotifyIcon>
</tray:NotifyIcon>-->
</Grid>
</metro:MetroWindow>
13 changes: 13 additions & 0 deletions src/Apps/Corathing.Organizer/Services/ResourceDictionaryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Corathing.Contracts.Services;

namespace Corathing.Organizer.Services;

public class ResourceDictionaryService : IResourceDictionaryService
{
}
27 changes: 27 additions & 0 deletions src/Apps/Corathing.Organizer/Services/StorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Corathing.Contracts.Services;

namespace Corathing.Organizer.Services;

public class StorageService : IStorageService
{
public void Delete(string filename)
{
throw new NotImplementedException();
}

public Task<StorageHandleArgs<T>> ReadAsync<T>(string filename)
{
throw new NotImplementedException();
}

public Task<StorageHandleArgs<T>> SaveAsync<T>(string filename, T content)
{
throw new NotImplementedException();
}
}
9 changes: 5 additions & 4 deletions src/Apps/Corathing.Organizer/Services/WidgetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using System.Text;
using System.Threading.Tasks;

namespace Corathing.Organizer.Services
using Corathing.Contracts.Services;

namespace Corathing.Organizer.Services;

public class WidgetService : IWidgetService
{
class WidgetService
{
}
}
32 changes: 20 additions & 12 deletions src/Apps/Corathing.Organizer/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

using Microsoft.Extensions.DependencyInjection;

using NuGet.Packaging;

using Wpf.Ui;

using static MaterialDesignThemes.Wpf.Theme.ToolBar;
Expand Down Expand Up @@ -68,6 +70,14 @@ public partial class DashboardViewModel : ObservableObject

#endregion Private Fields

#region Contructors
public DashboardViewModel()
{
Projects = new ObservableCollection<ProjectContext>();
AddWidgetMenuItemViewModels = new ObservableCollection<MenuItemViewModel>();
}
#endregion

#region Public Properties

protected override void OnPropertyChanged(PropertyChangedEventArgs e)
Expand Down Expand Up @@ -213,23 +223,18 @@ public void DashboardConfigurationComplete(DashboardConfigurationType type, bool
/// <returns>Task.</returns>
public Task Start(IServiceProvider services)
{
// --------------------------------------------------------------------------
// Available Widgets
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// Load Component Data
// --------------------------------------------------------------------------
Projects = new ObservableCollection<ProjectContext>
Projects.AddRange(new []
{
new ProjectContext { Title = "My Project" }
};
SelectedProject = Projects[0];
SelectedProject.Workflows.Add(new WorkflowContext { Title = "My Workflow" });

//Workflows = [new WorkflowContext { Title = "My Workflow" }];
//SelectedWorkflow = Workflows[0];
AddWidgetMenuItemViewModels = new ObservableCollection<MenuItemViewModel>();
});
SelectedProject = Projects.FirstOrDefault();
SelectedProject.Workflows.AddRange(new[]
{
new WorkflowContext { Title = "My Workflow" }
});

// --------------------------------------------------------------------------
// Add Widget Menu
Expand All @@ -240,6 +245,9 @@ public Task Start(IServiceProvider services)
MenuItems = new ObservableCollection<MenuItemViewModel>(),
});

// --------------------------------------------------------------------------
// Add Widget Menu
// --------------------------------------------------------------------------
IPackageService packageService = services.GetService<IPackageService>();
foreach (var widget in packageService.GetAvailableWidgets())
{
Expand Down
7 changes: 3 additions & 4 deletions src/Shared/Corathing.Contracts/Services/IWidgetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using System.Text;
using System.Threading.Tasks;

namespace Corathing.Contracts.Services
namespace Corathing.Contracts.Services;

public interface IWidgetService
{
internal class IWidgetService
{
}
}
38 changes: 33 additions & 5 deletions src/Shared/Corathing.Dashboards.WPF/Controls/DashboardHost.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,45 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Corathing.Dashboards.WPF.Controls"
FocusVisualStyle="{x:Null}">
FocusVisualStyle="{DynamicResource ControlFocusVisualStyle}">
<ItemsControl.Resources>
<Color x:Key="KeyboardFocusBorderColor">#87FFFFFF</Color>

<SolidColorBrush x:Key="KeyboardFocusBorderColorBrush"
Color="{StaticResource KeyboardFocusBorderColor}" />

<Style x:Key="ControlFocusVisualStyle">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle RadiusX="4"
RadiusY="4"
SnapsToDevicePixels="True"
Stroke="{DynamicResource KeyboardFocusBorderColorBrush}"
StrokeThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="EmptyControlFocusVisualStyle">
<Setter Property="Control.Template"
Value="{x:Null}" />
</Style>


</ItemsControl.Resources>

<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer x:Name="DashboardHostScrollViewer"
FocusVisualStyle="{x:Null}"
FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<AdornerDecorator FocusVisualStyle="{x:Null}">
<Grid FocusVisualStyle="{x:Null}">
<AdornerDecorator FocusVisualStyle="{DynamicResource EmptyControlFocusVisualStyle}">
<Grid>
<Canvas x:Name="HighlightWidgetCanvas"
FocusVisualStyle="{x:Null}" />
FocusVisualStyle="{DynamicResource EmptyControlFocusVisualStyle}" />
<ItemsPresenter />
</Grid>
</AdornerDecorator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public bool CanDropFile
private readonly List<WidgetHost> _widgetHosts = new List<WidgetHost>();
private List<WidgetLayout> _widgetLayouts = new List<WidgetLayout>();


// True if a drag is in progress.
private bool DragInProgress = false;
private DragAdorner _draggingAdorner;
Expand Down Expand Up @@ -578,6 +577,7 @@ private void DashboardHost_Unloaded(object sender, RoutedEventArgs e)
private void EditEnabler()
{
AllowDrop = EditMode;
_widgetHosts.ForEach(widgetHost => widgetHost.EditMode = EditMode);

if (EditMode)
return;
Expand Down
Loading

0 comments on commit 524ce5c

Please sign in to comment.