Skip to content

Commit 0b2f8be

Browse files
committed
Add support for Dev Home
1 parent eaf7526 commit 0b2f8be

4 files changed

Lines changed: 123 additions & 27 deletions

File tree

src/Templates.cs

Lines changed: 117 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
using Microsoft.UI.Xaml.Controls;
1+
using ABI.System;
2+
using Microsoft.UI.Xaml;
3+
using Microsoft.UI.Xaml.Controls;
4+
using Microsoft.UI.Xaml.Media;
5+
using Microsoft.VisualBasic;
26
using System;
37
using System.Collections.Generic;
8+
using System.ComponentModel;
49
using System.Linq;
10+
using System.Net.WebSockets;
511
using System.Text;
612
using System.Threading.Tasks;
13+
using Windows.ApplicationModel;
714
using Windows.Graphics.Printing.PrintSupport;
15+
using Windows.UI.Text;
16+
using WingetUIWidgetProvider;
17+
using static System.Net.Mime.MediaTypeNames;
818

919
namespace WingetUIWidgetProvider
1020
{
@@ -207,20 +217,15 @@ private static string GeneratePackageStructure(int index)
207217
""cells"": [
208218
{
209219
""type"": ""TableCell"",
210-
""minHeight"": ""2px"",
211220
""items"": [
212221
{
213222
""type"": ""Image"",
214-
""url"": ""${Icon"+index.ToString()+ @"}"",
215-
""horizontalAlignment"": ""Center"",
216-
""width"": ""24px"",
217-
""spacing"": ""Padding""
223+
""url"": ""${Icon" + index.ToString()+ @"}""
218224
}
219225
],
220-
""backgroundImage"": {
221-
""verticalAlignment"": ""Center""
222-
},
223-
""verticalContentAlignment"": ""Center""
226+
""verticalContentAlignment"": ""Center"",
227+
""minHeight"": ""36px"",
228+
""spacing"": ""None""
224229
},
225230
{
226231
""type"": ""TableCell"",
@@ -252,7 +257,8 @@ private static string GeneratePackageStructure(int index)
252257
]
253258
}
254259
],
255-
""verticalContentAlignment"": ""Center""
260+
""verticalContentAlignment"": ""Center"",
261+
""spacing"": ""None""
256262
},
257263
{
258264
""type"": ""TableCell"",
@@ -265,17 +271,22 @@ private static string GeneratePackageStructure(int index)
265271
""title"": ""🡇"",
266272
""verb"": """ + Verbs.UpdatePackage + index.ToString() + @""",
267273
""data"": {},
268-
""tooltip"": ""Update this package""
274+
""tooltip"": ""Update this package"",
275+
""spacing"": ""None""
269276
}
270277
],
271-
""horizontalAlignment"": ""Center""
278+
""horizontalAlignment"": ""Center"",
279+
""spacing"": ""None""
272280
}
273281
],
274282
""verticalContentAlignment"": ""Center"",
275-
""minHeight"": ""36px""
283+
""spacing"": ""None"",
284+
""minHeight"": ""36px"",
285+
""spacing"": ""None""
276286
}
277287
],
278-
""$when"": ""${$root.Package" + index.ToString()+@"Visisble}""
288+
""$when"": ""${$root.Package" + index.ToString()+ @"Visisble}"",
289+
""spacing"": ""None""
279290
}";
280291
return package;
281292
}
@@ -313,6 +324,92 @@ public static string GetData_UpdatesList(int count, Package[] upgradablePackages
313324
return data;
314325
}
315326

