mirror of
https://git.sr.ht/~eliasnaur/gio-cmd
synced 2026-07-01 07:35:37 +00:00
gogio: add deeplink support
Add a new flag "-schemes" which links the URL schemes to the app. Signed-off-by: inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
@@ -48,6 +48,7 @@ type manifestData struct {
|
||||
Features []string
|
||||
IconSnip string
|
||||
AppName string
|
||||
Schemes []string
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -442,6 +443,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
||||
Features: features,
|
||||
IconSnip: iconSnip,
|
||||
AppName: appName,
|
||||
Schemes: bi.schemes,
|
||||
}
|
||||
tmpl, err := template.New("test").Parse(
|
||||
`<?xml version="1.0" encoding="utf-8"?>
|
||||
@@ -458,11 +460,20 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
|
||||
android:theme="@style/Theme.GioApp"
|
||||
android:configChanges="screenSize|screenLayout|smallestScreenSize|orientation|keyboardHidden"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:launchMode="singleInstance"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
{{range .Schemes}}
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"></action>
|
||||
<category android:name="android.intent.category.DEFAULT"></category>
|
||||
<category android:name="android.intent.category.BROWSABLE"></category>
|
||||
<data android:scheme="{{.}}"></data>
|
||||
</intent-filter>
|
||||
{{end}}
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>`)
|
||||
|
||||
@@ -31,6 +31,7 @@ type buildInfo struct {
|
||||
notaryAppleID string
|
||||
notaryPassword string
|
||||
notaryTeamID string
|
||||
schemes []string
|
||||
}
|
||||
|
||||
type Semver struct {
|
||||
@@ -78,6 +79,7 @@ func newBuildInfo(pkgPath string) (*buildInfo, error) {
|
||||
notaryAppleID: *notaryID,
|
||||
notaryPassword: *notaryPass,
|
||||
notaryTeamID: *notaryTeamID,
|
||||
schemes: getCommaList(*schemes),
|
||||
}
|
||||
return bi, nil
|
||||
}
|
||||
@@ -147,6 +149,15 @@ func getLdFlags(appID string) string {
|
||||
return strings.Join(ldflags, " ")
|
||||
}
|
||||
|
||||
func getCommaList(s string) (list []string) {
|
||||
for _, v := range strings.Split(s, ",") {
|
||||
if v := strings.TrimSpace(v); v != "" {
|
||||
list = append(list, v)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
type packageMetadata struct {
|
||||
PkgPath string
|
||||
Dir string
|
||||
|
||||
@@ -82,4 +82,9 @@ for details. If not provided, the password will be prompted.
|
||||
|
||||
The -notaryteamid flag specifies the team ID to use for notarization of MacOS app, ignored if
|
||||
-notaryid is not provided.
|
||||
|
||||
The -schemes flag specifies a list of comma separated URI schemes that the program can
|
||||
handle. For example, use -schemes yourAppName to receive a app.URLEvent for URIs
|
||||
starting with yourAppName://. It is only supported on Android, iOS, macOS and Windows.
|
||||
On Windows, it will restrict the program to a single instance.
|
||||
`
|
||||
|
||||
+57
-11
@@ -4,6 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -302,36 +304,57 @@ func buildInfoPlist(bi *buildInfo) string {
|
||||
case "tvos":
|
||||
supportPlatform = "AppleTVOS"
|
||||
}
|
||||
return fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
manifestSrc := struct {
|
||||
AppName string
|
||||
AppID string
|
||||
Version string
|
||||
VersionCode uint32
|
||||
Platform string
|
||||
MinVersion int
|
||||
SupportPlatform string
|
||||
Schemes []string
|
||||
}{
|
||||
AppName: appName,
|
||||
AppID: bi.appID,
|
||||
Version: bi.version.String(),
|
||||
VersionCode: bi.version.VersionCode,
|
||||
Platform: platform,
|
||||
MinVersion: minIOSVersion,
|
||||
SupportPlatform: supportPlatform,
|
||||
Schemes: bi.schemes,
|
||||
}
|
||||
|
||||
tmpl, err := template.New("manifest").Parse(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>%s</string>
|
||||
<string>{{.AppName}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>%s</string>
|
||||
<string>{{.AppID}}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>%s</string>
|
||||
<string>{{.AppName}}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>%s</string>
|
||||
<string>{{.Version}}</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>%d</string>
|
||||
<string>{{.VersionCode}}</string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array><string>arm64</string></array>
|
||||
<key>DTPlatformName</key>
|
||||
<string>%s</string>
|
||||
<string>{{.Platform}}</string>
|
||||
<key>DTPlatformVersion</key>
|
||||
<string>12.4</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>%d</string>
|
||||
<string>{{.MinVersion}}</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
@@ -339,7 +362,7 @@ func buildInfoPlist(bi *buildInfo) string {
|
||||
</array>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>%s</string>
|
||||
<string>{{.SupportPlatform}}</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
@@ -354,13 +377,36 @@ func buildInfoPlist(bi *buildInfo) string {
|
||||
<key>DTSDKBuild</key>
|
||||
<string>16G73</string>
|
||||
<key>DTSDKName</key>
|
||||
<string>%s12.4</string>
|
||||
<string>{{.Platform}}12.4</string>
|
||||
<key>DTXcode</key>
|
||||
<string>1030</string>
|
||||
<key>DTXcodeBuild</key>
|
||||
<string>10G8</string>
|
||||
{{if .Schemes}}
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
{{range .Schemes}}
|
||||
<dict>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>{{.}}</string>
|
||||
</array>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
</dict>
|
||||
</plist>`, appName, bi.appID, appName, bi.version, bi.version.VersionCode, platform, minIOSVersion, supportPlatform, platform)
|
||||
</plist>`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var manifestBuffer bytes.Buffer
|
||||
if err := tmpl.Execute(&manifestBuffer, manifestSrc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return manifestBuffer.String()
|
||||
}
|
||||
|
||||
func iosPlatformFor(target string) string {
|
||||
|
||||
+33
-15
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -34,9 +35,7 @@ func buildMac(tmpDir string, bi *buildInfo) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := builder.setInfo(bi, name); err != nil {
|
||||
return fmt.Errorf("can't build the resources: %v", err)
|
||||
}
|
||||
builder.setInfo(bi, name)
|
||||
|
||||
for _, arch := range bi.archs {
|
||||
tmpDest := filepath.Join(builder.TempDir, filepath.Base(builder.DestDir))
|
||||
@@ -122,7 +121,20 @@ func (b *macBuilder) setIcon(path string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *macBuilder) setInfo(buildInfo *buildInfo, name string) error {
|
||||
func (b *macBuilder) setInfo(buildInfo *buildInfo, name string) {
|
||||
|
||||
manifestSrc := struct {
|
||||
Name string
|
||||
Bundle string
|
||||
Version Semver
|
||||
Schemes []string
|
||||
}{
|
||||
Name: name,
|
||||
Bundle: buildInfo.appID,
|
||||
Version: buildInfo.version,
|
||||
Schemes: buildInfo.schemes,
|
||||
}
|
||||
|
||||
t, err := template.New("manifest").Parse(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
@@ -137,20 +149,28 @@ func (b *macBuilder) setInfo(buildInfo *buildInfo, name string) error {
|
||||
<true/>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
{{if .Schemes}}
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
{{range .Schemes}}
|
||||
<dict>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>{{.}}</string>
|
||||
</array>
|
||||
</dict>
|
||||
{{end}}
|
||||
</array>
|
||||
{{end}}
|
||||
</dict>
|
||||
</plist>`)
|
||||
if err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var manifest bufferCoff
|
||||
if err := t.Execute(&manifest, struct {
|
||||
Name, Bundle string
|
||||
}{
|
||||
Name: name,
|
||||
Bundle: buildInfo.appID,
|
||||
}); err != nil {
|
||||
return err
|
||||
var manifest bytes.Buffer
|
||||
if err := t.Execute(&manifest, manifestSrc); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
b.Manifest = manifest.Bytes()
|
||||
|
||||
@@ -164,8 +184,6 @@ func (b *macBuilder) setInfo(buildInfo *buildInfo, name string) error {
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *macBuilder) buildProgram(buildInfo *buildInfo, binDest string, name string, arch string) error {
|
||||
|
||||
@@ -41,6 +41,7 @@ var (
|
||||
notaryID = flag.String("notaryid", "", "specify the apple id to use for notarization.")
|
||||
notaryPass = flag.String("notarypass", "", "specify app-specific password of the Apple ID to be used for notarization.")
|
||||
notaryTeamID = flag.String("notaryteamid", "", "specify the team id to use for notarization.")
|
||||
schemes = flag.String("schemes", "", "specify a list of comma separated URL schemes that the program accepts")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -202,10 +202,18 @@ func (b *windowsBuilder) buildProgram(buildInfo *buildInfo, name string, arch st
|
||||
dest = filepath.Join(filepath.Dir(b.DestDir), name+"_"+arch+".exe")
|
||||
}
|
||||
|
||||
ldflags := buildInfo.ldflags
|
||||
if buildInfo.schemes != nil {
|
||||
ldflags += ` -X "gioui.org/app.schemesURI=` + strings.Join(buildInfo.schemes, ",") + `" `
|
||||
}
|
||||
if buildInfo.appID != "" {
|
||||
ldflags += ` -X "gioui.org/app.ID=` + buildInfo.appID + `" `
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
"go",
|
||||
"build",
|
||||
"-ldflags=-H=windowsgui "+buildInfo.ldflags,
|
||||
"-ldflags=-H=windowsgui "+ldflags,
|
||||
"-tags="+buildInfo.tags,
|
||||
"-o", dest,
|
||||
buildInfo.pkgPath,
|
||||
|
||||
Reference in New Issue
Block a user