Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyosi committed Jun 9, 2024
1 parent f1c1ece commit dabffc3
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ debug.log
tags*
moc*
editor/version.txt
editor/objcbridge.h
editor/objcbridge.m
cmd/goneovim/goneovim
cmd/goneovim/debug
cmd/goneovim/deploy/*
Expand Down
13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ endif

app: ## Build goneovim
@test -f ./editor/moc.go & $(GOQTMOC) desktop ./cmd/goneovim && \
go generate
ifneq ($(OSNAME),Darwin)
@rm -fr editor/objcbridge*
endif
@$(GOQTDEPLOY) build desktop ./cmd/goneovim && \
go generate && \
$(GOQTDEPLOY) build desktop ./cmd/goneovim && \
cp -pR runtime $(RUNTIME_DIR)
ifeq ($(OSNAME),Darwin)
@/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $(VERSION_HASH)" "./cmd/goneovim/deploy/darwin/goneovim.app/Contents/Info.plist" && \
Expand Down Expand Up @@ -78,11 +75,7 @@ deps: ## Get dependent libraries.
@$(GOQTMOC) desktop ./cmd/goneovim

test: ## Test goneovim
@go generate
ifneq ($(OSNAME),Darwin)
@rm -fr editor/objcbridge*
endif
@go test ./editor
@go generate && go test ./editor

clean: ## Delete pre-built application binaries and Moc files.
@rm -fr cmd/goneovim/deploy/*
Expand Down
2 changes: 1 addition & 1 deletion editor/objcbridge.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
void SetMyApplicationDelegate();
void SetMyApplicationDelegate();
2 changes: 1 addition & 1 deletion editor/objcbridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ void SetMyApplicationDelegate() {
NSApplication *app = [NSApplication sharedApplication];
app.delegate = [[MyApplicationDelegate alloc] init];
[app activateIgnoringOtherApps:YES]; // make application foreground
}
}
73 changes: 73 additions & 0 deletions generate_objcbridge_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//go:build generate

package main

import (
"fmt"
"os"
"path/filepath"
"runtime"
"text/template"
)

const objcbridgeH = `void SetMyApplicationDelegate();`

const objcbridgeM = `#import <Cocoa/Cocoa.h>
char *cFilename;
// Forward declaration of the Go function to be called from C
extern void GetOpeningFilepath(char* str);
@interface MyApplicationDelegate : NSObject <NSApplicationDelegate>
@end
@implementation MyApplicationDelegate
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
return YES;
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename {
char *utf8String = [filename UTF8String];
cFilename = strdup(utf8String);
GetOpeningFilepath(cFilename);
return YES;
}
@end
void SetMyApplicationDelegate() {
NSApplication *app = [NSApplication sharedApplication];
app.delegate = [[MyApplicationDelegate alloc] init];
[app activateIgnoringOtherApps:YES]; // make application foreground
}`

func main() {
if runtime.GOOS != "darwin" {
return
}

generateFile(filepath.Join("editor", "objcbridge.h"), objcbridgeH)
generateFile(filepath.Join("editor", "objcbridge.m"), objcbridgeM)
}

func generateFile(filename, content string) {
file, err := os.Create(filename)
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()

tmpl, err := template.New("file").Parse(content)
if err != nil {
fmt.Println("Error parsing template:", err)
return
}

err = tmpl.Execute(file, nil)
if err != nil {
fmt.Println("Error executing template:", err)
}
}
1 change: 1 addition & 0 deletions goneovim.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package goneovim

//go:generate sh -c "printf %s $(git describe --tags) > editor/version.txt"
//go:generate go run generate_objcbridge_darwin.go

0 comments on commit dabffc3

Please sign in to comment.