forked from vito-go/mywords
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import "C" | ||
import ( | ||
"mywords/dict" | ||
"mywords/server" | ||
"sync" | ||
"time" | ||
) | ||
|
||
func init() { | ||
// flutter 中的日志是 UTC 时间,所以这里要设置时区 | ||
time.Local = time.FixedZone("CST", 8*3600) | ||
} | ||
|
||
var once sync.Once | ||
|
||
//export Init | ||
func Init(rootDataDir *C.char, proxyUrl *C.char) { | ||
once.Do(func() { | ||
initGlobal(C.GoString(rootDataDir), C.GoString(proxyUrl)) | ||
}) | ||
} | ||
func initGlobal(rootDataDir string, proxyUrl string) { | ||
srv, err := server.NewServer(rootDataDir, proxyUrl) | ||
if err != nil { | ||
panic(err) | ||
} | ||
serverGlobal = srv | ||
multiDictGlobal = dict.NewMultiDictZip(rootDataDir) | ||
go multiDictGlobal.Init() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,22 @@ | ||
//go:build !flutter | ||
|
||
package main | ||
|
||
import "C" | ||
import ( | ||
"fmt" | ||
"mywords/dict" | ||
"mywords/server" | ||
"sync" | ||
"time" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// 可以命令行的方式运行 | ||
func main() { | ||
// must Init when using the exported method in this package | ||
fmt.Println("Hello World from Flutter") | ||
} | ||
|
||
func init() { | ||
// flutter 中的日志是 UTC 时间,所以这里要设置时区 | ||
time.Local = time.FixedZone("CST", 8*3600) | ||
} | ||
|
||
var once sync.Once | ||
|
||
//export Init | ||
func Init(rootDataDir *C.char, proxyUrl *C.char) { | ||
once.Do(func() { | ||
initGlobal(C.GoString(rootDataDir), C.GoString(proxyUrl)) | ||
}) | ||
} | ||
func initGlobal(rootDataDir string, proxyUrl string) { | ||
srv, err := server.NewServer(rootDataDir, proxyUrl) | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
panic(err) | ||
} | ||
initGlobal(filepath.Join(homeDir, ".local/share/com.example.mywords"), "") | ||
err = serverGlobal.ShareOpen(18964, 890604) | ||
if err != nil { | ||
panic(err) | ||
} | ||
serverGlobal = srv | ||
multiDictGlobal = dict.NewMultiDictZip(rootDataDir) | ||
go multiDictGlobal.Init() | ||
select {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build flutter | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
// 编译为so库供flutter使用 | ||
// must Init when using the exported method in this package | ||
fmt.Println("Hello World from Flutter") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters