mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 22:55:48 +01:00
Perfect! I've successfully refactored the code to have a common jumplist.go file with all the shared structs and methods. This eliminates code duplication across platforms. Here's what the refactoring accomplished:
## Summary of Refactoring ### 1. **Common File** (`jumplist.go`) - Contains all shared structs: `JumpListItemType`, `JumpListItem`, `JumpListCategory`, and `JumpList` - Implements common methods: `AddCategory()`, `ClearCategories()`, and `Apply()` - The `Apply()` method calls the platform-specific `applyPlatform()` method ### 2. **Platform-Specific Files** - **Windows** (`jumplist_windows.go`): Contains only Windows-specific implementation - COM interface definitions and implementations - `CreateJumpList()` method for windowsApp - `applyPlatform()` method with the actual Windows jumplist logic - **macOS** (`jumplist_darwin.go`): Minimal stub implementation - `CreateJumpList()` method for darwinApp - `applyPlatform()` method that returns nil (no-op) - **Linux** (`jumplist_linux.go`): Minimal stub implementation - `CreateJumpList()` method for linuxApp - `applyPlatform()` method that returns nil (no-op) ### Benefits - **No code duplication**: All common structs and logic are in one place - **Cleaner platform files**: Platform-specific files only contain platform-specific code - **Easier maintenance**: Changes to the API only need to be made in one place - **Type safety**: The common interface ensures all platforms implement the required methods The API remains exactly the same for users, but the implementation is now much cleaner and more maintainable.
This commit is contained in:
parent
6d4900a832
commit
dd67cbefeb
4 changed files with 64 additions and 112 deletions
55
v3/pkg/application/jumplist.go
Normal file
55
v3/pkg/application/jumplist.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package application
|
||||
|
||||
// JumpListItemType represents the type of jump list item
|
||||
type JumpListItemType int
|
||||
|
||||
const (
|
||||
// JumpListItemTypeTask represents a task item
|
||||
JumpListItemTypeTask JumpListItemType = iota
|
||||
// JumpListItemTypeSeparator represents a separator (Windows only)
|
||||
JumpListItemTypeSeparator
|
||||
)
|
||||
|
||||
// JumpListItem represents a single item in a jump list
|
||||
type JumpListItem struct {
|
||||
Type JumpListItemType
|
||||
Title string
|
||||
Description string
|
||||
FilePath string
|
||||
Arguments string
|
||||
IconPath string
|
||||
IconIndex int
|
||||
}
|
||||
|
||||
// JumpListCategory represents a category of items in a jump list
|
||||
type JumpListCategory struct {
|
||||
Name string
|
||||
Items []JumpListItem
|
||||
}
|
||||
|
||||
// JumpList provides an interface for managing application jump lists.
|
||||
// This is primarily a Windows feature, but the API is designed to be
|
||||
// cross-platform safe (no-op on non-Windows platforms).
|
||||
type JumpList struct {
|
||||
app platformApp
|
||||
categories []JumpListCategory
|
||||
}
|
||||
|
||||
// AddCategory adds a category to the jump list.
|
||||
// If the category name is empty, the items will be added as tasks.
|
||||
func (j *JumpList) AddCategory(category JumpListCategory) {
|
||||
j.categories = append(j.categories, category)
|
||||
}
|
||||
|
||||
// ClearCategories removes all categories from the jump list.
|
||||
func (j *JumpList) ClearCategories() {
|
||||
j.categories = []JumpListCategory{}
|
||||
}
|
||||
|
||||
// Apply applies the current jump list configuration.
|
||||
// On Windows, this updates the taskbar jump list.
|
||||
// On other platforms, this is a no-op.
|
||||
func (j *JumpList) Apply() error {
|
||||
// Platform-specific implementation
|
||||
return j.applyPlatform()
|
||||
}
|
||||
|
|
@ -2,33 +2,6 @@
|
|||
|
||||
package application
|
||||
|
||||
type JumpListItemType int
|
||||
|
||||
const (
|
||||
JumpListItemTypeTask JumpListItemType = iota
|
||||
JumpListItemTypeSeparator
|
||||
)
|
||||
|
||||
type JumpListItem struct {
|
||||
Type JumpListItemType
|
||||
Title string
|
||||
Description string
|
||||
FilePath string
|
||||
Arguments string
|
||||
IconPath string
|
||||
IconIndex int
|
||||
}
|
||||
|
||||
type JumpListCategory struct {
|
||||
Name string
|
||||
Items []JumpListItem
|
||||
}
|
||||
|
||||
type JumpList struct {
|
||||
app *darwinApp
|
||||
categories []JumpListCategory
|
||||
}
|
||||
|
||||
func (app *darwinApp) CreateJumpList() *JumpList {
|
||||
return &JumpList{
|
||||
app: app,
|
||||
|
|
@ -36,17 +9,7 @@ func (app *darwinApp) CreateJumpList() *JumpList {
|
|||
}
|
||||
}
|
||||
|
||||
func (j *JumpList) AddCategory(category JumpListCategory) {
|
||||
// Stub implementation for macOS
|
||||
j.categories = append(j.categories, category)
|
||||
}
|
||||
|
||||
func (j *JumpList) ClearCategories() {
|
||||
// Stub implementation for macOS
|
||||
j.categories = []JumpListCategory{}
|
||||
}
|
||||
|
||||
func (j *JumpList) Apply() error {
|
||||
func (j *JumpList) applyPlatform() error {
|
||||
// Stub implementation for macOS
|
||||
// Jump lists are Windows-specific, so this is a no-op on macOS
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -2,33 +2,6 @@
|
|||
|
||||
package application
|
||||
|
||||
type JumpListItemType int
|
||||
|
||||
const (
|
||||
JumpListItemTypeTask JumpListItemType = iota
|
||||
JumpListItemTypeSeparator
|
||||
)
|
||||
|
||||
type JumpListItem struct {
|
||||
Type JumpListItemType
|
||||
Title string
|
||||
Description string
|
||||
FilePath string
|
||||
Arguments string
|
||||
IconPath string
|
||||
IconIndex int
|
||||
}
|
||||
|
||||
type JumpListCategory struct {
|
||||
Name string
|
||||
Items []JumpListItem
|
||||
}
|
||||
|
||||
type JumpList struct {
|
||||
app *linuxApp
|
||||
categories []JumpListCategory
|
||||
}
|
||||
|
||||
func (app *linuxApp) CreateJumpList() *JumpList {
|
||||
return &JumpList{
|
||||
app: app,
|
||||
|
|
@ -36,17 +9,7 @@ func (app *linuxApp) CreateJumpList() *JumpList {
|
|||
}
|
||||
}
|
||||
|
||||
func (j *JumpList) AddCategory(category JumpListCategory) {
|
||||
// Stub implementation for Linux
|
||||
j.categories = append(j.categories, category)
|
||||
}
|
||||
|
||||
func (j *JumpList) ClearCategories() {
|
||||
// Stub implementation for Linux
|
||||
j.categories = []JumpListCategory{}
|
||||
}
|
||||
|
||||
func (j *JumpList) Apply() error {
|
||||
func (j *JumpList) applyPlatform() error {
|
||||
// Stub implementation for Linux
|
||||
// Jump lists are Windows-specific, so this is a no-op on Linux
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -9,33 +9,6 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
type JumpListItemType int
|
||||
|
||||
const (
|
||||
JumpListItemTypeTask JumpListItemType = iota
|
||||
JumpListItemTypeSeparator
|
||||
)
|
||||
|
||||
type JumpListItem struct {
|
||||
Type JumpListItemType
|
||||
Title string
|
||||
Description string
|
||||
FilePath string
|
||||
Arguments string
|
||||
IconPath string
|
||||
IconIndex int
|
||||
}
|
||||
|
||||
type JumpListCategory struct {
|
||||
Name string
|
||||
Items []JumpListItem
|
||||
}
|
||||
|
||||
type JumpList struct {
|
||||
app *windowsApp
|
||||
categories []JumpListCategory
|
||||
}
|
||||
|
||||
var (
|
||||
modole32 = syscall.NewLazyDLL("ole32.dll")
|
||||
modshell32 = syscall.NewLazyDLL("shell32.dll")
|
||||
|
|
@ -169,15 +142,13 @@ func (app *windowsApp) CreateJumpList() *JumpList {
|
|||
}
|
||||
}
|
||||
|
||||
func (j *JumpList) AddCategory(category JumpListCategory) {
|
||||
j.categories = append(j.categories, category)
|
||||
}
|
||||
func (j *JumpList) applyPlatform() error {
|
||||
// Type assert to get the windowsApp
|
||||
app, ok := j.app.(*windowsApp)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid app type for Windows jumplist")
|
||||
}
|
||||
|
||||
func (j *JumpList) ClearCategories() {
|
||||
j.categories = []JumpListCategory{}
|
||||
}
|
||||
|
||||
func (j *JumpList) Apply() error {
|
||||
hr := w32.CoInitializeEx(0, w32.COINIT_APARTMENTTHREADED)
|
||||
if hr != w32.S_OK && hr != w32.S_FALSE {
|
||||
return fmt.Errorf("CoInitializeEx failed: %v", hr)
|
||||
|
|
@ -197,7 +168,7 @@ func (j *JumpList) Apply() error {
|
|||
}
|
||||
defer pDestList.Release()
|
||||
|
||||
appID := w32.MustStringToUTF16Ptr(j.app.parent.options.Name)
|
||||
appID := w32.MustStringToUTF16Ptr(app.parent.options.Name)
|
||||
|
||||
hr = pDestList.SetAppID(appID)
|
||||
if hr != w32.S_OK {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue