Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
c40aee3
implement MacOS openFile/openFiles events
APshenkin Sep 13, 2023
7342a45
Merge branch 'master' into feature/mac-open-files
APshenkin Sep 13, 2023
4d461c1
wip: windows file association
APshenkin Sep 16, 2023
006c383
fix macro import
APshenkin Sep 16, 2023
77f7a67
add file icon copy
APshenkin Sep 16, 2023
54ea8bb
try copy icon
APshenkin Sep 16, 2023
8e0543a
keep only required part of scripts
APshenkin Sep 16, 2023
48d02bf
update config schema
APshenkin Sep 16, 2023
51d391f
fix json
APshenkin Sep 16, 2023
d5ccecc
Merge branch 'feature/mac-open-files' into feature/open-files
APshenkin Sep 16, 2023
329b9a5
set fileAssociation for mac via config
APshenkin Sep 16, 2023
2670bde
proper iconName handling
APshenkin Sep 16, 2023
82bc909
add fileAssociation icon generator
APshenkin Sep 16, 2023
2a836c8
fix file association icons bundle
APshenkin Sep 16, 2023
3b1c600
don't break compatibility
APshenkin Sep 16, 2023
410746c
Merge branch 'master' into feature/open-files
APshenkin Sep 17, 2023
c56c628
Merge branch 'master' into feature/open-files
APshenkin Sep 21, 2023
8f242ec
remove mimeType as not supported linux for now
APshenkin Sep 21, 2023
a1cba0d
Merge branch 'feature/open-files' of github.com:APshenkin/wails into …
APshenkin Sep 21, 2023
97553de
Merge branch 'master' into feature/open-files
APshenkin Sep 22, 2023
9326562
add documentation
APshenkin Sep 22, 2023
b6c0e94
Merge branch 'feature/open-files' of github.com:APshenkin/wails into …
APshenkin Sep 22, 2023
e695663
adjust config schema
APshenkin Sep 22, 2023
045aa05
restore formatting
APshenkin Sep 22, 2023
ce0554d
try implement single instance lock with params passing
APshenkin Sep 24, 2023
a4d0050
fix focusing
APshenkin Sep 24, 2023
a89cbb1
fix focusing
APshenkin Sep 24, 2023
9b9be20
formatting
APshenkin Sep 24, 2023
967f6d6
use channel buffer for second instance events
APshenkin Sep 24, 2023
4a75912
handle errors
APshenkin Sep 24, 2023
340d969
add comment
APshenkin Sep 24, 2023
a9b12a5
Merge branch 'master' into feature/open-files
leaanthony Sep 25, 2023
ab1e0a9
remove unused option in file association
APshenkin Sep 25, 2023
e1f8be2
Merge branch 'feature/open-files' of github.com:APshenkin/wails into …
APshenkin Sep 25, 2023
d2abb67
Merge branch 'master' into feature/open-files
APshenkin Sep 26, 2023
4e3861a
Merge branch 'master' into feature/open-files
leaanthony Sep 26, 2023
5fb1603
wip: linux single instance lock
APshenkin Sep 26, 2023
a8e41e8
wip: linux single instance
APshenkin Sep 26, 2023
98f7596
some experiments with making window active
APshenkin Sep 26, 2023
575a23e
try to use unminimise
APshenkin Sep 26, 2023
b1a0745
remove unused
APshenkin Sep 26, 2023
dac6dec
try present for window
APshenkin Sep 26, 2023
0d0e88a
try present for window
APshenkin Sep 26, 2023
2966157
fix build
APshenkin Sep 26, 2023
097155b
cleanup
APshenkin Sep 27, 2023
e2089c0
cleanup
APshenkin Sep 27, 2023
9afd27a
implement single instance lock on mac os
APshenkin Sep 28, 2023
5d67e0e
implement proper show for windows
APshenkin Sep 28, 2023
71fa5fa
proper unmimimise
APshenkin Sep 28, 2023
faed07a
get rid of openFiles mac os. change configuration structure
APshenkin Sep 28, 2023
424484e
Merge branch 'feature/open-files' of github.com:APshenkin/wails into …
APshenkin Sep 28, 2023
d7077b9
remove unused channel
APshenkin Sep 28, 2023
785b432
remove unused function
APshenkin Sep 28, 2023
473ce9b
Merge branch 'feature/open-files' into feature/single-lock
APshenkin Sep 28, 2023
8a3fd43
add documentation for single instance lock
APshenkin Sep 28, 2023
954a42a
add PR link
APshenkin Sep 28, 2023
d7f3328
wip mac os deeplinks
APshenkin Sep 28, 2023
bd3395f
put custom url listner on top to catch link on app opening
APshenkin Sep 28, 2023
7cc4b08
put custom url listner on top to catch link on app opening
APshenkin Sep 28, 2023
98dedb5
try add custom url windows
APshenkin Sep 29, 2023
355de4f
adjust custom url
APshenkin Sep 29, 2023
8657dd6
add docs
APshenkin Sep 29, 2023
cbd26b5
Merge branch 'master' into feature/deeplinks
APshenkin Oct 23, 2023
ec15949
merge master
APshenkin Oct 23, 2023
aeef183
update documentation
APshenkin Oct 23, 2023
a6ac4e3
add comment for darwin
APshenkin Oct 23, 2023
825e0a9
add PR link
APshenkin Oct 23, 2023
022ee49
change naming
APshenkin Oct 23, 2023
e6fe53f
change naming
APshenkin Oct 23, 2023
fa3b567
change naming
APshenkin Oct 23, 2023
8365d68
change naming
APshenkin Oct 23, 2023
e6c716b
fix formatting
APshenkin Oct 23, 2023
1a064a2
fix naming
APshenkin Oct 23, 2023
0cb0cfe
Fix typo
APshenkin Oct 23, 2023
3f074fc
Merge branch 'master' into feature/deeplinks
APshenkin Oct 24, 2023
8b63ad5
Merge branch 'master' into feature/deeplinks
APshenkin Oct 30, 2023
205a116
Merge branch 'master' into feature/deeplinks
APshenkin Oct 30, 2023
595e731
Merge branch 'master' into feature/deeplinks
leaanthony Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions v2/internal/frontend/desktop/darwin/CustomProtocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef CustomProtocol_h
#define CustomProtocol_h

#import <Cocoa/Cocoa.h>

extern void HandleCustomProtocol(char*);

@interface CustomProtocolSchemeHandler : NSObject
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
@end

void StartCustomProtocolHandler(void);

#endif /* CustomProtocol_h */
20 changes: 20 additions & 0 deletions v2/internal/frontend/desktop/darwin/CustomProtocol.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "CustomProtocol.h"

@implementation CustomProtocolSchemeHandler
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
[event paramDescriptorForKeyword:keyDirectObject];

NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];

HandleCustomProtocol((char*)[[[event paramDescriptorForKeyword:keyDirectObject] stringValue] UTF8String]);
}
@end

void StartCustomProtocolHandler(void) {
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];

[appleEventManager setEventHandler:[CustomProtocolSchemeHandler class]
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID: kAEGetURL];
}
24 changes: 24 additions & 0 deletions v2/internal/frontend/desktop/darwin/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package darwin
#cgo LDFLAGS: -framework Foundation -framework Cocoa -framework WebKit
#import <Foundation/Foundation.h>
#import "Application.h"
#import "CustomProtocol.h"
#import "WailsContext.h"

#include <stdlib.h>
Expand Down Expand Up @@ -39,6 +40,7 @@ var messageBuffer = make(chan string, 100)
var requestBuffer = make(chan webview.Request, 100)
var callbackBuffer = make(chan uint, 10)
var openFilepathBuffer = make(chan string, 100)
var openUrlBuffer = make(chan string, 100)
var secondInstanceBuffer = make(chan options.SecondInstanceData, 1)

type Frontend struct {
Expand Down Expand Up @@ -79,6 +81,9 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
}
result.startURL, _ = url.Parse(startURL)

// this should be initialized as early as possible to handle first instance launch
C.StartCustomProtocolHandler()

if _starturl, _ := ctx.Value("starturl").(*url.URL); _starturl != nil {
result.startURL = _starturl
} else {
Expand Down Expand Up @@ -110,6 +115,7 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger.
go result.startMessageProcessor()
go result.startCallbackProcessor()
go result.startFileOpenProcessor()
go result.startUrlOpenProcessor()
go result.startSecondInstanceProcessor()

return result
Expand All @@ -121,6 +127,12 @@ func (f *Frontend) startFileOpenProcessor() {
}
}

func (f *Frontend) startUrlOpenProcessor() {
for url := range openUrlBuffer {
f.ProcessOpenUrlEvent(url)
}
}

