Skip to content

Commit 0fa72db

Browse files
committed
Desktop integration mode added
1 parent ef47005 commit 0fa72db

File tree

6 files changed

+147
-68
lines changed

6 files changed

+147
-68
lines changed

Widgets/App.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ private void HandleLogEvent(object? sender, LogMessage logMessage)
158158
{
159159
Debug.WriteLine(logMessage.ToString());
160160

161-
var logFormat = $"[{logMessage.Timestamp}] [{logMessage.Level}] [{logMessage.PluginName}] {logMessage.Message}";
161+
var logFormat = $"[{logMessage.Timestamp:yyyy-MM-dd HH:mm:ss.fff}] [{logMessage.Level}] [{logMessage.PluginName}] {logMessage.Message}";
162162

163163
Logger.BufferLog(logFormat);
164164
}
165165

166166
// Unhandled excepitons
167167
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
168168
{
169-
Logger.Warning(e.Exception.Message);
169+
Logger.Warning(e.Exception);
170170
MessageBox.Show($"Error: {e.Exception.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
171171
e.Handled = true;
172172
}
@@ -176,15 +176,15 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
176176
{
177177
if (e.ExceptionObject is Exception exception)
178178
{
179-
Logger.Error(exception.Message);
179+
Logger.Error(exception);
180180
//MessageBox.Show($"Error: {exception.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
181181
}
182182
}
183183

184184
// Unhandled excepitons
185185
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
186186
{
187-
Logger.Error(e.Exception.Message);
187+
Logger.Error(e.Exception);
188188
//MessageBox.Show($"Error: {e.Exception.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
189189
e.SetObserved();
190190
}

Widgets/ConfigJsonStruct.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static WidgetJsonStruct ConfigToJsonStruct(WidgetDefaultStruct configStru
3939
ShowInTaskbar = configStruct.ShowInTaskbar,
4040
SizeToContent = configStruct.SizeToContent,
4141
IsHitTestVisible = configStruct.IsHitTestVisible,
42+
DesktopIntegration = configStruct.DesktopIntegration,
4243
Dragable = configStruct.Dragable,
4344
};
4445
}
@@ -66,6 +67,8 @@ public static WidgetDefaultStruct JsonToConfigStruct(WidgetJsonStruct defaultStr
6667
ShowInTaskbar = defaultStruct.ShowInTaskbar,
6768
AllowsTransparency= defaultStruct.AllowsTransparency,
6869
SizeToContent= defaultStruct.SizeToContent,
70+
IsHitTestVisible = defaultStruct.IsHitTestVisible,
71+
DesktopIntegration = defaultStruct.DesktopIntegration,
6972
Dragable = defaultStruct.Dragable,
7073
};
7174
}
@@ -93,6 +96,7 @@ public class WidgetJsonStruct
9396
public bool ShowInTaskbar { get; set; }
9497
public SizeToContent SizeToContent { get; set; }
9598
public bool IsHitTestVisible { get; set; }
99+
public bool DesktopIntegration { get; set; }
96100
public bool Dragable { get; set; }
97101
};
98102
}

Widgets/Manager.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@
179179
<TextBlock Text="Interactive" Foreground="{StaticResource TextBrush}" Width="100" VerticalAlignment="Center"/>
180180
<CheckBox x:Name="wInteractive" IsChecked="{Binding SelectedWidget.Interactive}" Foreground="{StaticResource TextBrush}" Style="{StaticResource CheckBox}"></CheckBox>
181181
</StackPanel>
182+
<StackPanel Margin="0 9" Orientation="Horizontal" HorizontalAlignment="Stretch">
183+
<TextBlock Text="Desktop Mode" Foreground="{StaticResource TextBrush}" Width="100" VerticalAlignment="Center"/>
184+
<CheckBox x:Name="wDesktopIntegration" IsChecked="{Binding SelectedWidget.DesktopIntegration}" Foreground="{StaticResource TextBrush}" Style="{StaticResource CheckBox}"></CheckBox>
182185
</StackPanel>
186+
</StackPanel>
183187