327+
private static string GetUpdatesListTemplate(int numOfPackages)
328+
{
329+
string basestr = @"
330+
{
331+
""type"": ""Container"",
332+
""items"": [
333+
{
334+
""type"": ""TextBlock"",
335+
""text"": ""Available Updates: ${count}"",
336+
""wrap"": true,
337+
""weight"": ""bolder"",
338+
""size"": ""medium""
339+
},
340+
{
341+
""type"": ""Table"",
342+
""columns"": [
343+
{
344+
""width"": ""32px""
345+
},
346+
{
347+
""width"": 1
348+
},
349+
{
350+
""width"": ""42px""
351+
}
352+
],
353+
""rows"": [";
354+
355+
for (int i = 0; i < numOfPackages; i++)
356+
basestr += GeneratePackageStructure(i) + ((i+1 == numOfPackages)? "\n": ",\n");
357+
358+
basestr += @"],
359+
""spacing"": ""None"",
360+
""showGridLines"": false,
361+
""height"": ""stretch"",
362+
""verticalCellContentAlignment"": ""Top""
363+
},
364+
{
365+
""type"": ""Container"",
366+
""verticalContentAlignment"": ""Center"",
367+
""items"": [
368+
{
369+
""type"": ""TextBlock"",
370+
""text"": ""${upgradablePackages}"",
371+
""horizontalAlignment"": ""Center"",
372+
""spacing"": ""None"",
373+
""weight"": ""Lighter"",
374+
""isSubtle"": true
375+
}
376+
],
377+
""height"": ""stretch"",
378+
""spacing"": ""None""
379+
},
380+
{
381+
""type"": ""ActionSet"",
382+
""actions"": [
383+
{
384+
""type"": ""Action.Execute"",
385+
""title"": ""Update all"",
386+
""verb"": """ + Verbs.UpdateAll + @"""
387+
},
388+
{
389+
""type"": ""Action.Execute"",
390+
""title"": ""Reload"",
391+
""verb"": """ + Verbs.Reload + @"""
392+
},
393+
{
394+
""type"": ""Action.Execute"",
395+
""title"": ""WingetUI"",
396+
""verb"": """ + Verbs.ViewUpdatesOnWingetUI + @"""
397+
}
398+
],
399+
""id"": ""buttons"",
400+
""horizontalAlignment"": ""Center"",
401+
""spacing"": ""None""
402+
}
403+
],
404+
""height"": ""stretch"",
405+
""$when"": ""${$root.UpdatesList}"",
406+
""spacing"": ""None"",
407+
""verticalContentAlignment"": ""Center""
408+
}";
409+
410+
return basestr;
411+
}
412+
316413
private static string UpdatesList = @"
317414
{
318415
""type"": ""Container"",
@@ -529,13 +626,15 @@ public static string GetData_UpdatesInCourse()
529626
}
530627
}";
531628

532-
public static string UpdatesTemplate = @"
629+
public static string GetUpdatesTemplate(int numOfUpdates)
630+
{
631+
return @"
533632
{
534633
""type"": ""AdaptiveCard"",
535634
""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"",
536635
""version"": ""1.5"",
537636
""body"": [
538-
" + UpdatesList + @"
637+
" + GetUpdatesListTemplate(numOfUpdates) + @"
539638
],
540639
""rtl"": false,
541640
""refresh"": {
@@ -545,7 +644,6 @@ public static string GetData_UpdatesInCourse()
545644
}
546645
}
547646
}";
548-
549-
647+
}
550648
}
551649
}

src/WidgetProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ private void WingetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv
8585
{
8686
e.widget.AvailableUpdates = e.Updates;
8787
Console.WriteLine("Showing available updates...");
88-
updateOptions.Template = Templates.UpdatesTemplate;
8988
string packages = "";
9089
Package[] upgradablePackages = new Package[e.widget.AvailableUpdates.Length];
9190
int nullPackages = 0;
@@ -104,7 +103,7 @@ private void WingetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv
104103
packages += (e.widget.AvailableUpdates.Length - i).ToString() + " more packages can also be upgraded";
105104
i = e.widget.AvailableUpdates.Length;
106105
}
107-
else if (e.widget.size == WidgetSize.Large && i == (7 + nullPackages) && e.widget.AvailableUpdates.Length > (7 + nullPackages) && e.widget.AvailableUpdates.Length > 7)
106+
else if (e.widget.size == WidgetSize.Large && i == (6 + nullPackages) && e.widget.AvailableUpdates.Length > (6 + nullPackages) && e.widget.AvailableUpdates.Length > 6)
108107
{
109108
i++;
110109
packages += (e.widget.AvailableUpdates.Length - i).ToString() + " more packages can also be upgraded";
@@ -119,11 +118,12 @@ private void WingetUI_UpdateCheckFinished(object? sender, UpdatesCheckFinishedEv
119118
}
120119
else
121120
{
121+
updateOptions.Template = Templates.GetUpdatesTemplate(e.widget.AvailableUpdates.Length);
122122
updateOptions.Data = Templates.GetData_UpdatesList(e.widget.AvailableUpdates.Length, upgradablePackages);
123123
}
124-
Debug.WriteLine(e.widget.Name);
125-
Debug.WriteLine(updateOptions.Template);
126-
Debug.WriteLine(updateOptions.Data);
124+
Console.WriteLine(e.widget.Name);
125+
Console.WriteLine(updateOptions.Template);
126+
Console.WriteLine(updateOptions.Data);
127127
WidgetManager.GetDefault().UpdateWidget(updateOptions);
128128
}
129129
}

src/WingetUIConnector.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ async public void GetAvailableUpdates(GenericWidget Widget, bool DeepCheck = fal
8383

8484
try
8585
{
86-
87-
8886
if (!is_connected_to_host)
8987
{
9088

src/WingetUIWidgetProvider.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>WinExe</OutputType>
4+
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>

0 commit comments

Comments
 (0)