feat(原生桌面): 统一桌面双横线参数
build.yaml / build (push) Successful in 44s

This commit is contained in:
xiaoqidun committed 2026-10-25 16:20:27 +08:00
1 parent 19aa5523f8
commit 3ef0e36026
3 files changed
+63 -8

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
// Copyright 2025-2026 肖其顿 (XIAO QI DUN)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build (windows && amd64) || (linux && (amd64 || arm64))
package main
import (
"os"
"strings"
)
// commandLine 读取桌面参数并处理参数错误
// 返回: []string 文件路径, string 浏览器数据目录
func commandLine() ([]string, string) {
paths, dataDir, ok := parseArguments(os.Args[1:])
if !ok {
os.Exit(2)
}
return paths, dataDir
}
// parseArguments 解析双横线选项及后续文件路径
// 入参: args 启动参数
// 返回: []string 文件路径, string 浏览器数据目录, bool 参数是否有效
func parseArguments(args []string) ([]string, string, bool) {
var dataDir string
for len(args) > 0 {
arg := args[0]
args = args[1:]
switch {
case arg == "--":
return args, dataDir, true
case arg == "--data-dir":
if len(args) == 0 {
return nil, dataDir, false
}
dataDir, args = args[0], args[1:]
case strings.HasPrefix(arg, "--data-dir="):
dataDir = strings.TrimPrefix(arg, "--data-dir=")
case strings.HasPrefix(arg, "-"):
return nil, dataDir, false
default:
return append([]string{arg}, args...), dataDir, true
}
}
return nil, dataDir, true
}
+2 -4
View File
@@ -18,7 +18,6 @@ package main
import (
"context"
"flag"
"fmt"
"os"
@@ -26,9 +25,8 @@ import (
)
func main() {
dataDir := flag.String("data-dir", "", "browser data directory")
flag.Parse()
if err := webview.Run(context.Background(), flag.Args(), *dataDir); err != nil {
paths, dataDir := commandLine()
if err := webview.Run(context.Background(), paths, dataDir); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
+2 -4
View File
@@ -18,7 +18,6 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"syscall"
@@ -28,9 +27,8 @@ import (
)
func main() {
dataDir := flag.String("data-dir", "", "browser data directory")
flag.Parse()
if err := webview.Run(context.Background(), flag.Args(), *dataDir); err != nil {
paths, dataDir := commandLine()
if err := webview.Run(context.Background(), paths, dataDir); err != nil {
fmt.Fprintln(os.Stderr, err)
message, _ := syscall.UTF16PtrFromString(err.Error())
title, _ := syscall.UTF16PtrFromString("OFDGo")