184188
<DockPanel Grid.Row="1" Grid.ColumnSpan="2" LastChildFill="False" Margin="0">
185189
<CheckBox x:Name="StartupCheckBox" Click="Startup_Click" Style="{StaticResource CheckBox}" DockPanel.Dock="Left" Foreground="{StaticResource TextBrush}">Start on system startup</CheckBox>

Widgets/Manager.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private void WindowSourceInitialized(object? sender, EventArgs e)
6767
}
6868

6969
// widget list to listbox
70-
public void CreateWidgetList()
70+
public async void CreateWidgetList()
7171
{
7272
WidgetListBox.ItemsSource = Widgets;
7373

@@ -87,6 +87,7 @@ public void CreateWidgetList()
8787
};
8888

8989
Widgets.Add(widgetViewModel);
90+
await widgetViewModel.WidgetLoaded();
9091

9192
}
9293
catch (Exception ex)

Widgets/WidgetViewModel.cs

Lines changed: 132 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.ComponentModel;
2-
using System.Diagnostics;
32
using System.Windows;
43
using System.Windows.Input;
54
using System.Windows.Media;
@@ -14,6 +13,7 @@ public partial class WidgetViewModel : INotifyPropertyChanged
1413

1514
public IPlugin Plugin;
1615
public string WidgetID;
16+
private TaskCompletionSource<bool>? widgetLoaded;
1717

1818
public WidgetViewModel(IPlugin Plugin)
1919
{
@@ -23,18 +23,61 @@ public WidgetViewModel(IPlugin Plugin)
2323
IsActive = WidgetSettings.IsActive;
2424
}
2525

26+
/// <summary>
27+
/// Widget Window Instance
28+
/// </summary>
29+
/// <returns></returns>
30+
private bool WidgetInit()
31+
{
32+
if (WidgetWindow == null)
33+
{
34+
try
35+
{
36+
widgetLoaded = new TaskCompletionSource<bool>();
37+
WidgetWindow = Plugin.WidgetWindow();
38+
WidgetWindow.SetWidgetStruct(WidgetSettings);
39+
WidgetWindow.Window.Loaded += WidgetWindow_Loaded;
40+
WidgetWindow.Window.Activated += WidgetWindow_Activated;
41+
}
42+
catch (Exception ex)
43+
{
44+
Logger.Error($"Widget Window Instance:{ex.Message}");
45+
}
46+
}
47+
48+
return WidgetWindow != null;
49+
}
2650

2751
/// <summary>
28-
/// Formdaki widget Name binding
52+
/// Open Widget Window
2953
/// </summary>
30-
private string _name = "";
31-
public string Name
54+
private void WidgetOpen()
3255
{
33-
get { return _name; }
34-
set
56+
if (WidgetInit() && WidgetWindow is not null)
3557
{
36-
_name = value;
37-
OnPropertyChanged(nameof(Name));
58+
if (_isActive && !WidgetWindow.Window.IsVisible)
59+
{
60+
WidgetWindow.Window.Show();
61+
Logger.Info($"Plugin Activated: {Plugin.Name}");
62+
}
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Close Widget Window
68+
/// </summary>
69+
private void WidgetClose()
70+
{
71+
if (WidgetInit() && WidgetWindow is not null)
72+
{
73+
if (!_isActive && WidgetWindow.Window.IsVisible)
74+
{
75+
WidgetWindow.Window.Close();
76+
WidgetWindow.Window.Loaded -= WidgetWindow_Loaded;
77+
WidgetWindow.Window.Activated -= WidgetWindow_Activated;
78+
WidgetWindow = null;
79+
Logger.Info($"Plugin Deactivated: {Plugin.Name}");
80+
}
3881
}
3982
}
4083

@@ -51,49 +94,39 @@ public bool IsActive
5194
{
5295
_isActive = value;
5396

54-
WidgetSettings.IsActive = value;
97+
WidgetSettings.IsActive = _isActive;
5598
Instance.SetConfig(WidgetID, WidgetSettings);
5699
Instance.Save();
57100

58-
if (WidgetWindow == null && _isActive)
101+
if(_isActive)
59102
{
60-
try
61-
{
62-
WidgetWindow = Plugin.WidgetWindow();
63-
WidgetWindow.SetWidgetStruct(WidgetSettings);
64-
WidgetWindow.Window.Loaded += WidgetWindow_Loaded;
65-
WidgetWindow.Window.Activated += WidgetWindow_Activated;
66-
}
67-
catch (Exception ex)
68-
{
69-
Logger.Error($"Widget Window Instance:{ex.Message}");
70-
}
103+
WidgetOpen();
71104
}
72-
73-
// WidgetWindow State
74-
if (WidgetWindow != null)
105+
else
75106
{
76-
if (_isActive && !WidgetWindow.Window.IsVisible)
77-
{
78-
WidgetWindow.Window.Show();
79-
Logger.Info($"Plugin Activated: {Plugin.Name}");
80-
}
81-
82-
if (!_isActive && WidgetWindow.Window.IsVisible)
83-
{
84-
WidgetWindow.Window.Close();
85-
WidgetWindow.Window.Loaded -= WidgetWindow_Loaded;
86-
WidgetWindow.Window.Activated -= WidgetWindow_Activated;
87-
WidgetWindow = null;
88-
Logger.Info($"Plugin Deactivated: {Plugin.Name}");
89-
}
107+
WidgetClose();
90108
}
91109

92110
OnPropertyChanged(nameof(IsActive));
93111
}
94112
}
95113
}
96114

