forked from TurboHsu/Vocab-Master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_darwin.go
62 lines (50 loc) · 1.23 KB
/
platform_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"os"
"os/exec"
"path/filepath"
)
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#include <Foundation/Foundation.h>
const char* nsstring2cstring(NSString *s) {
if (s == NULL) { return NULL; }
const char *cstr = [s UTF8String];
return cstr;
}
NSString* getFontPath() {
NSBundle *main = [NSBundle mainBundle];
return [main pathForResource:@"font" ofType:@"ttf"];
}
*/
import "C"
func CString(s *C.NSString) *C.char {
return C.nsstring2cstring(s)
}
func GoString(p *C.NSString) string {
return C.GoString(CString(p))
}
func GetPlatform() (Platform, error) {
fontPath := GoString(C.getFontPath())
homeDir, err := os.UserHomeDir()
if err != nil {
return Platform{}, err
}
dataDir := filepath.Join(homeDir, "Library", "Application Support", "VocabMaster")
err = os.MkdirAll(dataDir, os.ModePerm)
if err != nil {
return Platform{}, err
}
//to get cocoa resources dir, where the font is located,
//a window is required, even if it's not shown
return Platform{
DataDir: dataDir,
CertDir: filepath.Join(dataDir, "cert"),
Font: fontPath,
}, nil
}
func (receiver Platform) OpenCertDir() {
cmd := exec.Command("/bin/bash", "-c", "open \""+receiver.CertDir+"\"")
cmd.Start()
}