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

Fix for issue #190 #191

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

shrey-gang
Copy link

#190
Partnering pull request can be found here: asticode/astilectron#20

@coveralls
Copy link

coveralls commented Jun 25, 2019

Coverage Status

Coverage remained the same at ?% when pulling 54792fd on shrey-gang:unixDomainSocket into 12a267a on asticode:master.

@shrey-gang
Copy link
Author

@asticode
I tried running the coverage test it doesn't fail but yes code coverage is 79% which is low.
Need some help here, can you suggest something to improve this.

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.

Sorry for reviewing so late.

Don't bother for the tests, I'll see what I can do later.

The PR needs some changes though.

astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
astilectron.go Outdated Show resolved Hide resolved
@shrey-gang
Copy link
Author

@asticode
Sorry for taking so long in making those changes. I have made all the changes as per your suggestions.

astilectron.go Outdated
@@ -45,6 +46,11 @@ const (
EventNameAppTooManyAccept = "app.too.many.accept"
)

// // Unix socket path
Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove this?

astilectron.go Outdated
ElectronSwitches []string
SingleInstance bool
SkipSetup bool // If true, the user must handle provisioning and executing astilectron.
TCPPort *int // The port to listen on.
Copy link
Owner

Choose a reason for hiding this comment

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

Replace this attribute by Addr string so that users may provide their proper addr, not just port

astilectron.go Outdated
@@ -286,7 +346,7 @@ func (a *Astilectron) execute() (err error) {
} else {
singleInstance = "false"
}
var cmd = exec.CommandContext(ctx, a.paths.AppExecutable(), append([]string{a.paths.AstilectronApplication(), a.listener.Addr().String(), singleInstance}, a.options.ElectronSwitches...)...)
var cmd = exec.CommandContext(ctx, a.paths.AppExecutable(), append([]string{a.paths.AstilectronApplication(), listenType, a.listener.Addr().String(), singleInstance}, a.options.ElectronSwitches...)...)
Copy link
Owner

Choose a reason for hiding this comment

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

You shouldn't have to add a flag here. However make sure a.listener.Addr().String() contains the full addr (unix://path/to/socket or tcp://127.0.0.1:4003)

astilectron.go Outdated
@@ -274,7 +334,7 @@ func (a *Astilectron) acceptTCP(chanAccepted chan bool) {
}

// execute executes Astilectron in Electron
func (a *Astilectron) execute() (err error) {
func (a *Astilectron) execute(listenType string) (err error) {
Copy link
Owner

Choose a reason for hiding this comment

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

No need for this new parameter

astilectron.go Outdated
}

// Execute
if !a.options.SkipSetup {
if err = a.execute(); err != nil {
if err = a.execute(listenType); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

No need for this new parameter

astilectron.go Outdated
return "", nil
}

func (a *Astilectron) listenFunc(fn func() error) (err error) {
Copy link
Owner

Choose a reason for hiding this comment

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

Creating this intermediary function doesn't seem really useful

astilectron.go Outdated
// Creates a unix socket
func (a *Astilectron) listenUnix() (err error) {

UNIX_SOCKET_PATH := filepath.Join(a.paths.DataDirectory(), "astilectron.sock")
Copy link
Owner

Choose a reason for hiding this comment

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

Don't name the variable in upper case with _. Name it p

astilectron.go Outdated

UNIX_SOCKET_PATH := filepath.Join(a.paths.DataDirectory(), "astilectron.sock")

_ = os.Remove(UNIX_SOCKET_PATH)
Copy link
Owner

Choose a reason for hiding this comment

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

Check the error here

astilectron.go Outdated

_ = os.Remove(UNIX_SOCKET_PATH)

if err := a.listenFunc(func() error {
Copy link
Owner

Choose a reason for hiding this comment

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

No need for this listenFunc intermediary function

astilectron.go Outdated
// and listens to the first TCP connection coming its way (this should be Astilectron).
func (a *Astilectron) listenTCP() (err error) {
// function to create TCP/Unix socket connection
func (a *Astilectron) listen() (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

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

After seeing this, it seems overly complicated.

Here's what I'd rather do:

  1. Determine var addr string => check a.options.Addr first, then check os
  2. Depending on the scheme of addr, create the proper connection

@shrey-gang
Copy link
Author

Tried testing the changes using the astilectron bundler but did not succeed in that as the bundler always downloads the astilectron from the master tested go-astilectron part the "Addr" is getting updated properly.

@asticode
Copy link
Owner

asticode commented Nov 2, 2019

When using the bundler, you can use the -a flag to indicate the path to your local astilectron folder. That way, it's your astilectron version that is bundled.

@shrey-gang
Copy link
Author

Made some changes in the client connection part, instead of checking the string for "tcp://" or "unix://" I have used net.isIP().
In this way, we don't have to make much changes in the go-astilectron part, plus the code looks cleaner.
I hope this is correct 🤞

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.

None yet

4 participants