1
1
using System . ComponentModel ;
2
- using System . Diagnostics ;
3
2
using System . Windows ;
4
3
using System . Windows . Input ;
5
4
using System . Windows . Media ;
@@ -14,6 +13,7 @@ public partial class WidgetViewModel : INotifyPropertyChanged
14
13
15
14
public IPlugin Plugin ;
16
15
public string WidgetID ;
16
+ private TaskCompletionSource < bool > ? widgetLoaded ;
17
17
18
18
public WidgetViewModel ( IPlugin Plugin )
19
19
{
@@ -23,18 +23,61 @@ public WidgetViewModel(IPlugin Plugin)
23
23
IsActive = WidgetSettings . IsActive ;
24
24
}
25
25
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
+ }
26
50
27
51
/// <summary>
28
- /// Formdaki widget Name binding
52
+ /// Open Widget Window
29
53
/// </summary>
30
- private string _name = "" ;
31
- public string Name
54
+ private void WidgetOpen ( )
32
55
{
33
- get { return _name ; }
34
- set
56
+ if ( WidgetInit ( ) && WidgetWindow is not null )
35
57
{
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
+ }
38
81
}
39
82
}
40
83
@@ -51,49 +94,39 @@ public bool IsActive
51
94
{
52
95
_isActive = value ;
53
96
54
- WidgetSettings . IsActive = value ;
97
+ WidgetSettings . IsActive = _isActive ;
55
98
Instance . SetConfig ( WidgetID , WidgetSettings ) ;
56
99
Instance . Save ( ) ;
57
100
58
- if ( WidgetWindow == null && _isActive )
101
+ if ( _isActive )
59
102
{
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 ( ) ;
71
104
}
72
-
73
- // WidgetWindow State
74
- if ( WidgetWindow != null )
105
+ else
75
106
{
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 ( ) ;
90
108
}
91
109
92
110
OnPropertyChanged ( nameof ( IsActive ) ) ;
93
111
}
94
112
}
95
113
}
96
114
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
+
97
130
/// <summary>
98
131
/// Window kapandığında aktif olanları pasife çekme
99
132
/// </summary>
@@ -352,7 +385,7 @@ public Color Background
352
385
}
353
386
354
387
/// <summary>
355
- /// Widget Dragable
388
+ /// Widget SizeToContent
356
389
/// </summary>
357
390
private int _sizeToContent ;
358
391
public int SizeToContent
@@ -405,7 +438,7 @@ public bool Dragable
405
438
}
406
439
407
440
/// <summary>
408
- /// Widget Dragable
441
+ /// Widget Resizable
409
442
/// </summary>
410
443
private int _resizable ;
411
444
public int Resizable
@@ -420,7 +453,7 @@ public int Resizable
420
453
}
421
454
422
455
/// <summary>
423
- /// Widget Dragable
456
+ /// Widget Interactive
424
457
/// </summary>
425
458
private bool _interactive ;
426
459
public bool Interactive
@@ -437,6 +470,24 @@ public bool Interactive
437
470
}
438
471
}
439
472
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
+
440
491
//widget is Dragable
441
492
private void WidgetDragableUpdate ( )
442
493
{
@@ -470,7 +521,7 @@ private void Widget_MouseDown_Dragable(object sender, MouseButtonEventArgs e)
470
521
}
471
522
}
472
523
473
- //widget is Dragable
524
+ //widget is Resizable
474
525
private void WidgetResizableUpdate ( )
475
526
{
476
527
if ( WidgetWindow != null && WidgetWindow . Window . IsVisible )
@@ -488,7 +539,7 @@ private void WidgetResizableUpdate()
488
539
}
489
540
}
490
541
491
- // Widget window dragmove
542
+ // Widget window resize
492
543
private void Widget_Resize ( object sender , SizeChangedEventArgs e )
493
544
{
494
545
if ( WidgetWindow != null && WidgetWindow . Window . IsActive )
@@ -501,8 +552,25 @@ private void Widget_Resize(object sender, SizeChangedEventArgs e)
501
552
// Widget window Loaded
502
553
private void WidgetWindow_Loaded ( object sender , RoutedEventArgs e )
503
554
{
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
+ }
506
574
}
507
575
508
576
// Widget window Activated
@@ -514,23 +582,24 @@ private void WidgetWindow_Activated(object? sender, EventArgs e)
514
582
515
583
public void InitSettings ( )
516
584
{
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 ;
534
603
}
535
604
536
605
public WidgetDefaultStruct ExportSettings ( )
@@ -550,6 +619,7 @@ public WidgetDefaultStruct ExportSettings()
550
619
WidgetSettings . ResizeMode = ( ResizeMode ) Resizable ;
551
620
WidgetSettings . Dragable = Dragable ;
552
621
WidgetSettings . IsHitTestVisible = Interactive ;
622
+ WidgetSettings . DesktopIntegration = DesktopIntegration ;
553
623
WidgetSettings . BorderBrush = new SolidColorBrush ( BorderColor ) ;
554
624
WidgetSettings . Background = new SolidColorBrush ( Background ) ;
555
625
0 commit comments