Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

custom resource path #6

Merged
merged 8 commits into from
Mar 20, 2018
Merged

custom resource path #6

merged 8 commits into from
Mar 20, 2018

Conversation

ZEROKISEKI
Copy link
Contributor

I'm use the go-astilectron-demo firstly. It use "resources" structure, like the code in main.go.

resources structure:


resources/
       |-app/
             |- index.html
             |-static
       |-icon.png
       |-...

main.go:


if err := bootstrap.Run(bootstrap.Options{
	Asset: Asset,
	AstilectronOptions: astilectron.Options{
		AppName:            AppName,
		AppIconDarwinPath:  "resources/icon.icns",
		AppIconDefaultPath: "resources/icon.png",
	},
	Debug:    *debug,
	Homepage: "index.html",       // this refers to resources/app/index.html in bootstrap, see bootstrap run.go:72
        .....

Yet in go-astilectron-bundler provide a way that change resources path in bundler.go:


// Resources path
if b.pathResources, err = absPath(c.ResourcesPath, func() (string, error) { return filepath.Join(b.pathInput, "resources"), nil }); err != nil {
	return
}

It can customly config resources_path in bundler.json to set the resources path, such as:

      
 resources_path: "xxxproject/dist"            // I think that nowadays many one use vue or react in production will generate like this structure instead of "resources" structure above.

However in go-astilectron-bootstrap is use stable path in homepage and restoreAssets in run.go:


// Restore resources
if o.RestoreAssets != nil {
	var rp = filepath.Join(a.Paths().BaseDirectory(), "resources")
	if _, err = os.Stat(rp); os.IsNotExist(err) {
		astilog.Debugf("Restoring resources in %s", rp)
		if err = o.RestoreAssets(a.Paths().BaseDirectory(), "resources"); err != nil {
			err = errors.Wrapf(err, "restoring resources in %s failed", rp)
			return
		}
	} else if err != nil {
		err = errors.Wrapf(err, "stating %s failed", rp)
		return
	} else {
		astilog.Debugf("%s already exists, skipping restoring resources...", rp)
	}
}

// Start
if err = a.Start(); err != nil {
	return errors.Wrap(err, "starting astilectron failed")
}

// Init window
var w *astilectron.Window
if w, err = a.NewWindow(filepath.Join(a.Paths().BaseDirectory(), "resources", "app", o.Homepage), o.WindowOptions); err != nil {
	return errors.Wrap(err, "new window failed")
}

I add HomeResources attr to help set the customly path setting in bootstrap.
I think if you merge this PR, It may have some changes with go-astilectron-demo

@asticode asticode self-assigned this Mar 20, 2018
Copy link
Owner

@asticode asticode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR sounds good, just a few minor changes though.

Cheers

options.go Outdated
@@ -9,6 +9,7 @@ type Options struct {
Asset Asset
AstilectronOptions astilectron.Options
Debug bool
HomeResource string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather you name the variable ResourcesPath

run.go Outdated
@@ -45,12 +45,17 @@ func Run(o Options) (err error) {
a.SetProvisioner(astibundler.NewProvisioner(o.Asset))
}

var homeResource string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, could you name the variable resourcesPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@asticode asticode merged commit 8bcccbf into asticode:master Mar 20, 2018
@asticode
Copy link
Owner

Cheers

asticode pushed a commit that referenced this pull request Mar 26, 2018
* add HomeDirectory setting

* add HomeResources path setting

* remove unused package

* add custom resources path

* modify attrName HomeResources to ResourcesPath

* format tab

* modify attrName to resourcesPath
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants