Skip to content

Commit 8478aa1

Browse files
committed
Improved the API
1 parent e40eb81 commit 8478aa1

File tree

11 files changed

+503
-552
lines changed

11 files changed

+503
-552
lines changed

JumpListManager.WinUI/ViewModels/MainPageViewModel.cs

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,73 +83,34 @@ public unsafe void EnumerateApplicationItems()
8383
public unsafe void EnumerateJumpListItems()
8484
{
8585
JumpListItems = new() { IsSourceGrouped = true, };
86-
86+
foreach (var list in GroupedJumpListItems) foreach (var item in list) item.Dispose();
8787
GroupedJumpListItems.Clear();
88-
foreach (var list in GroupedJumpListItems)
89-
foreach (var item in list) item.Dispose();
9088

9189
var amuid = ApplicationItems.ElementAt(SelectedIndexOfApplicationItems).AppUserModelID;
9290

93-
if (JumpListNative.Create(amuid) is not { } manager)
94-
throw new InvalidOperationException($"Failed to initialize {nameof(JumpListManager)}.");
95-
96-
InsertAutomaticDestinationItems(manager);
97-
InsertCustomDestinationItems(manager);
98-
InsertTaskItems(manager);
99-
100-
JumpListItems.Source = new ObservableCollection<JumpListGroupItem>(GroupedJumpListItems);
101-
102-
manager.Dispose();
103-
104-
void InsertAutomaticDestinationItems(JumpListNative manager)
105-
{
106-
var pinnedItems = new JumpListGroupItem() { Key = "Pinned" };
107-
108-
if (manager.HasAutomaticDestinationsOf(DESTLISTTYPE.PINNED))
109-
foreach (var item in manager.EnumerateAutomaticDestinationsOf(DESTLISTTYPE.PINNED))
110-
pinnedItems.Add(item);
91+
// Initialize the jump list manager
92+
using JumpList manager = JumpList.Create(amuid)
93+
?? throw new InvalidOperationException($"Failed to initialize {nameof(JumpListManager)}.");
11194

112-
if (pinnedItems.Count is not 0)
113-
GroupedJumpListItems.Add(pinnedItems);
95+
// Insert the pinned items
96+
if (manager.EnumeratePinnedItems() is { Count: not 0 } pinnedItems)
97+
GroupedJumpListItems.Add(pinnedItems);
11498

115-
var recentItems = new JumpListGroupItem() { Key = "Recent" };
99+
// Insert the recent items
100+
if (manager.EnumerateRecentItems() is { Count: not 0 } recentItems)
101+
GroupedJumpListItems.Add(recentItems);
116102

117-
if (manager.HasAutomaticDestinationsOf(DESTLISTTYPE.RECENT))
118-
{
119-
foreach (var item in manager.EnumerateAutomaticDestinationsOf(DESTLISTTYPE.RECENT))
120-
{
121-
recentItems.Add(item);
122-
}
123-
}
103+
// Insert the custom destination items
104+
int count = manager.GetCustomDestinationsCount();
105+
for (uint index = 0U; index < (uint)count; index++)
106+
if (manager.EnumerateCustomDestinationsAt(index) is { } list)
107+
GroupedJumpListItems.Add(list);
124108

125-
if (recentItems.Count is not 0)
126-
GroupedJumpListItems.Add(recentItems);
127-
}
109+
// Insert the task items
110+
if (manager.EnumerateTasks() is { Count: not 0 } taskItems)
111+
GroupedJumpListItems.Add(taskItems);
128112

129-
void InsertCustomDestinationItems(JumpListNative manager)
130-
{
131-
int count = manager.GetCustomDestinationsCount();
132-
133-
for (uint index = 0U; index < (uint)count; index++)
134-
{
135-
if (manager.EnumerateCustomDestinationsAt(index) is { } list)
136-
GroupedJumpListItems.Add(list);
137-
}
138-
}
139-
140-
void InsertTaskItems(JumpListNative manager)
141-
{
142-
var taskItems = new JumpListGroupItem() { Key = "Tasks" };
143-
144-
if (manager.EnumerateTasks() is not { } list)
145-
return;
146-
147-
foreach (var item in list)
148-
taskItems.Add(item);
149-
150-
if (taskItems.Count is not 0)
151-
GroupedJumpListItems.Add(taskItems);
152-
}
113+
JumpListItems.Source = new ObservableCollection<JumpListGroupItem>(GroupedJumpListItems);
153114
}
154115

