-
Notifications
You must be signed in to change notification settings - Fork 344
Fix for issue #190 #191
base: master
Are you sure you want to change the base?
Fix for issue #190 #191
Conversation
@asticode |
There was a problem hiding this 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.
@asticode |
astilectron.go
Outdated
@@ -45,6 +46,11 @@ const ( | |||
EventNameAppTooManyAccept = "app.too.many.accept" | |||
) | |||
|
|||
// // Unix socket path |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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...)...) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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:
- Determine
var addr string
=> checka.options.Addr
first, then checkos
- Depending on the
scheme
ofaddr
, create the proper connection
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. |
When using the bundler, you can use the |
afe15dc
to
0302461
Compare
Made some changes in the client connection part, instead of checking the string for "tcp://" or "unix://" I have used net.isIP(). |
#190
Partnering pull request can be found here: asticode/astilectron#20