115+
116+
/// <summary>
117+
/// Formdaki widget Name binding
118+
/// </summary>
119+
private string _name = "";
120+
public string Name
121+
{
122+
get { return _name; }
123+
set
124+
{
125+
_name = value;
126+
OnPropertyChanged(nameof(Name));
127+
}
128+
}
129+
97130
/// <summary>
98131
/// Window kapandığında aktif olanları pasife çekme
99132
/// </summary>
@@ -352,7 +385,7 @@ public Color Background
352385
}
353386

354387
/// <summary>
355-
/// Widget Dragable
388+
/// Widget SizeToContent
356389
/// </summary>
357390
private int _sizeToContent;
358391
public int SizeToContent
@@ -405,7 +438,7 @@ public bool Dragable
405438
}
406439

407440
/// <summary>
408-
/// Widget Dragable
441+
/// Widget Resizable
409442
/// </summary>
410443
private int _resizable;
411444
public int Resizable
@@ -420,7 +453,7 @@ public int Resizable
420453
}
421454

422455
/// <summary>
423-
/// Widget Dragable
456+
/// Widget Interactive
424457
/// </summary>
425458
private bool _interactive;
426459
public bool Interactive
@@ -437,6 +470,24 @@ public bool Interactive
437470
}
438471
}
439472

473+
/// <summary>
474+
/// Widget Dragable
475+
/// </summary>
476+
private bool _desktopIntegration;
477+
public bool DesktopIntegration
478+
{
479+
get { return _desktopIntegration; }
480+
set
481+
{
482+
_desktopIntegration = value;
483+
if (WidgetWindow != null)
484+
{
485+
WidgetWindow.DesktopIntegration = _desktopIntegration;
486+
}
487+
OnPropertyChanged(nameof(DesktopIntegration));
488+
}
489+
}
490+
440491
//widget is Dragable
441492
private void WidgetDragableUpdate()
442493
{
@@ -470,7 +521,7 @@ private void Widget_MouseDown_Dragable(object sender, MouseButtonEventArgs e)
470521
}
471522
}
472523

473-
//widget is Dragable
524+
//widget is Resizable
474525
private void WidgetResizableUpdate()
475526
{
476527
if (WidgetWindow != null && WidgetWindow.Window.IsVisible)
@@ -488,7 +539,7 @@ private void WidgetResizableUpdate()
488539
}
489540
}
490541