155116
public unsafe void EnumerateContextMenuItems()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- Copyright (c) 0x5BFA. Licensed under the MIT License. -->
2+
<Page
3+
x:Class="JumpListManager.WinUI.Views.JumpListViewPage"
4+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:JumpListManager.WinUI.Views"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Grid />
12+
</Page>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 0x5BFA. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.UI.Xaml.Controls;
5+
6+
namespace JumpListManager.WinUI.Views
7+
{
8+
public sealed partial class JumpListViewPage : Page
9+
{
10+
public JumpListViewPage()
11+
{
12+
InitializeComponent();
13+
}
14+
}
15+
}

JumpListManager.WinUI/Views/MainPage.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- Copyright (c) 0x5BFA. Licensed under the MIT License. -->
12
<Page
23
x:Class="JumpListManager.Views.MainPage"
34
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

JumpListManager.WinUI/Views/AboutDialog.xaml renamed to JumpListManager.WinUI/Views/SettingsPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ContentDialog
2-
x:Class="JumpListManager.Views.AboutDialog"
2+
x:Class="JumpListManager.Views.SettingsPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

JumpListManager.WinUI/Views/AboutDialog.xaml.cs renamed to JumpListManager.WinUI/Views/SettingsPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace JumpListManager.Views
77
{
8-
public sealed partial class AboutDialog : ContentDialog
8+
public sealed partial class SettingsPage : ContentDialog
99
{
10-
public AboutDialog()
10+
public SettingsPage()
1111
{
1212
InitializeComponent();
1313
}

JumpListManager/ComPtr`1.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,28 @@ public void Attach(T* other)
4646
return ptr;
4747
}
4848

49+
public readonly HRESULT CopyTo(T** ptr)
50+
{
51+
InternalAddRef();
52+
*ptr = _ptr;
53+
54+
return HRESULT.S_OK;
55+
}
56+
4957
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5058
public readonly T* Get() => _ptr;
5159

5260
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5361
public readonly T** GetAddressOf() => (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
5462

63+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64+
private readonly void InternalAddRef()
65+
{
66+
T* ptr = _ptr;
67+
if (ptr != null)
68+
_ = ((IUnknown*)ptr)->AddRef();
69+
}
70+
5571
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5672
public void Dispose()
5773
{

JumpListManager/ICustomDestinationList2.cs renamed to JumpListManager/IInternalCustomDestinationList.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
// Copyright (c) 0x5BFA. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.Runtime.CompilerServices;
65
using System.Runtime.InteropServices;
76
using Windows.Win32.Foundation;
87

98
namespace Windows.Win32.System.Com
109
{
1110
/// <summary>
12-
/// Defines unmanaged raw vtable for the <see cref="ICustomDestinationList2"/> interface.
11+
/// Defines unmanaged raw vtable for the <see cref="IInternalCustomDestinationList"/> interface.
1312
/// </summary>
1413
/// <remarks>
1514
/// - <a href="https://github.com/GigabyteProductions/classicshell/blob/HEAD/src/ClassicStartMenu/ClassicStartMenuDLL/JumpLists.cpp"/>
1615
/// </remarks>
17-
public unsafe partial struct ICustomDestinationList2
16+
public unsafe partial struct IInternalCustomDestinationList
1817
{
1918
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
2019
private void** lpVtbl;
2120
#pragma warning restore CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
2221

2322
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2423
public HRESULT SetMinItems(uint dwMinItems)
25-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, uint, int>)lpVtbl[3])(
26-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), dwMinItems);
24+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, uint, int>)lpVtbl[3])(
25+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), dwMinItems);
2726

2827
/// <summary>
29-
/// Initializes this instance of <see cref="ICustomDestinationList2"/> with the specified Application User Model ID (AMUID).
28+
/// Initializes this instance of <see cref="IInternalCustomDestinationList"/> with the specified Application User Model ID (AMUID).
3029
/// </summary>
31-
/// <param name="pszAppID">The Application User Model ID to initialize this instance of <see cref="ICustomDestinationList2"/> with.</param>
30+
/// <param name="pszAppID">The Application User Model ID to initialize this instance of <see cref="IInternalCustomDestinationList"/> with.</param>
3231
/// <returns>Returns <see cref="HRESULT.S_OK"/> if successful, or an error value otherwise.</returns>
3332
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3433
public HRESULT SetApplicationID(PCWSTR pszAppID)
35-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, PCWSTR, int>)lpVtbl[4])(
36-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), pszAppID);
34+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, PCWSTR, int>)lpVtbl[4])(
35+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), pszAppID);
3736

3837
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3938
public HRESULT GetSlotCount(uint* pdwSlotCount)
40-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, uint*, int>)lpVtbl[5])(
41-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), pdwSlotCount);
39+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, uint*, int>)lpVtbl[5])(
40+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), pdwSlotCount);
4241

4342
/// <summary>
4443
/// Gets the number of categories in the custom destination list.
@@ -47,8 +46,8 @@ public HRESULT GetSlotCount(uint* pdwSlotCount)
4746
/// <returns>Returns <see cref="HRESULT.S_OK"/> if successful, or an error value otherwise.</returns>
4847
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4948
public HRESULT GetCategoryCount(uint* pdwCategoryCount)
50-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, uint*, int>)lpVtbl[6])(
51-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), pdwCategoryCount);
49+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, uint*, int>)lpVtbl[6])(
50+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), pdwCategoryCount);
5251

5352
/// <summary>
5453
/// Gets the category at the specified index in the custom destination list.
@@ -59,13 +58,13 @@ public HRESULT GetCategoryCount(uint* pdwCategoryCount)
5958
/// <returns>Returns <see cref="HRESULT.S_OK"/> if successful, or an error value otherwise.</returns>
6059
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6160
public HRESULT GetCategory(uint index, GETCATFLAG flags, APPDESTCATEGORY* pCategory)
62-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, uint, GETCATFLAG, APPDESTCATEGORY*, int>)lpVtbl[7])(
63-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), index, flags, pCategory);
61+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, uint, GETCATFLAG, APPDESTCATEGORY*, int>)lpVtbl[7])(
62+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), index, flags, pCategory);
6463

6564
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6665
public HRESULT DeleteCategory(uint a1, int a2)
67-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, int>)lpVtbl[8])(
68-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this));
66+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, int>)lpVtbl[8])(
67+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this));
6968

7069
/// <summary>
7170
/// Enumerates the destinations at the specific index in the categories in the custom destinations.
@@ -76,23 +75,23 @@ public HRESULT DeleteCategory(uint a1, int a2)
7675
/// <returns>Returns <see cref="HRESULT.S_OK"/> if successful, or an error value otherwise.</returns>
7776
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7877
public HRESULT EnumerateCategoryDestinations(uint index, Guid* riid, void** ppvObject)
79-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, uint, Guid*, void**, int>)lpVtbl[9])(
80-
(ICustomDestinationList2*)Unsafe.AsPointer(ref this), index, riid, ppvObject);
78+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, uint, Guid*, void**, int>)lpVtbl[9])(
79+
(IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), index, riid, ppvObject);
8180

8281
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8382
public HRESULT RemoveDestination(IUnknown* pObject)
84-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, IUnknown*, int>)lpVtbl[10])
85-
((ICustomDestinationList2*)Unsafe.AsPointer(ref this), pObject);
83+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, IUnknown*, int>)lpVtbl[10])
84+
((IInternalCustomDestinationList*)Unsafe.AsPointer(ref this), pObject);
8685

8786
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8887
public HRESULT HasListEx(int* a1, int* a2)
89-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, int>)lpVtbl[11])
90-
((ICustomDestinationList2*)Unsafe.AsPointer(ref this));
88+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, int>)lpVtbl[11])
89+
((IInternalCustomDestinationList*)Unsafe.AsPointer(ref this));
9190

9291
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9392
public HRESULT ClearRemovedDestinations()
94-
=> (HRESULT)((delegate* unmanaged[MemberFunction]<ICustomDestinationList2*, int>)lpVtbl[12])
95-
((ICustomDestinationList2*)Unsafe.AsPointer(ref this));
93+
=> (HRESULT)((delegate* unmanaged[MemberFunction]<IInternalCustomDestinationList*, int>)lpVtbl[12])
94+
((IInternalCustomDestinationList*)Unsafe.AsPointer(ref this));
9695
}
9796

9897
[StructLayout(LayoutKind.Sequential)]

0 commit comments

Comments
 (0)