Skip to content

Commit 88f0959

Browse files
committed
Fix init sequence bug for embedded assets
1 parent edcb4ab commit 88f0959

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

cmd/build.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/go-flutter-desktop/hover/internal/androidmanifest"
65
"os"
76
"os/exec"
87
"path/filepath"
98
"runtime"
109
"strings"
1110

11+
"github.com/go-flutter-desktop/hover/internal/androidmanifest"
12+
1213
"github.com/hashicorp/go-version"
1314
"github.com/otiai10/copy"
1415
"github.com/spf13/cobra"
@@ -223,7 +224,7 @@ func assertTargetFileExists(targetFilename string) {
223224
if targetFilename == config.BuildTargetDefault {
224225
log.Warnf("Let hover add the \"lib/main_desktop.dart\" file? ")
225226
if askForConfirmation() {
226-
fileutils.CopyAsset("app/main_desktop.dart", filepath.Join("lib", "main_desktop.dart"), fileutils.AssetsBox)
227+
fileutils.CopyAsset("app/main_desktop.dart", filepath.Join("lib", "main_desktop.dart"), fileutils.AssetsBox())
227228
log.Infof("Target file \"lib/main_desktop.dart\" has been created.")
228229
log.Infof(" Depending on your project, you might want to tweak it.")
229230
return

cmd/init-plugin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ var createPluginCmd = &cobra.Command{
4848
"urlVSCRepo": vcsPath,
4949
}
5050

51-
fileutils.ExecuteTemplateFromAssetsBox("plugin/plugin.go.tmpl", filepath.Join(build.BuildPath, "plugin.go"), fileutils.AssetsBox, templateData)
52-
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.tmpl", filepath.Join(build.BuildPath, "README.md"), fileutils.AssetsBox, templateData)
53-
fileutils.ExecuteTemplateFromAssetsBox("plugin/import.go.tmpl.tmpl", filepath.Join(build.BuildPath, "import.go.tmpl"), fileutils.AssetsBox, templateData)
51+
fileutils.ExecuteTemplateFromAssetsBox("plugin/plugin.go.tmpl", filepath.Join(build.BuildPath, "plugin.go"), fileutils.AssetsBox(), templateData)
52+
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.tmpl", filepath.Join(build.BuildPath, "README.md"), fileutils.AssetsBox(), templateData)
53+
fileutils.ExecuteTemplateFromAssetsBox("plugin/import.go.tmpl.tmpl", filepath.Join(build.BuildPath, "import.go.tmpl"), fileutils.AssetsBox(), templateData)
5454

5555
dlibPath := filepath.Join(build.BuildPath, "dlib")
5656
err = os.Mkdir(dlibPath, 0775)
5757
if err != nil {
5858
log.Errorf("Failed to create '%s' directory: %v", dlibPath, err)
5959
os.Exit(1)
6060
}
61-
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.dlib.tmpl", filepath.Join(dlibPath, "README.md"), fileutils.AssetsBox, templateData)
61+
fileutils.ExecuteTemplateFromAssetsBox("plugin/README.md.dlib.tmpl", filepath.Join(dlibPath, "README.md"), fileutils.AssetsBox(), templateData)
6262

6363
platforms := []string{"darwin", "linux", "windows"}
6464
for _, platform := range platforms {

cmd/init.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ var initCmd = &cobra.Command{
6060
os.Exit(1)
6161
}
6262

63-
fileutils.CopyAsset("app/main.go", filepath.Join(desktopCmdPath, "main.go"), fileutils.AssetsBox)
64-
fileutils.CopyAsset("app/options.go", filepath.Join(desktopCmdPath, "options.go"), fileutils.AssetsBox)
65-
fileutils.CopyAsset("app/icon.png", filepath.Join(desktopAssetsPath, "icon.png"), fileutils.AssetsBox)
66-
fileutils.CopyAsset("app/gitignore", filepath.Join(build.BuildPath, ".gitignore"), fileutils.AssetsBox)
67-
fileutils.CopyAsset("app/hover.yaml", filepath.Join(build.BuildPath, "hover.yaml"), fileutils.AssetsBox)
63+
fileutils.CopyAsset("app/main.go", filepath.Join(desktopCmdPath, "main.go"), fileutils.AssetsBox())
64+
fileutils.CopyAsset("app/options.go", filepath.Join(desktopCmdPath, "options.go"), fileutils.AssetsBox())
65+
fileutils.CopyAsset("app/icon.png", filepath.Join(desktopAssetsPath, "icon.png"), fileutils.AssetsBox())
66+
fileutils.CopyAsset("app/gitignore", filepath.Join(build.BuildPath, ".gitignore"), fileutils.AssetsBox())
67+
fileutils.CopyAsset("app/hover.yaml", filepath.Join(build.BuildPath, "hover.yaml"), fileutils.AssetsBox())
6868

6969
initializeGoModule(projectPath)
7070
log.Printf("Available plugin for this project:")

cmd/packaging/packaging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (t *packagingTask) init(ignoreAlreadyExists bool) {
154154
log.Errorf("Failed to create directory %s: %v", filepath.Dir(destinationFile), err)
155155
os.Exit(1)
156156
}
157-
fileutils.ExecuteTemplateFromAssetsBox(fmt.Sprintf("packaging/%s", sourceFile), destinationFile, fileutils.AssetsBox, templateData)
157+
fileutils.ExecuteTemplateFromAssetsBox(fmt.Sprintf("packaging/%s", sourceFile), destinationFile, fileutils.AssetsBox(), templateData)
158158
}
159159
log.Infof("go/packaging/%s has been created. You can modify the configuration files and add it to git.", t.packagingFormatName)
160160
log.Infof(fmt.Sprintf("You now can package the %s using `%s`", strings.Split(t.packagingFormatName, "-")[0], log.Au().Magenta("hover build "+t.packagingFormatName)))

internal/fileutils/assets.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ package fileutils
33

44
import (
55
"os"
6+
"sync"
67

78
rice "github.com/GeertJohan/go.rice"
89
"github.com/go-flutter-desktop/hover/internal/log"
910
)
1011

11-
// AssetsBox hover's assets box
12-
var AssetsBox *rice.Box
12+
var (
13+
assetsBox *rice.Box
14+
assetsBoxOnce sync.Once
15+
)
1316

14-
func init() {
15-
var err error
16-
AssetsBox, err = rice.FindBox("../../assets")
17-
if err != nil {
18-
log.Errorf("Failed to find hover assets: %v", err)
19-
os.Exit(1)
20-
}
17+
// AssetsBox hover's assets box
18+
func AssetsBox() *rice.Box {
19+
assetsBoxOnce.Do(func() {
20+
var err error
21+
assetsBox, err = rice.FindBox("../../assets")
22+
if err != nil {
23+
log.Errorf("Failed to find hover assets: %v", err)
24+
os.Exit(1)
25+
}
26+
})
27+
return assetsBox
2128
}

0 commit comments

Comments
 (0)