491-
// Widget window dragmove
542+
// Widget window resize
492543
private void Widget_Resize(object sender, SizeChangedEventArgs e)
493544
{
494545
if (WidgetWindow != null && WidgetWindow.Window.IsActive)
@@ -501,8 +552,25 @@ private void Widget_Resize(object sender, SizeChangedEventArgs e)
501552
// Widget window Loaded
502553
private void WidgetWindow_Loaded(object sender, RoutedEventArgs e)
503554
{
504-
Resizable = (int)WidgetSettings.ResizeMode;
505-
Dragable = WidgetSettings.Dragable;
555+
try
556+
{
557+
Resizable = (int)WidgetSettings.ResizeMode;
558+
Dragable = WidgetSettings.Dragable;
559+
DesktopIntegration = WidgetSettings.DesktopIntegration;
560+
}
561+
finally
562+
{
563+
widgetLoaded?.SetResult(true);
564+
}
565+
}
566+
567+
// Widget window Activated
568+
public async Task WidgetLoaded()
569+
{
570+
if (widgetLoaded != null)
571+
{
572+
await widgetLoaded.Task;
573+
}
506574
}
507575

508576
// Widget window Activated
@@ -514,23 +582,24 @@ private void WidgetWindow_Activated(object? sender, EventArgs e)
514582

515583
public void InitSettings()
516584
{
517-
Width = WidgetSettings.Width;
518-
Height = WidgetSettings.Height;
519-
MaxWidth = WidgetSettings.MaxWidth;
520-
MaxHeight = WidgetSettings.MaxHeight;
521-
MinWidth = WidgetSettings.MinWidth;
522-
MinHeight = WidgetSettings.MinHeight;
523-
Left = WidgetSettings.Left;
524-
Top = WidgetSettings.Top;
525-
Border = WidgetSettings.BorderThickness;
526-
Margin = WidgetSettings.Margin;
527-
Padding = WidgetSettings.Padding;
528-
BorderColor = WidgetSettings.BorderBrush.Color;
529-
Background = WidgetSettings.Background.Color;
530-
SizeToContent = (int)WidgetSettings.SizeToContent;
531-
Resizable = (int)WidgetSettings.ResizeMode;
532-
Interactive = WidgetSettings.IsHitTestVisible;
533-
Dragable = WidgetSettings.Dragable;
585+
_width = WidgetSettings.Width;
586+
_height = WidgetSettings.Height;
587+
_maxWidth = WidgetSettings.MaxWidth;
588+
_maxHeight = WidgetSettings.MaxHeight;
589+
_minWidth = WidgetSettings.MinWidth;
590+
_minHeight = WidgetSettings.MinHeight;
591+
_left = WidgetSettings.Left;
592+
_top = WidgetSettings.Top;
593+
_border = WidgetSettings.BorderThickness;
594+
_margin = WidgetSettings.Margin;
595+
_padding = WidgetSettings.Padding;
596+
_borderColor = WidgetSettings.BorderBrush.Color;
597+
_background = WidgetSettings.Background.Color;
598+
_sizeToContent = (int)WidgetSettings.SizeToContent;
599+
_interactive = WidgetSettings.IsHitTestVisible;
600+
_resizable = (int)WidgetSettings.ResizeMode;
601+
_dragable = WidgetSettings.Dragable;
602+
_desktopIntegration = WidgetSettings.DesktopIntegration;
534603
}
535604

536605
public WidgetDefaultStruct ExportSettings()
@@ -550,6 +619,7 @@ public WidgetDefaultStruct ExportSettings()
550619
WidgetSettings.ResizeMode = (ResizeMode)Resizable;
551620
WidgetSettings.Dragable = Dragable;
552621
WidgetSettings.IsHitTestVisible = Interactive;
622+
WidgetSettings.DesktopIntegration = DesktopIntegration;
553623
WidgetSettings.BorderBrush = new SolidColorBrush(BorderColor);
554624
WidgetSettings.Background = new SolidColorBrush(Background);
555625

Widgets/Widgets.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</ItemGroup>
2929
<ItemGroup>
3030
<Reference Include="Widgets.Common">
31-
<HintPath>..\..\Widgets.Common\Widgets.Common\bin\Debug\net8.0-windows\Widgets.Common.dll</HintPath>
31+
<HintPath>..\..\Widgets.Common\Widgets.Common\bin\Release\net8.0-windows\Widgets.Common.dll</HintPath>
3232
</Reference>
3333
</ItemGroup>
3434
</Project>

0 commit comments

Comments
 (0)