func (f *Frontend) startSecondInstanceProcessor() {
for secondInstanceData := range secondInstanceBuffer {
if f.frontendOptions.SingleInstanceLock != nil &&
Expand Down Expand Up @@ -385,6 +397,12 @@ func (f *Frontend) ProcessOpenFileEvent(filePath string) {
}
}

func (f *Frontend) ProcessOpenUrlEvent(url string) {
if f.frontendOptions.Mac != nil && f.frontendOptions.Mac.OnUrlOpen != nil {
f.frontendOptions.Mac.OnUrlOpen(url)
}
}

func (f *Frontend) Callback(message string) {
escaped, err := json.Marshal(message)
if err != nil {
Expand Down Expand Up @@ -434,3 +452,9 @@ func HandleOpenFile(filePath *C.char) {
goFilepath := C.GoString(filePath)
openFilepathBuffer <- goFilepath
}

//export HandleCustomProtocol
func HandleCustomProtocol(url *C.char) {
goUrl := C.GoString(url)
openUrlBuffer <- goUrl
}
7 changes: 7 additions & 0 deletions v2/internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type Info struct {
Copyright *string `json:"copyright"`
Comments *string `json:"comments"`
FileAssociations []FileAssociation `json:"fileAssociations"`
Protocols []Protocol `json:"protocols"`
}

type FileAssociation struct {
Expand All @@ -232,6 +233,12 @@ type FileAssociation struct {
Role string `json:"role"`
}

type Protocol struct {
Scheme string `json:"scheme"`
Description string `json:"description"`
Role string `json:"role"`
}

type Bindings struct {
TsGeneration TsGeneration `json:"ts_generation"`
}
Expand Down
17 changes: 17 additions & 0 deletions v2/pkg/buildassets/build/darwin/Info.dev.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@
{{end}}
</array>
{{end}}
{{if .Info.Protocols}}
<key>CFBundleURLTypes</key>
<array>
{{range .Info.Protocols}}
<dict>
<key>CFBundleURLName</key>
<string>com.wails.{{.Scheme}}</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{{.Scheme}}</string>
</array>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
</dict>
{{end}}
</array>
{{end}}
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
Expand Down
17 changes: 17 additions & 0 deletions v2/pkg/buildassets/build/darwin/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,22 @@
{{end}}
</array>
{{end}}
{{if .Info.Protocols}}
<key>CFBundleURLTypes</key>
<array>
{{range .Info.Protocols}}
<dict>
<key>CFBundleURLName</key>
<string>com.wails.{{.Scheme}}</string>
<key>CFBundleURLSchemes</key>
<array>
<string>{{.Scheme}}</string>
</array>
<key>CFBundleTypeRole</key>
<string>{{.Role}}</string>
</dict>
{{end}}
</array>
{{end}}
</dict>
</plist>
2 changes: 2 additions & 0 deletions v2/pkg/buildassets/build/windows/installer/project.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Section
CreateShortCut "$DESKTOP\${INFO_PRODUCTNAME}.lnk" "$INSTDIR\${PRODUCT_EXECUTABLE}"

!insertmacro wails.associateFiles
!insertmacro wails.associateCustomProtocols

!insertmacro wails.writeUninstaller
SectionEnd
Expand All @@ -107,6 +108,7 @@ Section "uninstall"
Delete "$DESKTOP\${INFO_PRODUCTNAME}.lnk"

!insertmacro wails.unassociateFiles
!insertmacro wails.unassociateCustomProtocols

!insertmacro wails.deleteUninstaller
SectionEnd
29 changes: 29 additions & 0 deletions v2/pkg/buildassets/build/windows/installer/wails_tools.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,32 @@ RequestExecutionLevel "${REQUEST_EXECUTION_LEVEL}"
Delete "$INSTDIR\{{.IconName}}.ico"
{{end}}
!macroend

!macro CUSTOM_PROTOCOL_ASSOCIATE PROTOCOL DESCRIPTION ICON COMMAND
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "" "${DESCRIPTION}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}" "URL Protocol" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\DefaultIcon" "" "${ICON}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${PROTOCOL}\shell\open\command" "" "${COMMAND}"
!macroend

!macro CUSTOM_PROTOCOL_UNASSOCIATE PROTOCOL
DeleteRegKey SHELL_CONTEXT "Software\Classes\${PROTOCOL}"
!macroend

!macro wails.associateCustomProtocols
; Create custom protocols associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_ASSOCIATE "{{.Scheme}}" "{{.Description}}" "$INSTDIR\${PRODUCT_EXECUTABLE},0" "$INSTDIR\${PRODUCT_EXECUTABLE} $\"%1$\""

{{end}}
!macroend

!macro wails.unassociateCustomProtocols
; Delete app custom protocol associations
{{range .Info.Protocols}}
!insertmacro CUSTOM_PROTOCOL_UNASSOCIATE "{{.Scheme}}"
{{end}}
!macroend
1 change: 1 addition & 0 deletions v2/pkg/options/mac/mac.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ type Options struct {
//ActivationPolicy ActivationPolicy
About *AboutInfo
OnFileOpen func(filePath string) `json:"-"`
OnUrlOpen func(filePath string) `json:"-"`
//URLHandlers map[string]func(string)
}
Loading