forked from jinyaoMa/my-app
-
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
19 changed files
with
424 additions
and
116 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
package app | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
instance *Application | ||
) | ||
|
||
type Application struct { | ||
wlc *WailsLifeCycle | ||
} | ||
|
||
func App() *Application { | ||
once.Do(func() { | ||
instance = &Application{ | ||
wlc: &WailsLifeCycle{}, | ||
} | ||
}) | ||
return instance | ||
} | ||
|
||
func (a *Application) WailsLifeCycle() *WailsLifeCycle { | ||
return a.wlc | ||
} |
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,38 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"log" | ||
) | ||
|
||
// Wailsapp Life Cycle | ||
type WailsLifeCycle struct { | ||
ctx context.Context | ||
} | ||
|
||
func (wlc *WailsLifeCycle) Startup(ctx context.Context) { | ||
wlc.ctx = ctx | ||
|
||
log.Println("WAILS START UP") | ||
} | ||
|
||
func (wlc *WailsLifeCycle) DomReady(ctx context.Context) { | ||
log.Println("WAILS DOM READY") | ||
} | ||
|
||
func (wlc *WailsLifeCycle) BeforeClose(ctx context.Context) (prevent bool) { | ||
log.Println("WAILS BEFORE CLOSE") | ||
return false | ||
} | ||
|
||
func (wlc *WailsLifeCycle) Shutdown(ctx context.Context) { | ||
log.Println("WAILS SHUTDOWN") | ||
} | ||
|
||
func (wlc *WailsLifeCycle) Suspend() { | ||
log.Println("WAILS SUSPEND") | ||
} | ||
|
||
func (wlc *WailsLifeCycle) Resume() { | ||
log.Println("WAILS RESUME") | ||
} |
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,48 @@ | ||
package i18n | ||
|
||
import ( | ||
"sync" | ||
|
||
"golang.org/x/exp/slices" | ||
) | ||
|
||
var ( | ||
once sync.Once | ||
instance *i18n | ||
) | ||
|
||
type i18n struct { | ||
localeMap localeMap | ||
availableLanguages []string | ||
currentLocale string | ||
} | ||
|
||
func I18n() *i18n { | ||
once.Do(func() { | ||
localeMap, availableLanguages := load() | ||
|
||
currentLocale := "" | ||
if len(availableLanguages) > 0 { | ||
currentLocale = availableLanguages[0] | ||
} | ||
|
||
instance = &i18n{ | ||
localeMap: localeMap, | ||
availableLanguages: availableLanguages, | ||
currentLocale: currentLocale, | ||
} | ||
}) | ||
return instance | ||
} | ||
|
||
func (i *i18n) Change(lang string) (ok bool) { | ||
if slices.Contains(i.availableLanguages, lang) { | ||
i.currentLocale = lang | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (i *i18n) Locale() (l locale) { | ||
return i.localeMap[i.currentLocale] | ||
} |
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,56 @@ | ||
package i18n | ||
|
||
import ( | ||
"embed" | ||
"encoding/json" | ||
"path/filepath" | ||
) | ||
|
||
//go:embed locales | ||
var locales embed.FS | ||
|
||
const ( | ||
dirLocales = "locales" | ||
) | ||
|
||
type locale struct { | ||
Lang struct { | ||
Code string `json:"code"` | ||
Text string `json:"text"` | ||
} `json:"lang"` | ||
AppName string `json:"appname"` | ||
DisplayLanguage string `json:"display_language"` | ||
ColorTheme struct { | ||
Title string `json:"title"` | ||
Light string `json:"light"` | ||
Dark string `json:"dark"` | ||
} `json:"color_theme"` | ||
ApiService struct { | ||
Start string `json:"start"` | ||
Stop string `json:"stop"` | ||
Swagger string `json:"swagger"` | ||
} `json:"api_service"` | ||
Quit string `json:"quit"` | ||
QuitDialog struct { | ||
Message string `json:"message"` | ||
DefaultButton string `json:"default_button"` | ||
CancelButton string `json:"cancel_button"` | ||
} `json:"quit_dialog"` | ||
} | ||
|
||
type localeMap map[string]locale | ||
|
||
func load() (tm localeMap, availableLanguages []string) { | ||
tm = make(localeMap) | ||
files, _ := locales.ReadDir(dirLocales) | ||
for _, f := range files { | ||
if !f.IsDir() { // load only locale JSON file | ||
t := locale{} | ||
data, _ := locales.ReadFile(filepath.Join(dirLocales, f.Name())) | ||
json.Unmarshal(data, &t) | ||
tm[t.Lang.Code] = t | ||
availableLanguages = append(availableLanguages, t.Lang.Code) | ||
} | ||
} | ||
return | ||
} |
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,24 @@ | ||
{ | ||
"lang": { | ||
"code": "en", | ||
"text": "English" | ||
}, | ||
"appname": "My Application", | ||
"quit": "Quit", | ||
"display_language": "Display Language", | ||
"color_theme": { | ||
"title": "Color Theme", | ||
"light": "Light", | ||
"dark": "Dark" | ||
}, | ||
"api_service": { | ||
"start": "Enable API service", | ||
"stop": "Disable API service", | ||
"swagger": "Open API docs" | ||
}, | ||
"quit_dialog": { | ||
"message": "Are you sure to quit?", | ||
"default_button": "Quit", | ||
"cancel_button": "Cancel" | ||
} | ||
} |
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,24 @@ | ||
{ | ||
"lang": { | ||
"code": "zh", | ||
"text": "简体中文" | ||
}, | ||
"appname": "我的应用程序", | ||
"quit": "退出", | ||
"display_language": "选择 显示语言", | ||
"color_theme": { | ||
"title": "选择 颜色主题", | ||
"light": "默认浅色", | ||
"dark": "默认深色" | ||
}, | ||
"api_service": { | ||
"start": "开启 API 服务", | ||
"stop": "关闭 API 服务", | ||
"swagger": "打开 API 文档" | ||
}, | ||
"quit_dialog": { | ||
"message": "确认退出 我的应用程序 吗?", | ||
"default_button": "退出", | ||
"cancel_button": "取消" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 tray | ||
|
||
import ( | ||
_ "embed" | ||
"sync" | ||
|
||
"github.com/getlantern/systray" | ||
) | ||
|
||
//go:embed icons/icon.ico | ||
var icon []byte | ||
|
||
var ( | ||
once sync.Once | ||
instance *tray | ||
) | ||
|
||
type tray struct { | ||
} | ||
|
||
func Tray() *tray { | ||
once.Do(func() { | ||
instance = &tray{} | ||
systray.Register(instance.onReady, nil) | ||
}) | ||
return instance | ||
} | ||
|
||
func (st *tray) onReady() { | ||
systray.SetTemplateIcon(icon, icon) | ||
systray.SetTitle("Webview example") | ||
} |
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 @@ | ||
package utils |
Oops, something went wrong.