7
7
using Microsoft . PowerToys . Settings . UI . Library ;
8
8
using System . Windows . Controls ;
9
9
using System . Linq ;
10
+ using Community . PowerToys . Run . Plugin . Update ;
11
+ using Wox . Infrastructure . Storage ;
12
+ using Wox . Plugin . Logger ;
10
13
11
14
namespace Community . PowerToys . Run . Plugin . Its_MyPic
12
15
{
13
- public class Main : IPlugin , IDelayedExecutionPlugin , IContextMenu , ISettingProvider , IPluginI18n
16
+ public class Main : IPlugin , IDelayedExecutionPlugin , IContextMenu , ISettingProvider , IPluginI18n , ISavable
14
17
{
15
18
public static string PluginID => "048FCB4CE3034FD9ACD9486F9FAB1F9E" ;
16
19
public string Name => "Its-MyPic" ;
@@ -30,6 +33,13 @@ public class Main : IPlugin, IDelayedExecutionPlugin, IContextMenu, ISettingProv
30
33
31
34
private readonly Data DB = new ( ) ;
32
35
36
+ private PluginJsonStorage < SampleSettings > Storage { get ; set ; }
37
+ public void Save ( ) => Storage . Save ( ) ;
38
+
39
+ private SampleSettings Settings { get ; set ; }
40
+
41
+ private PluginUpdateHandler Updater { get ; set ; }
42
+ private PluginInitContext Context { get ; set ; }
33
43
34
44
public List < Result > Query ( Query query )
35
45
{
@@ -38,12 +48,34 @@ public List<Result> Query(Query query)
38
48
public List < Result > Query ( Query query , bool delayedExecution )
39
49
{
40
50
var search = query . Search . ToLower ( ) ;
41
- var results = DB . GetMatchedSubtitleDatas ( search , delayedExecution ) ;
51
+ List < Result > results ;
52
+ if ( Updater . IsUpdateAvailable ( ) )
53
+ {
54
+ Log . Info ( "Update available" , GetType ( ) ) ;
55
+ results = Updater . GetResults ( ) ;
56
+ }
57
+ else
58
+ {
59
+ results = DB . GetMatchedSubtitleDatas ( search , delayedExecution ) ;
60
+ }
42
61
return results ;
43
62
}
44
63
public void Init ( PluginInitContext context )
45
64
{
46
65
CopyImage = false ;
66
+ Context = context ;
67
+
68
+ Storage = new PluginJsonStorage < SampleSettings > ( ) ;
69
+ Settings = Storage . Load ( ) ;
70
+
71
+ Log . Info ( context . CurrentPluginMetadata . Version , GetType ( ) ) ;
72
+
73
+ Updater = new PluginUpdateHandler ( Settings . Update ) ;
74
+ Updater . UpdateInstalling += OnUpdateInstalling ;
75
+ Updater . UpdateInstalled += OnUpdateInstalled ;
76
+ Updater . UpdateSkipped += OnUpdateSkipped ;
77
+
78
+ Updater . Init ( Context ) ;
47
79
}
48
80
49
81
public List < ContextMenuResult > LoadContextMenus ( Result selectedResult )
@@ -86,5 +118,24 @@ public string GetTranslatedPluginDescription()
86
118
{
87
119
throw new System . NotImplementedException ( ) ;
88
120
}
121
+
122
+
123
+ private void OnUpdateInstalling ( object sender , PluginUpdateEventArgs e )
124
+ {
125
+ Log . Info ( "UpdateInstalling: " + e . Version , GetType ( ) ) ;
126
+ }
127
+
128
+ private void OnUpdateInstalled ( object sender , PluginUpdateEventArgs e )
129
+ {
130
+ Log . Info ( "UpdateInstalled: " + e . Version , GetType ( ) ) ;
131
+ Context ! . API . ShowNotification ( $ "{ Name } { e . Version } ", "Update installed" ) ;
132
+ }
133
+
134
+ private void OnUpdateSkipped ( object sender , PluginUpdateEventArgs e )
135
+ {
136
+ Log . Info ( "UpdateSkipped: " + e . Version , GetType ( ) ) ;
137
+ Save ( ) ;
138
+ Context ? . API . ChangeQuery ( Context . CurrentPluginMetadata . ActionKeyword , true ) ;
139
+ }
89
140
}
90
141
}
0 commit comments