Skip to content

Commit

Permalink
feat: rolling release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayideyia committed Jul 2, 2024
1 parent dac3701 commit 7b6d552
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bridge/tray_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func InitTray(a *App, icon []byte, fs embed.FS) {
systray.SetTooltip("GUI.for.Cores")
systray.SetOnClick(func(menu systray.IMenu) { runtime.WindowShow(a.Ctx) })
systray.SetOnRClick(func(menu systray.IMenu) { menu.ShowMenu() })

// Ensure the tray is still available if rolling-release fails
mRestart := systray.AddMenuItem("Restart", "Restart")
mExit := systray.AddMenuItem("Exit", "Exit")
mRestart.Click(func() { a.RestartApp() })
mExit.Click(func() { a.ExitApp() })
}, nil)
}()
}
Expand Down
1 change: 1 addition & 0 deletions bridge/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type AppConfig struct {
Width int `yaml:"width"`
Height int `yaml:"height"`
MultipleInstance bool `yaml:"multipleInstance"`
RollingRelease bool `yaml:"rollingRelease"`
StartHidden bool
}

Expand Down
46 changes: 46 additions & 0 deletions bridge/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package bridge

import (
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -54,3 +57,46 @@ func ConvertByte2String(byte []byte) string {
decodeBytes, _ := simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
return string(decodeBytes)
}

func RollingRelease(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !Config.RollingRelease {
next.ServeHTTP(w, r)
return
}

url := r.URL.Path
if url == "/" {
url = "/index.html"
}

log.Printf("[Rolling Release] %v %v\n", r.Method, url)

file := GetPath("data/rolling-release" + url)

bytes, err := os.ReadFile(file)
if err != nil {
next.ServeHTTP(w, r)
return
}

ext := path.Ext(url)
mime := "application/octet-stream"

switch ext {
case ".html":
mime = "text/html"
case ".ico":
mime = "image/x-icon"
case ".png":
mime = "image/png"
case ".css":
mime = "text/css"
case ".js":
mime = "text/javascript"
}

w.Header().Set("Content-Type", mime)
w.Write(bytes)
})
}
2 changes: 1 addition & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_APP_TITLE = GUI.for.SingBox
VITE_APP_VERSION = v1.8.0
VITE_APP_VERSION = v1.8.1
VITE_APP_PROJECT_URL = https://github.com/GUI-for-Cores/GUI.for.SingBox
VITE_APP_VERSION_API = https://api.github.com/repos/GUI-for-Cores/GUI.for.SingBox/releases/latest
VITE_APP_TG_GROUP = https://t.me/GUI_for_Cores
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export default {
admin: 'Run As Admin',
addToMenu: 'Add Plugin To Menu',
multipleInstance: 'Allow Multiple Instances',
rollingRelease: 'Enable Rolling Release',
startup: {
name: 'Startup on boot',
delay: 'Delay(s)'
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export default {
admin: '以管理员身份运行',
addToMenu: '将插件添加到托盘菜单',
multipleInstance: '允许多个实例',
rollingRelease: '启用滚动发行',
startup: {
name: '开机时启动',
delay: '延迟(秒)'
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/stores/appSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type AppSettings = {
githubApiToken: string
multipleInstance: boolean
addPluginToMenu: boolean
rollingRelease: boolean
}

export const useAppSettingsStore = defineStore('app-settings', () => {
Expand Down Expand Up @@ -120,7 +121,8 @@ export const useAppSettingsStore = defineStore('app-settings', () => {
pluginSettings: {},
githubApiToken: '',
multipleInstance: false,
addPluginToMenu: false
addPluginToMenu: false,
rollingRelease: false
})

const saveAppSettings = debounce((config: string) => {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/views/SettingsView/components/GeneralSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ if (envStore.env.os === 'windows') {
</div>
<Switch v-model="appSettings.app.multipleInstance" />
</div>
<div class="settings-item">
<div class="title">
{{ t('settings.rollingRelease') }}
<span class="tips">({{ t('settings.needRestart') }})</span>
</div>
<Switch v-model="appSettings.app.rollingRelease" />
</div>
<div class="settings-item">
<div class="title">{{ t('settings.userAgent.name') }}</div>
<div style="display: flex; align-items: center">
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func main() {
WindowIsTranslucent: false,
},
AssetServer: &assetserver.Options{
Assets: assets,
Assets: assets,
Middleware: bridge.RollingRelease,
},
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: func() string {
Expand Down

0 comments on commit 7b6d552

Please sign in to comment.