id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
164,200 | hashicorp/memberlist | memberlist.go | resolveAddr | func (m *Memberlist) resolveAddr(hostStr string) ([]ipPort, error) {
// This captures the supplied port, or the default one.
hostStr = ensurePort(hostStr, m.config.BindPort)
host, sport, err := net.SplitHostPort(hostStr)
if err != nil {
return nil, err
}
lport, err := strconv.ParseUint(sport, 10, 16)
if err != nil {
return nil, err
}
port := uint16(lport)
// If it looks like an IP address we are done. The SplitHostPort() above
// will make sure the host part is in good shape for parsing, even for
// IPv6 addresses.
if ip := net.ParseIP(host); ip != nil {
return []ipPort{ipPort{ip, port}}, nil
}
// First try TCP so we have the best chance for the largest list of
// hosts to join. If this fails it's not fatal since this isn't a standard
// way to query DNS, and we have a fallback below.
ips, err := m.tcpLookupIP(host, port)
if err != nil {
m.logger.Printf("[DEBUG] memberlist: TCP-first lookup failed for '%s', falling back to UDP: %s", hostStr, err)
}
if len(ips) > 0 {
return ips, nil
}
// If TCP didn't yield anything then use the normal Go resolver which
// will try UDP, then might possibly try TCP again if the UDP response
// indicates it was truncated.
ans, err := net.LookupIP(host)
if err != nil {
return nil, err
}
ips = make([]ipPort, 0, len(ans))
for _, ip := range ans {
ips = append(ips, ipPort{ip, port})
}
return ips, nil
} | go | func (m *Memberlist) resolveAddr(hostStr string) ([]ipPort, error) {
// This captures the supplied port, or the default one.
hostStr = ensurePort(hostStr, m.config.BindPort)
host, sport, err := net.SplitHostPort(hostStr)
if err != nil {
return nil, err
}
lport, err := strconv.ParseUint(sport, 10, 16)
if err != nil {
return nil, err
}
port := uint16(lport)
// If it looks like an IP address we are done. The SplitHostPort() above
// will make sure the host part is in good shape for parsing, even for
// IPv6 addresses.
if ip := net.ParseIP(host); ip != nil {
return []ipPort{ipPort{ip, port}}, nil
}
// First try TCP so we have the best chance for the largest list of
// hosts to join. If this fails it's not fatal since this isn't a standard
// way to query DNS, and we have a fallback below.
ips, err := m.tcpLookupIP(host, port)
if err != nil {
m.logger.Printf("[DEBUG] memberlist: TCP-first lookup failed for '%s', falling back to UDP: %s", hostStr, err)
}
if len(ips) > 0 {
return ips, nil
}
// If TCP didn't yield anything then use the normal Go resolver which
// will try UDP, then might possibly try TCP again if the UDP response
// indicates it was truncated.
ans, err := net.LookupIP(host)
if err != nil {
return nil, err
}
ips = make([]ipPort, 0, len(ans))
for _, ip := range ans {
ips = append(ips, ipPort{ip, port})
}
return ips, nil
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"resolveAddr",
"(",
"hostStr",
"string",
")",
"(",
"[",
"]",
"ipPort",
",",
"error",
")",
"{",
"// This captures the supplied port, or the default one.",
"hostStr",
"=",
"ensurePort",
"(",
"hostStr",
",",
"m",
".",
"co... | // resolveAddr is used to resolve the address into an address,
// port, and error. If no port is given, use the default | [
"resolveAddr",
"is",
"used",
"to",
"resolve",
"the",
"address",
"into",
"an",
"address",
"port",
"and",
"error",
".",
"If",
"no",
"port",
"is",
"given",
"use",
"the",
"default"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L327-L370 |
164,201 | hashicorp/memberlist | memberlist.go | setAlive | func (m *Memberlist) setAlive() error {
// Get the final advertise address from the transport, which may need
// to see which address we bound to.
addr, port, err := m.transport.FinalAdvertiseAddr(
m.config.AdvertiseAddr, m.config.AdvertisePort)
if err != nil {
return fmt.Errorf("Failed to get final advertise address: %v", err)
}
// Check if this is a public address without encryption
ipAddr, err := sockaddr.NewIPAddr(addr.String())
if err != nil {
return fmt.Errorf("Failed to parse interface addresses: %v", err)
}
ifAddrs := []sockaddr.IfAddr{
sockaddr.IfAddr{
SockAddr: ipAddr,
},
}
_, publicIfs, err := sockaddr.IfByRFC("6890", ifAddrs)
if len(publicIfs) > 0 && !m.config.EncryptionEnabled() {
m.logger.Printf("[WARN] memberlist: Binding to public address without encryption!")
}
// Set any metadata from the delegate.
var meta []byte
if m.config.Delegate != nil {
meta = m.config.Delegate.NodeMeta(MetaMaxSize)
if len(meta) > MetaMaxSize {
panic("Node meta data provided is longer than the limit")
}
}
a := alive{
Incarnation: m.nextIncarnation(),
Node: m.config.Name,
Addr: addr,
Port: uint16(port),
Meta: meta,
Vsn: m.config.BuildVsnArray(),
}
m.aliveNode(&a, nil, true)
return nil
} | go | func (m *Memberlist) setAlive() error {
// Get the final advertise address from the transport, which may need
// to see which address we bound to.
addr, port, err := m.transport.FinalAdvertiseAddr(
m.config.AdvertiseAddr, m.config.AdvertisePort)
if err != nil {
return fmt.Errorf("Failed to get final advertise address: %v", err)
}
// Check if this is a public address without encryption
ipAddr, err := sockaddr.NewIPAddr(addr.String())
if err != nil {
return fmt.Errorf("Failed to parse interface addresses: %v", err)
}
ifAddrs := []sockaddr.IfAddr{
sockaddr.IfAddr{
SockAddr: ipAddr,
},
}
_, publicIfs, err := sockaddr.IfByRFC("6890", ifAddrs)
if len(publicIfs) > 0 && !m.config.EncryptionEnabled() {
m.logger.Printf("[WARN] memberlist: Binding to public address without encryption!")
}
// Set any metadata from the delegate.
var meta []byte
if m.config.Delegate != nil {
meta = m.config.Delegate.NodeMeta(MetaMaxSize)
if len(meta) > MetaMaxSize {
panic("Node meta data provided is longer than the limit")
}
}
a := alive{
Incarnation: m.nextIncarnation(),
Node: m.config.Name,
Addr: addr,
Port: uint16(port),
Meta: meta,
Vsn: m.config.BuildVsnArray(),
}
m.aliveNode(&a, nil, true)
return nil
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"setAlive",
"(",
")",
"error",
"{",
"// Get the final advertise address from the transport, which may need",
"// to see which address we bound to.",
"addr",
",",
"port",
",",
"err",
":=",
"m",
".",
"transport",
".",
"FinalAdvert... | // setAlive is used to mark this node as being alive. This is the same
// as if we received an alive notification our own network channel for
// ourself. | [
"setAlive",
"is",
"used",
"to",
"mark",
"this",
"node",
"as",
"being",
"alive",
".",
"This",
"is",
"the",
"same",
"as",
"if",
"we",
"received",
"an",
"alive",
"notification",
"our",
"own",
"network",
"channel",
"for",
"ourself",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L375-L418 |
164,202 | hashicorp/memberlist | memberlist.go | LocalNode | func (m *Memberlist) LocalNode() *Node {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
state := m.nodeMap[m.config.Name]
return &state.Node
} | go | func (m *Memberlist) LocalNode() *Node {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
state := m.nodeMap[m.config.Name]
return &state.Node
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"LocalNode",
"(",
")",
"*",
"Node",
"{",
"m",
".",
"nodeLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"nodeLock",
".",
"RUnlock",
"(",
")",
"\n",
"state",
":=",
"m",
".",
"nodeMap",
"[",
"m",
... | // LocalNode is used to return the local Node | [
"LocalNode",
"is",
"used",
"to",
"return",
"the",
"local",
"Node"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L421-L426 |
164,203 | hashicorp/memberlist | memberlist.go | UpdateNode | func (m *Memberlist) UpdateNode(timeout time.Duration) error {
// Get the node meta data
var meta []byte
if m.config.Delegate != nil {
meta = m.config.Delegate.NodeMeta(MetaMaxSize)
if len(meta) > MetaMaxSize {
panic("Node meta data provided is longer than the limit")
}
}
// Get the existing node
m.nodeLock.RLock()
state := m.nodeMap[m.config.Name]
m.nodeLock.RUnlock()
// Format a new alive message
a := alive{
Incarnation: m.nextIncarnation(),
Node: m.config.Name,
Addr: state.Addr,
Port: state.Port,
Meta: meta,
Vsn: m.config.BuildVsnArray(),
}
notifyCh := make(chan struct{})
m.aliveNode(&a, notifyCh, true)
// Wait for the broadcast or a timeout
if m.anyAlive() {
var timeoutCh <-chan time.Time
if timeout > 0 {
timeoutCh = time.After(timeout)
}
select {
case <-notifyCh:
case <-timeoutCh:
return fmt.Errorf("timeout waiting for update broadcast")
}
}
return nil
} | go | func (m *Memberlist) UpdateNode(timeout time.Duration) error {
// Get the node meta data
var meta []byte
if m.config.Delegate != nil {
meta = m.config.Delegate.NodeMeta(MetaMaxSize)
if len(meta) > MetaMaxSize {
panic("Node meta data provided is longer than the limit")
}
}
// Get the existing node
m.nodeLock.RLock()
state := m.nodeMap[m.config.Name]
m.nodeLock.RUnlock()
// Format a new alive message
a := alive{
Incarnation: m.nextIncarnation(),
Node: m.config.Name,
Addr: state.Addr,
Port: state.Port,
Meta: meta,
Vsn: m.config.BuildVsnArray(),
}
notifyCh := make(chan struct{})
m.aliveNode(&a, notifyCh, true)
// Wait for the broadcast or a timeout
if m.anyAlive() {
var timeoutCh <-chan time.Time
if timeout > 0 {
timeoutCh = time.After(timeout)
}
select {
case <-notifyCh:
case <-timeoutCh:
return fmt.Errorf("timeout waiting for update broadcast")
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"UpdateNode",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"// Get the node meta data",
"var",
"meta",
"[",
"]",
"byte",
"\n",
"if",
"m",
".",
"config",
".",
"Delegate",
"!=",
"nil",
"{",
"meta",
... | // UpdateNode is used to trigger re-advertising the local node. This is
// primarily used with a Delegate to support dynamic updates to the local
// meta data. This will block until the update message is successfully
// broadcasted to a member of the cluster, if any exist or until a specified
// timeout is reached. | [
"UpdateNode",
"is",
"used",
"to",
"trigger",
"re",
"-",
"advertising",
"the",
"local",
"node",
".",
"This",
"is",
"primarily",
"used",
"with",
"a",
"Delegate",
"to",
"support",
"dynamic",
"updates",
"to",
"the",
"local",
"meta",
"data",
".",
"This",
"will"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L433-L473 |
164,204 | hashicorp/memberlist | memberlist.go | SendTo | func (m *Memberlist) SendTo(to net.Addr, msg []byte) error {
// Encode as a user message
buf := make([]byte, 1, len(msg)+1)
buf[0] = byte(userMsg)
buf = append(buf, msg...)
// Send the message
return m.rawSendMsgPacket(to.String(), nil, buf)
} | go | func (m *Memberlist) SendTo(to net.Addr, msg []byte) error {
// Encode as a user message
buf := make([]byte, 1, len(msg)+1)
buf[0] = byte(userMsg)
buf = append(buf, msg...)
// Send the message
return m.rawSendMsgPacket(to.String(), nil, buf)
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"SendTo",
"(",
"to",
"net",
".",
"Addr",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"// Encode as a user message",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
",",
"len",
"(",
"msg",
")",
... | // SendTo is deprecated in favor of SendBestEffort, which requires a node to
// target. | [
"SendTo",
"is",
"deprecated",
"in",
"favor",
"of",
"SendBestEffort",
"which",
"requires",
"a",
"node",
"to",
"target",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L477-L485 |
164,205 | hashicorp/memberlist | memberlist.go | SendToUDP | func (m *Memberlist) SendToUDP(to *Node, msg []byte) error {
return m.SendBestEffort(to, msg)
} | go | func (m *Memberlist) SendToUDP(to *Node, msg []byte) error {
return m.SendBestEffort(to, msg)
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"SendToUDP",
"(",
"to",
"*",
"Node",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"m",
".",
"SendBestEffort",
"(",
"to",
",",
"msg",
")",
"\n",
"}"
] | // SendToUDP is deprecated in favor of SendBestEffort. | [
"SendToUDP",
"is",
"deprecated",
"in",
"favor",
"of",
"SendBestEffort",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L488-L490 |
164,206 | hashicorp/memberlist | memberlist.go | SendToTCP | func (m *Memberlist) SendToTCP(to *Node, msg []byte) error {
return m.SendReliable(to, msg)
} | go | func (m *Memberlist) SendToTCP(to *Node, msg []byte) error {
return m.SendReliable(to, msg)
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"SendToTCP",
"(",
"to",
"*",
"Node",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"m",
".",
"SendReliable",
"(",
"to",
",",
"msg",
")",
"\n",
"}"
] | // SendToTCP is deprecated in favor of SendReliable. | [
"SendToTCP",
"is",
"deprecated",
"in",
"favor",
"of",
"SendReliable",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L493-L495 |
164,207 | hashicorp/memberlist | memberlist.go | Members | func (m *Memberlist) Members() []*Node {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
nodes := make([]*Node, 0, len(m.nodes))
for _, n := range m.nodes {
if n.State != stateDead {
nodes = append(nodes, &n.Node)
}
}
return nodes
} | go | func (m *Memberlist) Members() []*Node {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
nodes := make([]*Node, 0, len(m.nodes))
for _, n := range m.nodes {
if n.State != stateDead {
nodes = append(nodes, &n.Node)
}
}
return nodes
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"Members",
"(",
")",
"[",
"]",
"*",
"Node",
"{",
"m",
".",
"nodeLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"nodeLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"nodes",
":=",
"make",
"(",
"[",
"]"... | // Members returns a list of all known live nodes. The node structures
// returned must not be modified. If you wish to modify a Node, make a
// copy first. | [
"Members",
"returns",
"a",
"list",
"of",
"all",
"known",
"live",
"nodes",
".",
"The",
"node",
"structures",
"returned",
"must",
"not",
"be",
"modified",
".",
"If",
"you",
"wish",
"to",
"modify",
"a",
"Node",
"make",
"a",
"copy",
"first",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L522-L534 |
164,208 | hashicorp/memberlist | memberlist.go | NumMembers | func (m *Memberlist) NumMembers() (alive int) {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
for _, n := range m.nodes {
if n.State != stateDead {
alive++
}
}
return
} | go | func (m *Memberlist) NumMembers() (alive int) {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
for _, n := range m.nodes {
if n.State != stateDead {
alive++
}
}
return
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"NumMembers",
"(",
")",
"(",
"alive",
"int",
")",
"{",
"m",
".",
"nodeLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"nodeLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"n",
":=",
"r... | // NumMembers returns the number of alive nodes currently known. Between
// the time of calling this and calling Members, the number of alive nodes
// may have changed, so this shouldn't be used to determine how many
// members will be returned by Members. | [
"NumMembers",
"returns",
"the",
"number",
"of",
"alive",
"nodes",
"currently",
"known",
".",
"Between",
"the",
"time",
"of",
"calling",
"this",
"and",
"calling",
"Members",
"the",
"number",
"of",
"alive",
"nodes",
"may",
"have",
"changed",
"so",
"this",
"sho... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L540-L551 |
164,209 | hashicorp/memberlist | memberlist.go | Leave | func (m *Memberlist) Leave(timeout time.Duration) error {
m.leaveLock.Lock()
defer m.leaveLock.Unlock()
if m.hasShutdown() {
panic("leave after shutdown")
}
if !m.hasLeft() {
atomic.StoreInt32(&m.leave, 1)
m.nodeLock.Lock()
state, ok := m.nodeMap[m.config.Name]
m.nodeLock.Unlock()
if !ok {
m.logger.Printf("[WARN] memberlist: Leave but we're not in the node map.")
return nil
}
d := dead{
Incarnation: state.Incarnation,
Node: state.Name,
}
m.deadNode(&d)
// Block until the broadcast goes out
if m.anyAlive() {
var timeoutCh <-chan time.Time
if timeout > 0 {
timeoutCh = time.After(timeout)
}
select {
case <-m.leaveBroadcast:
case <-timeoutCh:
return fmt.Errorf("timeout waiting for leave broadcast")
}
}
}
return nil
} | go | func (m *Memberlist) Leave(timeout time.Duration) error {
m.leaveLock.Lock()
defer m.leaveLock.Unlock()
if m.hasShutdown() {
panic("leave after shutdown")
}
if !m.hasLeft() {
atomic.StoreInt32(&m.leave, 1)
m.nodeLock.Lock()
state, ok := m.nodeMap[m.config.Name]
m.nodeLock.Unlock()
if !ok {
m.logger.Printf("[WARN] memberlist: Leave but we're not in the node map.")
return nil
}
d := dead{
Incarnation: state.Incarnation,
Node: state.Name,
}
m.deadNode(&d)
// Block until the broadcast goes out
if m.anyAlive() {
var timeoutCh <-chan time.Time
if timeout > 0 {
timeoutCh = time.After(timeout)
}
select {
case <-m.leaveBroadcast:
case <-timeoutCh:
return fmt.Errorf("timeout waiting for leave broadcast")
}
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"Leave",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"m",
".",
"leaveLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"leaveLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"m",
".",
"h... | // Leave will broadcast a leave message but will not shutdown the background
// listeners, meaning the node will continue participating in gossip and state
// updates.
//
// This will block until the leave message is successfully broadcasted to
// a member of the cluster, if any exist or until a specified timeout
// is reached.
//
// This method is safe to call multiple times, but must not be called
// after the cluster is already shut down. | [
"Leave",
"will",
"broadcast",
"a",
"leave",
"message",
"but",
"will",
"not",
"shutdown",
"the",
"background",
"listeners",
"meaning",
"the",
"node",
"will",
"continue",
"participating",
"in",
"gossip",
"and",
"state",
"updates",
".",
"This",
"will",
"block",
"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L563-L603 |
164,210 | hashicorp/memberlist | memberlist.go | anyAlive | func (m *Memberlist) anyAlive() bool {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
for _, n := range m.nodes {
if n.State != stateDead && n.Name != m.config.Name {
return true
}
}
return false
} | go | func (m *Memberlist) anyAlive() bool {
m.nodeLock.RLock()
defer m.nodeLock.RUnlock()
for _, n := range m.nodes {
if n.State != stateDead && n.Name != m.config.Name {
return true
}
}
return false
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"anyAlive",
"(",
")",
"bool",
"{",
"m",
".",
"nodeLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"nodeLock",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"m",
".",
"node... | // Check for any other alive node. | [
"Check",
"for",
"any",
"other",
"alive",
"node",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L606-L615 |
164,211 | hashicorp/memberlist | memberlist.go | Shutdown | func (m *Memberlist) Shutdown() error {
m.shutdownLock.Lock()
defer m.shutdownLock.Unlock()
if m.hasShutdown() {
return nil
}
// Shut down the transport first, which should block until it's
// completely torn down. If we kill the memberlist-side handlers
// those I/O handlers might get stuck.
if err := m.transport.Shutdown(); err != nil {
m.logger.Printf("[ERR] Failed to shutdown transport: %v", err)
}
// Now tear down everything else.
atomic.StoreInt32(&m.shutdown, 1)
close(m.shutdownCh)
m.deschedule()
return nil
} | go | func (m *Memberlist) Shutdown() error {
m.shutdownLock.Lock()
defer m.shutdownLock.Unlock()
if m.hasShutdown() {
return nil
}
// Shut down the transport first, which should block until it's
// completely torn down. If we kill the memberlist-side handlers
// those I/O handlers might get stuck.
if err := m.transport.Shutdown(); err != nil {
m.logger.Printf("[ERR] Failed to shutdown transport: %v", err)
}
// Now tear down everything else.
atomic.StoreInt32(&m.shutdown, 1)
close(m.shutdownCh)
m.deschedule()
return nil
} | [
"func",
"(",
"m",
"*",
"Memberlist",
")",
"Shutdown",
"(",
")",
"error",
"{",
"m",
".",
"shutdownLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"shutdownLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"m",
".",
"hasShutdown",
"(",
")",
"{",
... | // Shutdown will stop any background maintanence of network activity
// for this memberlist, causing it to appear "dead". A leave message
// will not be broadcasted prior, so the cluster being left will have
// to detect this node's shutdown using probing. If you wish to more
// gracefully exit the cluster, call Leave prior to shutting down.
//
// This method is safe to call multiple times. | [
"Shutdown",
"will",
"stop",
"any",
"background",
"maintanence",
"of",
"network",
"activity",
"for",
"this",
"memberlist",
"causing",
"it",
"to",
"appear",
"dead",
".",
"A",
"leave",
"message",
"will",
"not",
"be",
"broadcasted",
"prior",
"so",
"the",
"cluster"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/memberlist.go#L640-L660 |
164,212 | hashicorp/memberlist | mock_transport.go | NewTransport | func (n *MockNetwork) NewTransport() *MockTransport {
n.port += 1
addr := fmt.Sprintf("127.0.0.1:%d", n.port)
transport := &MockTransport{
net: n,
addr: &MockAddress{addr},
packetCh: make(chan *Packet),
streamCh: make(chan net.Conn),
}
if n.transports == nil {
n.transports = make(map[string]*MockTransport)
}
n.transports[addr] = transport
return transport
} | go | func (n *MockNetwork) NewTransport() *MockTransport {
n.port += 1
addr := fmt.Sprintf("127.0.0.1:%d", n.port)
transport := &MockTransport{
net: n,
addr: &MockAddress{addr},
packetCh: make(chan *Packet),
streamCh: make(chan net.Conn),
}
if n.transports == nil {
n.transports = make(map[string]*MockTransport)
}
n.transports[addr] = transport
return transport
} | [
"func",
"(",
"n",
"*",
"MockNetwork",
")",
"NewTransport",
"(",
")",
"*",
"MockTransport",
"{",
"n",
".",
"port",
"+=",
"1",
"\n",
"addr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"n",
".",
"port",
")",
"\n",
"transport",
":=",
"&",
"Mo... | // NewTransport returns a new MockTransport with a unique address, wired up to
// talk to the other transports in the MockNetwork. | [
"NewTransport",
"returns",
"a",
"new",
"MockTransport",
"with",
"a",
"unique",
"address",
"wired",
"up",
"to",
"talk",
"to",
"the",
"other",
"transports",
"in",
"the",
"MockNetwork",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/mock_transport.go#L19-L34 |
164,213 | hashicorp/memberlist | config.go | DefaultLANConfig | func DefaultLANConfig() *Config {
hostname, _ := os.Hostname()
return &Config{
Name: hostname,
BindAddr: "0.0.0.0",
BindPort: 7946,
AdvertiseAddr: "",
AdvertisePort: 7946,
ProtocolVersion: ProtocolVersion2Compatible,
TCPTimeout: 10 * time.Second, // Timeout after 10 seconds
IndirectChecks: 3, // Use 3 nodes for the indirect ping
RetransmitMult: 4, // Retransmit a message 4 * log(N+1) nodes
SuspicionMult: 4, // Suspect a node for 4 * log(N+1) * Interval
SuspicionMaxTimeoutMult: 6, // For 10k nodes this will give a max timeout of 120 seconds
PushPullInterval: 30 * time.Second, // Low frequency
ProbeTimeout: 500 * time.Millisecond, // Reasonable RTT time for LAN
ProbeInterval: 1 * time.Second, // Failure check every second
DisableTcpPings: false, // TCP pings are safe, even with mixed versions
AwarenessMaxMultiplier: 8, // Probe interval backs off to 8 seconds
GossipNodes: 3, // Gossip to 3 nodes
GossipInterval: 200 * time.Millisecond, // Gossip more rapidly
GossipToTheDeadTime: 30 * time.Second, // Same as push/pull
GossipVerifyIncoming: true,
GossipVerifyOutgoing: true,
EnableCompression: true, // Enable compression by default
SecretKey: nil,
Keyring: nil,
DNSConfigPath: "/etc/resolv.conf",
HandoffQueueDepth: 1024,
UDPBufferSize: 1400,
}
} | go | func DefaultLANConfig() *Config {
hostname, _ := os.Hostname()
return &Config{
Name: hostname,
BindAddr: "0.0.0.0",
BindPort: 7946,
AdvertiseAddr: "",
AdvertisePort: 7946,
ProtocolVersion: ProtocolVersion2Compatible,
TCPTimeout: 10 * time.Second, // Timeout after 10 seconds
IndirectChecks: 3, // Use 3 nodes for the indirect ping
RetransmitMult: 4, // Retransmit a message 4 * log(N+1) nodes
SuspicionMult: 4, // Suspect a node for 4 * log(N+1) * Interval
SuspicionMaxTimeoutMult: 6, // For 10k nodes this will give a max timeout of 120 seconds
PushPullInterval: 30 * time.Second, // Low frequency
ProbeTimeout: 500 * time.Millisecond, // Reasonable RTT time for LAN
ProbeInterval: 1 * time.Second, // Failure check every second
DisableTcpPings: false, // TCP pings are safe, even with mixed versions
AwarenessMaxMultiplier: 8, // Probe interval backs off to 8 seconds
GossipNodes: 3, // Gossip to 3 nodes
GossipInterval: 200 * time.Millisecond, // Gossip more rapidly
GossipToTheDeadTime: 30 * time.Second, // Same as push/pull
GossipVerifyIncoming: true,
GossipVerifyOutgoing: true,
EnableCompression: true, // Enable compression by default
SecretKey: nil,
Keyring: nil,
DNSConfigPath: "/etc/resolv.conf",
HandoffQueueDepth: 1024,
UDPBufferSize: 1400,
}
} | [
"func",
"DefaultLANConfig",
"(",
")",
"*",
"Config",
"{",
"hostname",
",",
"_",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"return",
"&",
"Config",
"{",
"Name",
":",
"hostname",
",",
"BindAddr",
":",
"\"",
"\"",
",",
"BindPort",
":",
"7946",
",",
... | // DefaultLANConfig returns a sane set of configurations for Memberlist.
// It uses the hostname as the node name, and otherwise sets very conservative
// values that are sane for most LAN environments. The default configuration
// errs on the side of caution, choosing values that are optimized
// for higher convergence at the cost of higher bandwidth usage. Regardless,
// these values are a good starting point when getting started with memberlist. | [
"DefaultLANConfig",
"returns",
"a",
"sane",
"set",
"of",
"configurations",
"for",
"Memberlist",
".",
"It",
"uses",
"the",
"hostname",
"as",
"the",
"node",
"name",
"and",
"otherwise",
"sets",
"very",
"conservative",
"values",
"that",
"are",
"sane",
"for",
"most... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/config.go#L226-L262 |
164,214 | hashicorp/memberlist | config.go | DefaultWANConfig | func DefaultWANConfig() *Config {
conf := DefaultLANConfig()
conf.TCPTimeout = 30 * time.Second
conf.SuspicionMult = 6
conf.PushPullInterval = 60 * time.Second
conf.ProbeTimeout = 3 * time.Second
conf.ProbeInterval = 5 * time.Second
conf.GossipNodes = 4 // Gossip less frequently, but to an additional node
conf.GossipInterval = 500 * time.Millisecond
conf.GossipToTheDeadTime = 60 * time.Second
return conf
} | go | func DefaultWANConfig() *Config {
conf := DefaultLANConfig()
conf.TCPTimeout = 30 * time.Second
conf.SuspicionMult = 6
conf.PushPullInterval = 60 * time.Second
conf.ProbeTimeout = 3 * time.Second
conf.ProbeInterval = 5 * time.Second
conf.GossipNodes = 4 // Gossip less frequently, but to an additional node
conf.GossipInterval = 500 * time.Millisecond
conf.GossipToTheDeadTime = 60 * time.Second
return conf
} | [
"func",
"DefaultWANConfig",
"(",
")",
"*",
"Config",
"{",
"conf",
":=",
"DefaultLANConfig",
"(",
")",
"\n",
"conf",
".",
"TCPTimeout",
"=",
"30",
"*",
"time",
".",
"Second",
"\n",
"conf",
".",
"SuspicionMult",
"=",
"6",
"\n",
"conf",
".",
"PushPullInterv... | // DefaultWANConfig works like DefaultConfig, however it returns a configuration
// that is optimized for most WAN environments. The default configuration is
// still very conservative and errs on the side of caution. | [
"DefaultWANConfig",
"works",
"like",
"DefaultConfig",
"however",
"it",
"returns",
"a",
"configuration",
"that",
"is",
"optimized",
"for",
"most",
"WAN",
"environments",
".",
"The",
"default",
"configuration",
"is",
"still",
"very",
"conservative",
"and",
"errs",
"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/config.go#L267-L278 |
164,215 | hashicorp/memberlist | config.go | DefaultLocalConfig | func DefaultLocalConfig() *Config {
conf := DefaultLANConfig()
conf.TCPTimeout = time.Second
conf.IndirectChecks = 1
conf.RetransmitMult = 2
conf.SuspicionMult = 3
conf.PushPullInterval = 15 * time.Second
conf.ProbeTimeout = 200 * time.Millisecond
conf.ProbeInterval = time.Second
conf.GossipInterval = 100 * time.Millisecond
conf.GossipToTheDeadTime = 15 * time.Second
return conf
} | go | func DefaultLocalConfig() *Config {
conf := DefaultLANConfig()
conf.TCPTimeout = time.Second
conf.IndirectChecks = 1
conf.RetransmitMult = 2
conf.SuspicionMult = 3
conf.PushPullInterval = 15 * time.Second
conf.ProbeTimeout = 200 * time.Millisecond
conf.ProbeInterval = time.Second
conf.GossipInterval = 100 * time.Millisecond
conf.GossipToTheDeadTime = 15 * time.Second
return conf
} | [
"func",
"DefaultLocalConfig",
"(",
")",
"*",
"Config",
"{",
"conf",
":=",
"DefaultLANConfig",
"(",
")",
"\n",
"conf",
".",
"TCPTimeout",
"=",
"time",
".",
"Second",
"\n",
"conf",
".",
"IndirectChecks",
"=",
"1",
"\n",
"conf",
".",
"RetransmitMult",
"=",
... | // DefaultLocalConfig works like DefaultConfig, however it returns a configuration
// that is optimized for a local loopback environments. The default configuration is
// still very conservative and errs on the side of caution. | [
"DefaultLocalConfig",
"works",
"like",
"DefaultConfig",
"however",
"it",
"returns",
"a",
"configuration",
"that",
"is",
"optimized",
"for",
"a",
"local",
"loopback",
"environments",
".",
"The",
"default",
"configuration",
"is",
"still",
"very",
"conservative",
"and"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/config.go#L283-L295 |
164,216 | hashicorp/memberlist | config.go | EncryptionEnabled | func (c *Config) EncryptionEnabled() bool {
return c.Keyring != nil && len(c.Keyring.GetKeys()) > 0
} | go | func (c *Config) EncryptionEnabled() bool {
return c.Keyring != nil && len(c.Keyring.GetKeys()) > 0
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"EncryptionEnabled",
"(",
")",
"bool",
"{",
"return",
"c",
".",
"Keyring",
"!=",
"nil",
"&&",
"len",
"(",
"c",
".",
"Keyring",
".",
"GetKeys",
"(",
")",
")",
">",
"0",
"\n",
"}"
] | // Returns whether or not encryption is enabled | [
"Returns",
"whether",
"or",
"not",
"encryption",
"is",
"enabled"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/config.go#L298-L300 |
164,217 | hashicorp/memberlist | suspicion.go | remainingSuspicionTime | func remainingSuspicionTime(n, k int32, elapsed time.Duration, min, max time.Duration) time.Duration {
frac := math.Log(float64(n)+1.0) / math.Log(float64(k)+1.0)
raw := max.Seconds() - frac*(max.Seconds()-min.Seconds())
timeout := time.Duration(math.Floor(1000.0*raw)) * time.Millisecond
if timeout < min {
timeout = min
}
// We have to take into account the amount of time that has passed so
// far, so we get the right overall timeout.
return timeout - elapsed
} | go | func remainingSuspicionTime(n, k int32, elapsed time.Duration, min, max time.Duration) time.Duration {
frac := math.Log(float64(n)+1.0) / math.Log(float64(k)+1.0)
raw := max.Seconds() - frac*(max.Seconds()-min.Seconds())
timeout := time.Duration(math.Floor(1000.0*raw)) * time.Millisecond
if timeout < min {
timeout = min
}
// We have to take into account the amount of time that has passed so
// far, so we get the right overall timeout.
return timeout - elapsed
} | [
"func",
"remainingSuspicionTime",
"(",
"n",
",",
"k",
"int32",
",",
"elapsed",
"time",
".",
"Duration",
",",
"min",
",",
"max",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"frac",
":=",
"math",
".",
"Log",
"(",
"float64",
"(",
"n",
")... | // remainingSuspicionTime takes the state variables of the suspicion timer and
// calculates the remaining time to wait before considering a node dead. The
// return value can be negative, so be prepared to fire the timer immediately in
// that case. | [
"remainingSuspicionTime",
"takes",
"the",
"state",
"variables",
"of",
"the",
"suspicion",
"timer",
"and",
"calculates",
"the",
"remaining",
"time",
"to",
"wait",
"before",
"considering",
"a",
"node",
"dead",
".",
"The",
"return",
"value",
"can",
"be",
"negative"... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/suspicion.go#L86-L97 |
164,218 | hashicorp/memberlist | suspicion.go | Confirm | func (s *suspicion) Confirm(from string) bool {
// If we've got enough confirmations then stop accepting them.
if atomic.LoadInt32(&s.n) >= s.k {
return false
}
// Only allow one confirmation from each possible peer.
if _, ok := s.confirmations[from]; ok {
return false
}
s.confirmations[from] = struct{}{}
// Compute the new timeout given the current number of confirmations and
// adjust the timer. If the timeout becomes negative *and* we can cleanly
// stop the timer then we will call the timeout function directly from
// here.
n := atomic.AddInt32(&s.n, 1)
elapsed := time.Since(s.start)
remaining := remainingSuspicionTime(n, s.k, elapsed, s.min, s.max)
if s.timer.Stop() {
if remaining > 0 {
s.timer.Reset(remaining)
} else {
go s.timeoutFn()
}
}
return true
} | go | func (s *suspicion) Confirm(from string) bool {
// If we've got enough confirmations then stop accepting them.
if atomic.LoadInt32(&s.n) >= s.k {
return false
}
// Only allow one confirmation from each possible peer.
if _, ok := s.confirmations[from]; ok {
return false
}
s.confirmations[from] = struct{}{}
// Compute the new timeout given the current number of confirmations and
// adjust the timer. If the timeout becomes negative *and* we can cleanly
// stop the timer then we will call the timeout function directly from
// here.
n := atomic.AddInt32(&s.n, 1)
elapsed := time.Since(s.start)
remaining := remainingSuspicionTime(n, s.k, elapsed, s.min, s.max)
if s.timer.Stop() {
if remaining > 0 {
s.timer.Reset(remaining)
} else {
go s.timeoutFn()
}
}
return true
} | [
"func",
"(",
"s",
"*",
"suspicion",
")",
"Confirm",
"(",
"from",
"string",
")",
"bool",
"{",
"// If we've got enough confirmations then stop accepting them.",
"if",
"atomic",
".",
"LoadInt32",
"(",
"&",
"s",
".",
"n",
")",
">=",
"s",
".",
"k",
"{",
"return",... | // Confirm registers that a possibly new peer has also determined the given
// node is suspect. This returns true if this was new information, and false
// if it was a duplicate confirmation, or if we've got enough confirmations to
// hit the minimum. | [
"Confirm",
"registers",
"that",
"a",
"possibly",
"new",
"peer",
"has",
"also",
"determined",
"the",
"given",
"node",
"is",
"suspect",
".",
"This",
"returns",
"true",
"if",
"this",
"was",
"new",
"information",
"and",
"false",
"if",
"it",
"was",
"a",
"duplic... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/suspicion.go#L103-L130 |
164,219 | hashicorp/memberlist | queue.go | orderedView | func (q *TransmitLimitedQueue) orderedView(reverse bool) []*limitedBroadcast {
q.mu.Lock()
defer q.mu.Unlock()
out := make([]*limitedBroadcast, 0, q.lenLocked())
q.walkReadOnlyLocked(reverse, func(cur *limitedBroadcast) bool {
out = append(out, cur)
return true
})
return out
} | go | func (q *TransmitLimitedQueue) orderedView(reverse bool) []*limitedBroadcast {
q.mu.Lock()
defer q.mu.Unlock()
out := make([]*limitedBroadcast, 0, q.lenLocked())
q.walkReadOnlyLocked(reverse, func(cur *limitedBroadcast) bool {
out = append(out, cur)
return true
})
return out
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"orderedView",
"(",
"reverse",
"bool",
")",
"[",
"]",
"*",
"limitedBroadcast",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"out",
":... | // for testing; emits in transmit order if reverse=false | [
"for",
"testing",
";",
"emits",
"in",
"transmit",
"order",
"if",
"reverse",
"=",
"false"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L65-L76 |
164,220 | hashicorp/memberlist | queue.go | lazyInit | func (q *TransmitLimitedQueue) lazyInit() {
if q.tq == nil {
q.tq = btree.New(32)
}
if q.tm == nil {
q.tm = make(map[string]*limitedBroadcast)
}
} | go | func (q *TransmitLimitedQueue) lazyInit() {
if q.tq == nil {
q.tq = btree.New(32)
}
if q.tm == nil {
q.tm = make(map[string]*limitedBroadcast)
}
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"lazyInit",
"(",
")",
"{",
"if",
"q",
".",
"tq",
"==",
"nil",
"{",
"q",
".",
"tq",
"=",
"btree",
".",
"New",
"(",
"32",
")",
"\n",
"}",
"\n",
"if",
"q",
".",
"tm",
"==",
"nil",
"{",
"q",
"... | // lazyInit initializes internal data structures the first time they are
// needed. You must already hold the mutex. | [
"lazyInit",
"initializes",
"internal",
"data",
"structures",
"the",
"first",
"time",
"they",
"are",
"needed",
".",
"You",
"must",
"already",
"hold",
"the",
"mutex",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L170-L177 |
164,221 | hashicorp/memberlist | queue.go | queueBroadcast | func (q *TransmitLimitedQueue) queueBroadcast(b Broadcast, initialTransmits int) {
q.mu.Lock()
defer q.mu.Unlock()
q.lazyInit()
if q.idGen == math.MaxInt64 {
// it's super duper unlikely to wrap around within the retransmit limit
q.idGen = 1
} else {
q.idGen++
}
id := q.idGen
lb := &limitedBroadcast{
transmits: initialTransmits,
msgLen: int64(len(b.Message())),
id: id,
b: b,
}
unique := false
if nb, ok := b.(NamedBroadcast); ok {
lb.name = nb.Name()
} else if _, ok := b.(UniqueBroadcast); ok {
unique = true
}
// Check if this message invalidates another.
if lb.name != "" {
if old, ok := q.tm[lb.name]; ok {
old.b.Finished()
q.deleteItem(old)
}
} else if !unique {
// Slow path, hopefully nothing hot hits this.
var remove []*limitedBroadcast
q.tq.Ascend(func(item btree.Item) bool {
cur := item.(*limitedBroadcast)
// Special Broadcasts can only invalidate each other.
switch cur.b.(type) {
case NamedBroadcast:
// noop
case UniqueBroadcast:
// noop
default:
if b.Invalidates(cur.b) {
cur.b.Finished()
remove = append(remove, cur)
}
}
return true
})
for _, cur := range remove {
q.deleteItem(cur)
}
}
// Append to the relevant queue.
q.addItem(lb)
} | go | func (q *TransmitLimitedQueue) queueBroadcast(b Broadcast, initialTransmits int) {
q.mu.Lock()
defer q.mu.Unlock()
q.lazyInit()
if q.idGen == math.MaxInt64 {
// it's super duper unlikely to wrap around within the retransmit limit
q.idGen = 1
} else {
q.idGen++
}
id := q.idGen
lb := &limitedBroadcast{
transmits: initialTransmits,
msgLen: int64(len(b.Message())),
id: id,
b: b,
}
unique := false
if nb, ok := b.(NamedBroadcast); ok {
lb.name = nb.Name()
} else if _, ok := b.(UniqueBroadcast); ok {
unique = true
}
// Check if this message invalidates another.
if lb.name != "" {
if old, ok := q.tm[lb.name]; ok {
old.b.Finished()
q.deleteItem(old)
}
} else if !unique {
// Slow path, hopefully nothing hot hits this.
var remove []*limitedBroadcast
q.tq.Ascend(func(item btree.Item) bool {
cur := item.(*limitedBroadcast)
// Special Broadcasts can only invalidate each other.
switch cur.b.(type) {
case NamedBroadcast:
// noop
case UniqueBroadcast:
// noop
default:
if b.Invalidates(cur.b) {
cur.b.Finished()
remove = append(remove, cur)
}
}
return true
})
for _, cur := range remove {
q.deleteItem(cur)
}
}
// Append to the relevant queue.
q.addItem(lb)
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"queueBroadcast",
"(",
"b",
"Broadcast",
",",
"initialTransmits",
"int",
")",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"q",
".",
... | // queueBroadcast is like QueueBroadcast but you can use a nonzero value for
// the initial transmit tier assigned to the message. This is meant to be used
// for unit testing. | [
"queueBroadcast",
"is",
"like",
"QueueBroadcast",
"but",
"you",
"can",
"use",
"a",
"nonzero",
"value",
"for",
"the",
"initial",
"transmit",
"tier",
"assigned",
"to",
"the",
"message",
".",
"This",
"is",
"meant",
"to",
"be",
"used",
"for",
"unit",
"testing",
... | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L182-L242 |
164,222 | hashicorp/memberlist | queue.go | deleteItem | func (q *TransmitLimitedQueue) deleteItem(cur *limitedBroadcast) {
_ = q.tq.Delete(cur)
if cur.name != "" {
delete(q.tm, cur.name)
}
if q.tq.Len() == 0 {
// At idle there's no reason to let the id generator keep going
// indefinitely.
q.idGen = 0
}
} | go | func (q *TransmitLimitedQueue) deleteItem(cur *limitedBroadcast) {
_ = q.tq.Delete(cur)
if cur.name != "" {
delete(q.tm, cur.name)
}
if q.tq.Len() == 0 {
// At idle there's no reason to let the id generator keep going
// indefinitely.
q.idGen = 0
}
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"deleteItem",
"(",
"cur",
"*",
"limitedBroadcast",
")",
"{",
"_",
"=",
"q",
".",
"tq",
".",
"Delete",
"(",
"cur",
")",
"\n",
"if",
"cur",
".",
"name",
"!=",
"\"",
"\"",
"{",
"delete",
"(",
"q",
... | // deleteItem removes the given item from the overall datastructure. You
// must already hold the mutex. | [
"deleteItem",
"removes",
"the",
"given",
"item",
"from",
"the",
"overall",
"datastructure",
".",
"You",
"must",
"already",
"hold",
"the",
"mutex",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L246-L257 |
164,223 | hashicorp/memberlist | queue.go | addItem | func (q *TransmitLimitedQueue) addItem(cur *limitedBroadcast) {
_ = q.tq.ReplaceOrInsert(cur)
if cur.name != "" {
q.tm[cur.name] = cur
}
} | go | func (q *TransmitLimitedQueue) addItem(cur *limitedBroadcast) {
_ = q.tq.ReplaceOrInsert(cur)
if cur.name != "" {
q.tm[cur.name] = cur
}
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"addItem",
"(",
"cur",
"*",
"limitedBroadcast",
")",
"{",
"_",
"=",
"q",
".",
"tq",
".",
"ReplaceOrInsert",
"(",
"cur",
")",
"\n",
"if",
"cur",
".",
"name",
"!=",
"\"",
"\"",
"{",
"q",
".",
"tm",
... | // addItem adds the given item into the overall datastructure. You must already
// hold the mutex. | [
"addItem",
"adds",
"the",
"given",
"item",
"into",
"the",
"overall",
"datastructure",
".",
"You",
"must",
"already",
"hold",
"the",
"mutex",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L261-L266 |
164,224 | hashicorp/memberlist | queue.go | GetBroadcasts | func (q *TransmitLimitedQueue) GetBroadcasts(overhead, limit int) [][]byte {
q.mu.Lock()
defer q.mu.Unlock()
// Fast path the default case
if q.lenLocked() == 0 {
return nil
}
transmitLimit := retransmitLimit(q.RetransmitMult, q.NumNodes())
var (
bytesUsed int
toSend [][]byte
reinsert []*limitedBroadcast
)
// Visit fresher items first, but only look at stuff that will fit.
// We'll go tier by tier, grabbing the largest items first.
minTr, maxTr := q.getTransmitRange()
for transmits := minTr; transmits <= maxTr; /*do not advance automatically*/ {
free := int64(limit - bytesUsed - overhead)
if free <= 0 {
break // bail out early
}
// Search for the least element on a given tier (by transmit count) as
// defined in the limitedBroadcast.Less function that will fit into our
// remaining space.
greaterOrEqual := &limitedBroadcast{
transmits: transmits,
msgLen: free,
id: math.MaxInt64,
}
lessThan := &limitedBroadcast{
transmits: transmits + 1,
msgLen: math.MaxInt64,
id: math.MaxInt64,
}
var keep *limitedBroadcast
q.tq.AscendRange(greaterOrEqual, lessThan, func(item btree.Item) bool {
cur := item.(*limitedBroadcast)
// Check if this is within our limits
if int64(len(cur.b.Message())) > free {
// If this happens it's a bug in the datastructure or
// surrounding use doing something like having len(Message())
// change over time. There's enough going on here that it's
// probably sane to just skip it and move on for now.
return true
}
keep = cur
return false
})
if keep == nil {
// No more items of an appropriate size in the tier.
transmits++
continue
}
msg := keep.b.Message()
// Add to slice to send
bytesUsed += overhead + len(msg)
toSend = append(toSend, msg)
// Check if we should stop transmission
q.deleteItem(keep)
if keep.transmits+1 >= transmitLimit {
keep.b.Finished()
} else {
// We need to bump this item down to another transmit tier, but
// because it would be in the same direction that we're walking the
// tiers, we will have to delay the reinsertion until we are
// finished our search. Otherwise we'll possibly re-add the message
// when we ascend to the next tier.
keep.transmits++
reinsert = append(reinsert, keep)
}
}
for _, cur := range reinsert {
q.addItem(cur)
}
return toSend
} | go | func (q *TransmitLimitedQueue) GetBroadcasts(overhead, limit int) [][]byte {
q.mu.Lock()
defer q.mu.Unlock()
// Fast path the default case
if q.lenLocked() == 0 {
return nil
}
transmitLimit := retransmitLimit(q.RetransmitMult, q.NumNodes())
var (
bytesUsed int
toSend [][]byte
reinsert []*limitedBroadcast
)
// Visit fresher items first, but only look at stuff that will fit.
// We'll go tier by tier, grabbing the largest items first.
minTr, maxTr := q.getTransmitRange()
for transmits := minTr; transmits <= maxTr; /*do not advance automatically*/ {
free := int64(limit - bytesUsed - overhead)
if free <= 0 {
break // bail out early
}
// Search for the least element on a given tier (by transmit count) as
// defined in the limitedBroadcast.Less function that will fit into our
// remaining space.
greaterOrEqual := &limitedBroadcast{
transmits: transmits,
msgLen: free,
id: math.MaxInt64,
}
lessThan := &limitedBroadcast{
transmits: transmits + 1,
msgLen: math.MaxInt64,
id: math.MaxInt64,
}
var keep *limitedBroadcast
q.tq.AscendRange(greaterOrEqual, lessThan, func(item btree.Item) bool {
cur := item.(*limitedBroadcast)
// Check if this is within our limits
if int64(len(cur.b.Message())) > free {
// If this happens it's a bug in the datastructure or
// surrounding use doing something like having len(Message())
// change over time. There's enough going on here that it's
// probably sane to just skip it and move on for now.
return true
}
keep = cur
return false
})
if keep == nil {
// No more items of an appropriate size in the tier.
transmits++
continue
}
msg := keep.b.Message()
// Add to slice to send
bytesUsed += overhead + len(msg)
toSend = append(toSend, msg)
// Check if we should stop transmission
q.deleteItem(keep)
if keep.transmits+1 >= transmitLimit {
keep.b.Finished()
} else {
// We need to bump this item down to another transmit tier, but
// because it would be in the same direction that we're walking the
// tiers, we will have to delay the reinsertion until we are
// finished our search. Otherwise we'll possibly re-add the message
// when we ascend to the next tier.
keep.transmits++
reinsert = append(reinsert, keep)
}
}
for _, cur := range reinsert {
q.addItem(cur)
}
return toSend
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"GetBroadcasts",
"(",
"overhead",
",",
"limit",
"int",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n"... | // GetBroadcasts is used to get a number of broadcasts, up to a byte limit
// and applying a per-message overhead as provided. | [
"GetBroadcasts",
"is",
"used",
"to",
"get",
"a",
"number",
"of",
"broadcasts",
"up",
"to",
"a",
"byte",
"limit",
"and",
"applying",
"a",
"per",
"-",
"message",
"overhead",
"as",
"provided",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L288-L373 |
164,225 | hashicorp/memberlist | queue.go | NumQueued | func (q *TransmitLimitedQueue) NumQueued() int {
q.mu.Lock()
defer q.mu.Unlock()
return q.lenLocked()
} | go | func (q *TransmitLimitedQueue) NumQueued() int {
q.mu.Lock()
defer q.mu.Unlock()
return q.lenLocked()
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"NumQueued",
"(",
")",
"int",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"q",
".",
"lenLocked",
"(",
")",
"\n",
"}"
] | // NumQueued returns the number of queued messages | [
"NumQueued",
"returns",
"the",
"number",
"of",
"queued",
"messages"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L376-L380 |
164,226 | hashicorp/memberlist | queue.go | lenLocked | func (q *TransmitLimitedQueue) lenLocked() int {
if q.tq == nil {
return 0
}
return q.tq.Len()
} | go | func (q *TransmitLimitedQueue) lenLocked() int {
if q.tq == nil {
return 0
}
return q.tq.Len()
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"lenLocked",
"(",
")",
"int",
"{",
"if",
"q",
".",
"tq",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"q",
".",
"tq",
".",
"Len",
"(",
")",
"\n",
"}"
] | // lenLocked returns the length of the overall queue datastructure. You must
// hold the mutex. | [
"lenLocked",
"returns",
"the",
"length",
"of",
"the",
"overall",
"queue",
"datastructure",
".",
"You",
"must",
"hold",
"the",
"mutex",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L384-L389 |
164,227 | hashicorp/memberlist | queue.go | Reset | func (q *TransmitLimitedQueue) Reset() {
q.mu.Lock()
defer q.mu.Unlock()
q.walkReadOnlyLocked(false, func(cur *limitedBroadcast) bool {
cur.b.Finished()
return true
})
q.tq = nil
q.tm = nil
q.idGen = 0
} | go | func (q *TransmitLimitedQueue) Reset() {
q.mu.Lock()
defer q.mu.Unlock()
q.walkReadOnlyLocked(false, func(cur *limitedBroadcast) bool {
cur.b.Finished()
return true
})
q.tq = nil
q.tm = nil
q.idGen = 0
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"Reset",
"(",
")",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"q",
".",
"walkReadOnlyLocked",
"(",
"false",
",",
"func",
"(",
"cu... | // Reset clears all the queued messages. Should only be used for tests. | [
"Reset",
"clears",
"all",
"the",
"queued",
"messages",
".",
"Should",
"only",
"be",
"used",
"for",
"tests",
"."
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L392-L404 |
164,228 | hashicorp/memberlist | queue.go | Prune | func (q *TransmitLimitedQueue) Prune(maxRetain int) {
q.mu.Lock()
defer q.mu.Unlock()
// Do nothing if queue size is less than the limit
for q.tq.Len() > maxRetain {
item := q.tq.Max()
if item == nil {
break
}
cur := item.(*limitedBroadcast)
cur.b.Finished()
q.deleteItem(cur)
}
} | go | func (q *TransmitLimitedQueue) Prune(maxRetain int) {
q.mu.Lock()
defer q.mu.Unlock()
// Do nothing if queue size is less than the limit
for q.tq.Len() > maxRetain {
item := q.tq.Max()
if item == nil {
break
}
cur := item.(*limitedBroadcast)
cur.b.Finished()
q.deleteItem(cur)
}
} | [
"func",
"(",
"q",
"*",
"TransmitLimitedQueue",
")",
"Prune",
"(",
"maxRetain",
"int",
")",
"{",
"q",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"q",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// Do nothing if queue size is less than the limit",
"fo... | // Prune will retain the maxRetain latest messages, and the rest
// will be discarded. This can be used to prevent unbounded queue sizes | [
"Prune",
"will",
"retain",
"the",
"maxRetain",
"latest",
"messages",
"and",
"the",
"rest",
"will",
"be",
"discarded",
".",
"This",
"can",
"be",
"used",
"to",
"prevent",
"unbounded",
"queue",
"sizes"
] | a8f83c6403e0c718e9336784a270c09dc4613d3e | https://github.com/hashicorp/memberlist/blob/a8f83c6403e0c718e9336784a270c09dc4613d3e/queue.go#L408-L422 |
164,229 | asticode/go-astilectron | tray.go | newTray | func newTray(o *TrayOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, wrt *writer) (t *Tray) {
// Init
t = &Tray{
o: o,
object: newObject(nil, c, d, i, wrt, i.new()),
}
// Make sure the tray's context is cancelled once the destroyed event is received
t.On(EventNameTrayEventDestroyed, func(e Event) (deleteListener bool) {
t.cancel()
return true
})
return
} | go | func newTray(o *TrayOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, wrt *writer) (t *Tray) {
// Init
t = &Tray{
o: o,
object: newObject(nil, c, d, i, wrt, i.new()),
}
// Make sure the tray's context is cancelled once the destroyed event is received
t.On(EventNameTrayEventDestroyed, func(e Event) (deleteListener bool) {
t.cancel()
return true
})
return
} | [
"func",
"newTray",
"(",
"o",
"*",
"TrayOptions",
",",
"c",
"*",
"asticontext",
".",
"Canceller",
",",
"d",
"*",
"dispatcher",
",",
"i",
"*",
"identifier",
",",
"wrt",
"*",
"writer",
")",
"(",
"t",
"*",
"Tray",
")",
"{",
"// Init",
"t",
"=",
"&",
... | // newTray creates a new tray | [
"newTray",
"creates",
"a",
"new",
"tray"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/tray.go#L34-L47 |
164,230 | asticode/go-astilectron | tray.go | Create | func (t *Tray) Create() (err error) {
if err = t.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameTrayCmdCreate, TargetID: t.id, TrayOptions: t.o}
_, err = synchronousEvent(t.c, t, t.w, e, EventNameTrayEventCreated)
return
} | go | func (t *Tray) Create() (err error) {
if err = t.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameTrayCmdCreate, TargetID: t.id, TrayOptions: t.o}
_, err = synchronousEvent(t.c, t, t.w, e, EventNameTrayEventCreated)
return
} | [
"func",
"(",
"t",
"*",
"Tray",
")",
"Create",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"t",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"var",
"e",
"=",
"Event",
"{",
"Name",
":",
... | // Create creates the tray | [
"Create",
"creates",
"the",
"tray"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/tray.go#L50-L57 |
164,231 | asticode/go-astilectron | tray.go | Destroy | func (t *Tray) Destroy() (err error) {
if err = t.isActionable(); err != nil {
return
}
_, err = synchronousEvent(t.c, t, t.w, Event{Name: EventNameTrayCmdDestroy, TargetID: t.id}, EventNameTrayEventDestroyed)
return
} | go | func (t *Tray) Destroy() (err error) {
if err = t.isActionable(); err != nil {
return
}
_, err = synchronousEvent(t.c, t, t.w, Event{Name: EventNameTrayCmdDestroy, TargetID: t.id}, EventNameTrayEventDestroyed)
return
} | [
"func",
"(",
"t",
"*",
"Tray",
")",
"Destroy",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"t",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"synchronousEvent",
"("... | // Destroy destroys the tray | [
"Destroy",
"destroys",
"the",
"tray"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/tray.go#L60-L66 |
164,232 | asticode/go-astilectron | tray.go | NewMenu | func (t *Tray) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(t.ctx, t.id, i, t.c, t.d, t.i, t.w)
} | go | func (t *Tray) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(t.ctx, t.id, i, t.c, t.d, t.i, t.w)
} | [
"func",
"(",
"t",
"*",
"Tray",
")",
"NewMenu",
"(",
"i",
"[",
"]",
"*",
"MenuItemOptions",
")",
"*",
"Menu",
"{",
"return",
"newMenu",
"(",
"t",
".",
"ctx",
",",
"t",
".",
"id",
",",
"i",
",",
"t",
".",
"c",
",",
"t",
".",
"d",
",",
"t",
... | // NewMenu creates a new tray menu | [
"NewMenu",
"creates",
"a",
"new",
"tray",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/tray.go#L69-L71 |
164,233 | asticode/go-astilectron | tray.go | SetImage | func (t *Tray) SetImage(image string) (err error) {
if err = t.isActionable(); err != nil {
return
}
t.o.Image = PtrStr(image)
_, err = synchronousEvent(t.c, t, t.w, Event{Name: EventNameTrayCmdSetImage, Image: image, TargetID: t.id}, EventNameTrayEventImageSet)
return
} | go | func (t *Tray) SetImage(image string) (err error) {
if err = t.isActionable(); err != nil {
return
}
t.o.Image = PtrStr(image)
_, err = synchronousEvent(t.c, t, t.w, Event{Name: EventNameTrayCmdSetImage, Image: image, TargetID: t.id}, EventNameTrayEventImageSet)
return
} | [
"func",
"(",
"t",
"*",
"Tray",
")",
"SetImage",
"(",
"image",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"t",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"o",
".",
"Im... | // SetImage sets the tray image | [
"SetImage",
"sets",
"the",
"tray",
"image"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/tray.go#L74-L81 |
164,234 | asticode/go-astilectron | event.go | Unmarshal | func (p *EventMessage) Unmarshal(i interface{}) error {
if b, ok := p.i.([]byte); ok {
return json.Unmarshal(b, i)
}
return errors.New("event message should []byte")
} | go | func (p *EventMessage) Unmarshal(i interface{}) error {
if b, ok := p.i.([]byte); ok {
return json.Unmarshal(b, i)
}
return errors.New("event message should []byte")
} | [
"func",
"(",
"p",
"*",
"EventMessage",
")",
"Unmarshal",
"(",
"i",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"b",
",",
"ok",
":=",
"p",
".",
"i",
".",
"(",
"[",
"]",
"byte",
")",
";",
"ok",
"{",
"return",
"json",
".",
"Unmarshal",
"(",
... | // Unmarshal unmarshals the payload into the given interface | [
"Unmarshal",
"unmarshals",
"the",
"payload",
"into",
"the",
"given",
"interface"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/event.go#L85-L90 |
164,235 | asticode/go-astilectron | event.go | UnmarshalJSON | func (p *EventMessage) UnmarshalJSON(i []byte) error {
p.i = i
return nil
} | go | func (p *EventMessage) UnmarshalJSON(i []byte) error {
p.i = i
return nil
} | [
"func",
"(",
"p",
"*",
"EventMessage",
")",
"UnmarshalJSON",
"(",
"i",
"[",
"]",
"byte",
")",
"error",
"{",
"p",
".",
"i",
"=",
"i",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON implements the JSONUnmarshaler interface | [
"UnmarshalJSON",
"implements",
"the",
"JSONUnmarshaler",
"interface"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/event.go#L93-L96 |
164,236 | asticode/go-astilectron | accelerator.go | NewAccelerator | func NewAccelerator(items ...string) (a *Accelerator) {
a = &Accelerator{}
for _, i := range items {
*a = append(*a, i)
}
return
} | go | func NewAccelerator(items ...string) (a *Accelerator) {
a = &Accelerator{}
for _, i := range items {
*a = append(*a, i)
}
return
} | [
"func",
"NewAccelerator",
"(",
"items",
"...",
"string",
")",
"(",
"a",
"*",
"Accelerator",
")",
"{",
"a",
"=",
"&",
"Accelerator",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"items",
"{",
"*",
"a",
"=",
"append",
"(",
"*",
"a",
",",
... | // NewAccelerator creates a new accelerator | [
"NewAccelerator",
"creates",
"a",
"new",
"accelerator"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/accelerator.go#L15-L21 |
164,237 | asticode/go-astilectron | paths.go | newPaths | func newPaths(os, arch string, o Options) (p *Paths, err error) {
// Init base directory path
p = &Paths{}
if err = p.initBaseDirectory(o.BaseDirectoryPath); err != nil {
err = errors.Wrap(err, "initializing base directory failed")
return
}
// Init data directory path
if err = p.initDataDirectory(o.DataDirectoryPath, o.AppName); err != nil {
err = errors.Wrap(err, "initializing data directory failed")
return
}
// Init other paths
//!\\ Order matters
p.appIconDarwinSrc = o.AppIconDarwinPath
if len(p.appIconDarwinSrc) > 0 && !filepath.IsAbs(p.appIconDarwinSrc) {
p.appIconDarwinSrc = filepath.Join(p.dataDirectory, p.appIconDarwinSrc)
}
p.appIconDefaultSrc = o.AppIconDefaultPath
if len(p.appIconDefaultSrc) > 0 && !filepath.IsAbs(p.appIconDefaultSrc) {
p.appIconDefaultSrc = filepath.Join(p.dataDirectory, p.appIconDefaultSrc)
}
p.vendorDirectory = filepath.Join(p.dataDirectory, "vendor")
p.provisionStatus = filepath.Join(p.vendorDirectory, "status.json")
p.astilectronDirectory = filepath.Join(p.vendorDirectory, "astilectron")
p.astilectronApplication = filepath.Join(p.astilectronDirectory, "main.js")
p.astilectronDownloadSrc = AstilectronDownloadSrc()
p.astilectronDownloadDst = filepath.Join(p.vendorDirectory, fmt.Sprintf("astilectron-v%s.zip", VersionAstilectron))
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, fmt.Sprintf("astilectron-%s", VersionAstilectron))
p.electronDirectory = filepath.Join(p.vendorDirectory, fmt.Sprintf("electron-%s-%s", os, arch))
p.electronDownloadSrc = ElectronDownloadSrc(os, arch)
p.electronDownloadDst = filepath.Join(p.vendorDirectory, fmt.Sprintf("electron-%s-%s-v%s.zip", os, arch, VersionElectron))
p.electronUnzipSrc = p.electronDownloadDst
p.initAppExecutable(os, o.AppName)
return
} | go | func newPaths(os, arch string, o Options) (p *Paths, err error) {
// Init base directory path
p = &Paths{}
if err = p.initBaseDirectory(o.BaseDirectoryPath); err != nil {
err = errors.Wrap(err, "initializing base directory failed")
return
}
// Init data directory path
if err = p.initDataDirectory(o.DataDirectoryPath, o.AppName); err != nil {
err = errors.Wrap(err, "initializing data directory failed")
return
}
// Init other paths
//!\\ Order matters
p.appIconDarwinSrc = o.AppIconDarwinPath
if len(p.appIconDarwinSrc) > 0 && !filepath.IsAbs(p.appIconDarwinSrc) {
p.appIconDarwinSrc = filepath.Join(p.dataDirectory, p.appIconDarwinSrc)
}
p.appIconDefaultSrc = o.AppIconDefaultPath
if len(p.appIconDefaultSrc) > 0 && !filepath.IsAbs(p.appIconDefaultSrc) {
p.appIconDefaultSrc = filepath.Join(p.dataDirectory, p.appIconDefaultSrc)
}
p.vendorDirectory = filepath.Join(p.dataDirectory, "vendor")
p.provisionStatus = filepath.Join(p.vendorDirectory, "status.json")
p.astilectronDirectory = filepath.Join(p.vendorDirectory, "astilectron")
p.astilectronApplication = filepath.Join(p.astilectronDirectory, "main.js")
p.astilectronDownloadSrc = AstilectronDownloadSrc()
p.astilectronDownloadDst = filepath.Join(p.vendorDirectory, fmt.Sprintf("astilectron-v%s.zip", VersionAstilectron))
p.astilectronUnzipSrc = filepath.Join(p.astilectronDownloadDst, fmt.Sprintf("astilectron-%s", VersionAstilectron))
p.electronDirectory = filepath.Join(p.vendorDirectory, fmt.Sprintf("electron-%s-%s", os, arch))
p.electronDownloadSrc = ElectronDownloadSrc(os, arch)
p.electronDownloadDst = filepath.Join(p.vendorDirectory, fmt.Sprintf("electron-%s-%s-v%s.zip", os, arch, VersionElectron))
p.electronUnzipSrc = p.electronDownloadDst
p.initAppExecutable(os, o.AppName)
return
} | [
"func",
"newPaths",
"(",
"os",
",",
"arch",
"string",
",",
"o",
"Options",
")",
"(",
"p",
"*",
"Paths",
",",
"err",
"error",
")",
"{",
"// Init base directory path",
"p",
"=",
"&",
"Paths",
"{",
"}",
"\n",
"if",
"err",
"=",
"p",
".",
"initBaseDirecto... | // newPaths creates new paths | [
"newPaths",
"creates",
"new",
"paths"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/paths.go#L33-L70 |
164,238 | asticode/go-astilectron | paths.go | initBaseDirectory | func (p *Paths) initBaseDirectory(baseDirectoryPath string) (err error) {
// No path specified in the options
p.baseDirectory = baseDirectoryPath
if len(p.baseDirectory) == 0 {
// Retrieve executable path
var ep string
if ep, err = os.Executable(); err != nil {
err = errors.Wrap(err, "retrieving executable path failed")
return
}
p.baseDirectory = filepath.Dir(ep)
}
// We need the absolute path
if p.baseDirectory, err = filepath.Abs(p.baseDirectory); err != nil {
err = errors.Wrap(err, "computing absolute path failed")
return
}
return
} | go | func (p *Paths) initBaseDirectory(baseDirectoryPath string) (err error) {
// No path specified in the options
p.baseDirectory = baseDirectoryPath
if len(p.baseDirectory) == 0 {
// Retrieve executable path
var ep string
if ep, err = os.Executable(); err != nil {
err = errors.Wrap(err, "retrieving executable path failed")
return
}
p.baseDirectory = filepath.Dir(ep)
}
// We need the absolute path
if p.baseDirectory, err = filepath.Abs(p.baseDirectory); err != nil {
err = errors.Wrap(err, "computing absolute path failed")
return
}
return
} | [
"func",
"(",
"p",
"*",
"Paths",
")",
"initBaseDirectory",
"(",
"baseDirectoryPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"// No path specified in the options",
"p",
".",
"baseDirectory",
"=",
"baseDirectoryPath",
"\n",
"if",
"len",
"(",
"p",
".",
"bas... | // initBaseDirectory initializes the base directory path | [
"initBaseDirectory",
"initializes",
"the",
"base",
"directory",
"path"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/paths.go#L73-L92 |
164,239 | asticode/go-astilectron | paths.go | ElectronDownloadSrc | func ElectronDownloadSrc(os, arch string) string {
// Get OS name
var o string
switch strings.ToLower(os) {
case "darwin":
o = "darwin"
case "linux":
o = "linux"
case "windows":
o = "win32"
}
// Get arch name
var a = "ia32"
if strings.ToLower(arch) == "amd64" || o == "darwin" {
a = "x64"
} else if strings.ToLower(arch) == "arm" && o == "linux" {
a = "armv7l"
}
// Return url
return fmt.Sprintf("https://github.com/electron/electron/releases/download/v%s/electron-v%s-%s-%s.zip", VersionElectron, VersionElectron, o, a)
} | go | func ElectronDownloadSrc(os, arch string) string {
// Get OS name
var o string
switch strings.ToLower(os) {
case "darwin":
o = "darwin"
case "linux":
o = "linux"
case "windows":
o = "win32"
}
// Get arch name
var a = "ia32"
if strings.ToLower(arch) == "amd64" || o == "darwin" {
a = "x64"
} else if strings.ToLower(arch) == "arm" && o == "linux" {
a = "armv7l"
}
// Return url
return fmt.Sprintf("https://github.com/electron/electron/releases/download/v%s/electron-v%s-%s-%s.zip", VersionElectron, VersionElectron, o, a)
} | [
"func",
"ElectronDownloadSrc",
"(",
"os",
",",
"arch",
"string",
")",
"string",
"{",
"// Get OS name",
"var",
"o",
"string",
"\n",
"switch",
"strings",
".",
"ToLower",
"(",
"os",
")",
"{",
"case",
"\"",
"\"",
":",
"o",
"=",
"\"",
"\"",
"\n",
"case",
... | // ElectronDownloadSrc returns the download URL of the platform-dependant electron zipfile | [
"ElectronDownloadSrc",
"returns",
"the",
"download",
"URL",
"of",
"the",
"platform",
"-",
"dependant",
"electron",
"zipfile"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/paths.go#L122-L144 |
164,240 | asticode/go-astilectron | paths.go | initAppExecutable | func (p *Paths) initAppExecutable(os, appName string) {
switch os {
case "darwin":
if appName == "" {
appName = "Electron"
}
p.appExecutable = filepath.Join(p.electronDirectory, appName+".app", "Contents", "MacOS", appName)
case "linux":
p.appExecutable = filepath.Join(p.electronDirectory, "electron")
case "windows":
p.appExecutable = filepath.Join(p.electronDirectory, "electron.exe")
}
} | go | func (p *Paths) initAppExecutable(os, appName string) {
switch os {
case "darwin":
if appName == "" {
appName = "Electron"
}
p.appExecutable = filepath.Join(p.electronDirectory, appName+".app", "Contents", "MacOS", appName)
case "linux":
p.appExecutable = filepath.Join(p.electronDirectory, "electron")
case "windows":
p.appExecutable = filepath.Join(p.electronDirectory, "electron.exe")
}
} | [
"func",
"(",
"p",
"*",
"Paths",
")",
"initAppExecutable",
"(",
"os",
",",
"appName",
"string",
")",
"{",
"switch",
"os",
"{",
"case",
"\"",
"\"",
":",
"if",
"appName",
"==",
"\"",
"\"",
"{",
"appName",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"p",
".",
... | // initAppExecutable initializes the app executable path | [
"initAppExecutable",
"initializes",
"the",
"app",
"executable",
"path"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/paths.go#L147-L159 |
164,241 | asticode/go-astilectron | menu.go | newMenu | func newMenu(parentCtx context.Context, rootID string, items []*MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) (m *Menu) {
// Init
m = &Menu{newSubMenu(parentCtx, rootID, items, c, d, i, w)}
// Make sure the menu's context is cancelled once the destroyed event is received
m.On(EventNameMenuEventDestroyed, func(e Event) (deleteListener bool) {
m.cancel()
return true
})
return
} | go | func newMenu(parentCtx context.Context, rootID string, items []*MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) (m *Menu) {
// Init
m = &Menu{newSubMenu(parentCtx, rootID, items, c, d, i, w)}
// Make sure the menu's context is cancelled once the destroyed event is received
m.On(EventNameMenuEventDestroyed, func(e Event) (deleteListener bool) {
m.cancel()
return true
})
return
} | [
"func",
"newMenu",
"(",
"parentCtx",
"context",
".",
"Context",
",",
"rootID",
"string",
",",
"items",
"[",
"]",
"*",
"MenuItemOptions",
",",
"c",
"*",
"asticontext",
".",
"Canceller",
",",
"d",
"*",
"dispatcher",
",",
"i",
"*",
"identifier",
",",
"w",
... | // newMenu creates a new menu | [
"newMenu",
"creates",
"a",
"new",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu.go#L24-L34 |
164,242 | asticode/go-astilectron | menu.go | Create | func (m *Menu) Create() (err error) {
if err = m.isActionable(); err != nil {
return
}
_, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameMenuCmdCreate, TargetID: m.id, Menu: m.toEvent()}, EventNameMenuEventCreated)
return
} | go | func (m *Menu) Create() (err error) {
if err = m.isActionable(); err != nil {
return
}
_, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameMenuCmdCreate, TargetID: m.id, Menu: m.toEvent()}, EventNameMenuEventCreated)
return
} | [
"func",
"(",
"m",
"*",
"Menu",
")",
"Create",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"synchronousEvent",
"(",... | // Create creates the menu | [
"Create",
"creates",
"the",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu.go#L42-L48 |
164,243 | asticode/go-astilectron | menu.go | Destroy | func (m *Menu) Destroy() (err error) {
if err = m.isActionable(); err != nil {
return
}
_, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameMenuCmdDestroy, TargetID: m.id, Menu: m.toEvent()}, EventNameMenuEventDestroyed)
return
} | go | func (m *Menu) Destroy() (err error) {
if err = m.isActionable(); err != nil {
return
}
_, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameMenuCmdDestroy, TargetID: m.id, Menu: m.toEvent()}, EventNameMenuEventDestroyed)
return
} | [
"func",
"(",
"m",
"*",
"Menu",
")",
"Destroy",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"synchronousEvent",
"("... | // Destroy destroys the menu | [
"Destroy",
"destroys",
"the",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/menu.go#L51-L57 |
164,244 | asticode/go-astilectron | session.go | newSession | func newSession(parentCtx context.Context, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) *Session {
return &Session{object: newObject(parentCtx, c, d, i, w, i.new())}
} | go | func newSession(parentCtx context.Context, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) *Session {
return &Session{object: newObject(parentCtx, c, d, i, w, i.new())}
} | [
"func",
"newSession",
"(",
"parentCtx",
"context",
".",
"Context",
",",
"c",
"*",
"asticontext",
".",
"Canceller",
",",
"d",
"*",
"dispatcher",
",",
"i",
"*",
"identifier",
",",
"w",
"*",
"writer",
")",
"*",
"Session",
"{",
"return",
"&",
"Session",
"{... | // newSession creates a new session | [
"newSession",
"creates",
"a",
"new",
"session"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/session.go#L25-L27 |
164,245 | asticode/go-astilectron | session.go | ClearCache | func (s *Session) ClearCache() (err error) {
if err = s.isActionable(); err != nil {
return
}
_, err = synchronousEvent(s.c, s, s.w, Event{Name: EventNameSessionCmdClearCache, TargetID: s.id}, EventNameSessionEventClearedCache)
return
} | go | func (s *Session) ClearCache() (err error) {
if err = s.isActionable(); err != nil {
return
}
_, err = synchronousEvent(s.c, s, s.w, Event{Name: EventNameSessionCmdClearCache, TargetID: s.id}, EventNameSessionEventClearedCache)
return
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"ClearCache",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"s",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"synchronousEvent",... | // ClearCache clears the Session's HTTP cache | [
"ClearCache",
"clears",
"the",
"Session",
"s",
"HTTP",
"cache"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/session.go#L30-L36 |
164,246 | asticode/go-astilectron | executer.go | DefaultExecuter | func DefaultExecuter(a *Astilectron, cmd *exec.Cmd) (err error) {
// Start command
astilog.Debugf("Starting cmd %s", strings.Join(cmd.Args, " "))
if err = cmd.Start(); err != nil {
err = errors.Wrapf(err, "starting cmd %s failed", strings.Join(cmd.Args, " "))
return
}
// Watch command
go a.watchCmd(cmd)
return
} | go | func DefaultExecuter(a *Astilectron, cmd *exec.Cmd) (err error) {
// Start command
astilog.Debugf("Starting cmd %s", strings.Join(cmd.Args, " "))
if err = cmd.Start(); err != nil {
err = errors.Wrapf(err, "starting cmd %s failed", strings.Join(cmd.Args, " "))
return
}
// Watch command
go a.watchCmd(cmd)
return
} | [
"func",
"DefaultExecuter",
"(",
"a",
"*",
"Astilectron",
",",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"(",
"err",
"error",
")",
"{",
"// Start command",
"astilog",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
","... | // DefaultExecuter represents the default executer | [
"DefaultExecuter",
"represents",
"the",
"default",
"executer"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/executer.go#L15-L26 |
164,247 | asticode/go-astilectron | writer.go | write | func (r *writer) write(e Event) (err error) {
// Marshal
var b []byte
if b, err = json.Marshal(e); err != nil {
return errors.Wrapf(err, "Marshaling %+v failed", e)
}
// Write
astilog.Debugf("Sending to Astilectron: %s", b)
if _, err = r.w.Write(append(b, '\n')); err != nil {
return errors.Wrapf(err, "Writing %s failed", b)
}
return
} | go | func (r *writer) write(e Event) (err error) {
// Marshal
var b []byte
if b, err = json.Marshal(e); err != nil {
return errors.Wrapf(err, "Marshaling %+v failed", e)
}
// Write
astilog.Debugf("Sending to Astilectron: %s", b)
if _, err = r.w.Write(append(b, '\n')); err != nil {
return errors.Wrapf(err, "Writing %s failed", b)
}
return
} | [
"func",
"(",
"r",
"*",
"writer",
")",
"write",
"(",
"e",
"Event",
")",
"(",
"err",
"error",
")",
"{",
"// Marshal",
"var",
"b",
"[",
"]",
"byte",
"\n",
"if",
"b",
",",
"err",
"=",
"json",
".",
"Marshal",
"(",
"e",
")",
";",
"err",
"!=",
"nil"... | // write writes to the stdin | [
"write",
"writes",
"to",
"the",
"stdin"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/writer.go#L29-L42 |
164,248 | asticode/go-astilectron | astilectron.go | New | func New(o Options) (a *Astilectron, err error) {
// Validate the OS
if !IsValidOS(runtime.GOOS) {
err = errors.Wrapf(err, "OS %s is invalid", runtime.GOOS)
return
}
// Init
a = &Astilectron{
canceller: asticontext.NewCanceller(),
channelQuit: make(chan bool),
dispatcher: newDispatcher(),
displayPool: newDisplayPool(),
executer: DefaultExecuter,
identifier: newIdentifier(),
options: o,
provisioner: DefaultProvisioner,
}
// Set paths
if a.paths, err = newPaths(runtime.GOOS, runtime.GOARCH, o); err != nil {
err = errors.Wrap(err, "creating new paths failed")
return
}
// Add default listeners
a.On(EventNameAppCmdStop, func(e Event) (deleteListener bool) {
a.Stop()
return
})
a.On(EventNameDisplayEventAdded, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
a.On(EventNameDisplayEventMetricsChanged, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
a.On(EventNameDisplayEventRemoved, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
return
} | go | func New(o Options) (a *Astilectron, err error) {
// Validate the OS
if !IsValidOS(runtime.GOOS) {
err = errors.Wrapf(err, "OS %s is invalid", runtime.GOOS)
return
}
// Init
a = &Astilectron{
canceller: asticontext.NewCanceller(),
channelQuit: make(chan bool),
dispatcher: newDispatcher(),
displayPool: newDisplayPool(),
executer: DefaultExecuter,
identifier: newIdentifier(),
options: o,
provisioner: DefaultProvisioner,
}
// Set paths
if a.paths, err = newPaths(runtime.GOOS, runtime.GOARCH, o); err != nil {
err = errors.Wrap(err, "creating new paths failed")
return
}
// Add default listeners
a.On(EventNameAppCmdStop, func(e Event) (deleteListener bool) {
a.Stop()
return
})
a.On(EventNameDisplayEventAdded, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
a.On(EventNameDisplayEventMetricsChanged, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
a.On(EventNameDisplayEventRemoved, func(e Event) (deleteListener bool) {
a.displayPool.update(e.Displays)
return
})
return
} | [
"func",
"New",
"(",
"o",
"Options",
")",
"(",
"a",
"*",
"Astilectron",
",",
"err",
"error",
")",
"{",
"// Validate the OS",
"if",
"!",
"IsValidOS",
"(",
"runtime",
".",
"GOOS",
")",
"{",
"err",
"=",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\... | // New creates a new Astilectron instance | [
"New",
"creates",
"a",
"new",
"Astilectron",
"instance"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L86-L129 |
164,249 | asticode/go-astilectron | astilectron.go | SetProvisioner | func (a *Astilectron) SetProvisioner(p Provisioner) *Astilectron {
a.provisioner = p
return a
} | go | func (a *Astilectron) SetProvisioner(p Provisioner) *Astilectron {
a.provisioner = p
return a
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"SetProvisioner",
"(",
"p",
"Provisioner",
")",
"*",
"Astilectron",
"{",
"a",
".",
"provisioner",
"=",
"p",
"\n",
"return",
"a",
"\n",
"}"
] | // SetProvisioner sets the provisioner | [
"SetProvisioner",
"sets",
"the",
"provisioner"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L138-L141 |
164,250 | asticode/go-astilectron | astilectron.go | SetExecuter | func (a *Astilectron) SetExecuter(e Executer) *Astilectron {
a.executer = e
return a
} | go | func (a *Astilectron) SetExecuter(e Executer) *Astilectron {
a.executer = e
return a
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"SetExecuter",
"(",
"e",
"Executer",
")",
"*",
"Astilectron",
"{",
"a",
".",
"executer",
"=",
"e",
"\n",
"return",
"a",
"\n",
"}"
] | // SetExecuter sets the executer | [
"SetExecuter",
"sets",
"the",
"executer"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L144-L147 |
164,251 | asticode/go-astilectron | astilectron.go | Start | func (a *Astilectron) Start() (err error) {
// Log
astilog.Debug("Starting...")
// Provision
if err = a.provision(); err != nil {
return errors.Wrap(err, "provisioning failed")
}
// Unfortunately communicating with Electron through stdin/stdout doesn't work on Windows so all communications
// will be done through TCP
if err = a.listenTCP(); err != nil {
return errors.Wrap(err, "listening failed")
}
// Execute
if err = a.execute(); err != nil {
err = errors.Wrap(err, "executing failed")
return
}
return
} | go | func (a *Astilectron) Start() (err error) {
// Log
astilog.Debug("Starting...")
// Provision
if err = a.provision(); err != nil {
return errors.Wrap(err, "provisioning failed")
}
// Unfortunately communicating with Electron through stdin/stdout doesn't work on Windows so all communications
// will be done through TCP
if err = a.listenTCP(); err != nil {
return errors.Wrap(err, "listening failed")
}
// Execute
if err = a.execute(); err != nil {
err = errors.Wrap(err, "executing failed")
return
}
return
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// Log",
"astilog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Provision",
"if",
"err",
"=",
"a",
".",
"provision",
"(",
")",
";",
"err",
"!=",
"ni... | // Start starts Astilectron | [
"Start",
"starts",
"Astilectron"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L155-L176 |
164,252 | asticode/go-astilectron | astilectron.go | provision | func (a *Astilectron) provision() error {
astilog.Debug("Provisioning...")
var ctx, _ = a.canceller.NewContext()
return a.provisioner.Provision(ctx, a.options.AppName, runtime.GOOS, runtime.GOARCH, *a.paths)
} | go | func (a *Astilectron) provision() error {
astilog.Debug("Provisioning...")
var ctx, _ = a.canceller.NewContext()
return a.provisioner.Provision(ctx, a.options.AppName, runtime.GOOS, runtime.GOARCH, *a.paths)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"provision",
"(",
")",
"error",
"{",
"astilog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"var",
"ctx",
",",
"_",
"=",
"a",
".",
"canceller",
".",
"NewContext",
"(",
")",
"\n",
"return",
"a",
".",
"provi... | // provision provisions Astilectron | [
"provision",
"provisions",
"Astilectron"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L179-L183 |
164,253 | asticode/go-astilectron | astilectron.go | watchNoAccept | func (a *Astilectron) watchNoAccept(timeout time.Duration, chanAccepted chan bool) {
//check timeout
if timeout == 0 {
timeout = DefaultAcceptTCPTimeout
}
var t = time.NewTimer(timeout)
defer t.Stop()
for {
select {
case <-chanAccepted:
return
case <-t.C:
astilog.Errorf("No TCP connection has been accepted in the past %s", timeout)
a.dispatcher.dispatch(Event{Name: EventNameAppNoAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
return
}
}
} | go | func (a *Astilectron) watchNoAccept(timeout time.Duration, chanAccepted chan bool) {
//check timeout
if timeout == 0 {
timeout = DefaultAcceptTCPTimeout
}
var t = time.NewTimer(timeout)
defer t.Stop()
for {
select {
case <-chanAccepted:
return
case <-t.C:
astilog.Errorf("No TCP connection has been accepted in the past %s", timeout)
a.dispatcher.dispatch(Event{Name: EventNameAppNoAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
return
}
}
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"watchNoAccept",
"(",
"timeout",
"time",
".",
"Duration",
",",
"chanAccepted",
"chan",
"bool",
")",
"{",
"//check timeout",
"if",
"timeout",
"==",
"0",
"{",
"timeout",
"=",
"DefaultAcceptTCPTimeout",
"\n",
"}",
"\n"... | // watchNoAccept checks whether a TCP connection is accepted quickly enough | [
"watchNoAccept",
"checks",
"whether",
"a",
"TCP",
"connection",
"is",
"accepted",
"quickly",
"enough"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L205-L223 |
164,254 | asticode/go-astilectron | astilectron.go | acceptTCP | func (a *Astilectron) acceptTCP(chanAccepted chan bool) {
for i := 0; i <= 1; i++ {
// Accept
var conn net.Conn
var err error
if conn, err = a.listener.Accept(); err != nil {
astilog.Errorf("%s while TCP accepting", err)
a.dispatcher.dispatch(Event{Name: EventNameAppErrorAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
return
}
// We only accept the first connection which should be Astilectron, close the next one and stop
// the app
if i > 0 {
astilog.Errorf("Too many TCP connections")
a.dispatcher.dispatch(Event{Name: EventNameAppTooManyAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
conn.Close()
return
}
// Let the timer know a connection has been accepted
chanAccepted <- true
// Create reader and writer
a.writer = newWriter(conn)
ctx, _ := a.canceller.NewContext()
a.reader = newReader(ctx, a.dispatcher, conn)
go a.reader.read()
}
} | go | func (a *Astilectron) acceptTCP(chanAccepted chan bool) {
for i := 0; i <= 1; i++ {
// Accept
var conn net.Conn
var err error
if conn, err = a.listener.Accept(); err != nil {
astilog.Errorf("%s while TCP accepting", err)
a.dispatcher.dispatch(Event{Name: EventNameAppErrorAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
return
}
// We only accept the first connection which should be Astilectron, close the next one and stop
// the app
if i > 0 {
astilog.Errorf("Too many TCP connections")
a.dispatcher.dispatch(Event{Name: EventNameAppTooManyAccept, TargetID: targetIDApp})
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
conn.Close()
return
}
// Let the timer know a connection has been accepted
chanAccepted <- true
// Create reader and writer
a.writer = newWriter(conn)
ctx, _ := a.canceller.NewContext()
a.reader = newReader(ctx, a.dispatcher, conn)
go a.reader.read()
}
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"acceptTCP",
"(",
"chanAccepted",
"chan",
"bool",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"1",
";",
"i",
"++",
"{",
"// Accept",
"var",
"conn",
"net",
".",
"Conn",
"\n",
"var",
"err",
"error",
"... | // watchAcceptTCP accepts TCP connections | [
"watchAcceptTCP",
"accepts",
"TCP",
"connections"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L226-L257 |
164,255 | asticode/go-astilectron | astilectron.go | execute | func (a *Astilectron) execute() (err error) {
// Log
astilog.Debug("Executing...")
// Create command
var ctx, _ = a.canceller.NewContext()
var singleInstance string
if a.options.SingleInstance == true {
singleInstance = "true"
} else {
singleInstance = "false"
}
var cmd = exec.CommandContext(ctx, a.paths.AppExecutable(), append([]string{a.paths.AstilectronApplication(), a.listener.Addr().String(), singleInstance}, a.options.ElectronSwitches...)...)
a.stderrWriter = astiexec.NewStdWriter(func(i []byte) { astilog.Debugf("Stderr says: %s", i) })
a.stdoutWriter = astiexec.NewStdWriter(func(i []byte) { astilog.Debugf("Stdout says: %s", i) })
cmd.Stderr = a.stderrWriter
cmd.Stdout = a.stdoutWriter
// Execute command
if err = a.executeCmd(cmd); err != nil {
return errors.Wrap(err, "executing cmd failed")
}
return
} | go | func (a *Astilectron) execute() (err error) {
// Log
astilog.Debug("Executing...")
// Create command
var ctx, _ = a.canceller.NewContext()
var singleInstance string
if a.options.SingleInstance == true {
singleInstance = "true"
} else {
singleInstance = "false"
}
var cmd = exec.CommandContext(ctx, a.paths.AppExecutable(), append([]string{a.paths.AstilectronApplication(), a.listener.Addr().String(), singleInstance}, a.options.ElectronSwitches...)...)
a.stderrWriter = astiexec.NewStdWriter(func(i []byte) { astilog.Debugf("Stderr says: %s", i) })
a.stdoutWriter = astiexec.NewStdWriter(func(i []byte) { astilog.Debugf("Stdout says: %s", i) })
cmd.Stderr = a.stderrWriter
cmd.Stdout = a.stdoutWriter
// Execute command
if err = a.executeCmd(cmd); err != nil {
return errors.Wrap(err, "executing cmd failed")
}
return
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"execute",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// Log",
"astilog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"// Create command",
"var",
"ctx",
",",
"_",
"=",
"a",
".",
"canceller",
".",
"NewContext"... | // execute executes Astilectron in Electron | [
"execute",
"executes",
"Astilectron",
"in",
"Electron"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L260-L283 |
164,256 | asticode/go-astilectron | astilectron.go | executeCmd | func (a *Astilectron) executeCmd(cmd *exec.Cmd) (err error) {
var e = synchronousFunc(a.canceller, a, func() {
err = a.executer(a, cmd)
}, EventNameAppEventReady)
// Update display pool
if e.Displays != nil {
a.displayPool.update(e.Displays)
}
// Create dock
a.dock = newDock(a.canceller, a.dispatcher, a.identifier, a.writer)
// Update supported features
a.supported = e.Supported
return
} | go | func (a *Astilectron) executeCmd(cmd *exec.Cmd) (err error) {
var e = synchronousFunc(a.canceller, a, func() {
err = a.executer(a, cmd)
}, EventNameAppEventReady)
// Update display pool
if e.Displays != nil {
a.displayPool.update(e.Displays)
}
// Create dock
a.dock = newDock(a.canceller, a.dispatcher, a.identifier, a.writer)
// Update supported features
a.supported = e.Supported
return
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"executeCmd",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"(",
"err",
"error",
")",
"{",
"var",
"e",
"=",
"synchronousFunc",
"(",
"a",
".",
"canceller",
",",
"a",
",",
"func",
"(",
")",
"{",
"err",
"=",
... | // executeCmd executes the command | [
"executeCmd",
"executes",
"the",
"command"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L286-L302 |
164,257 | asticode/go-astilectron | astilectron.go | watchCmd | func (a *Astilectron) watchCmd(cmd *exec.Cmd) {
// Wait
cmd.Wait()
// Check the canceller to check whether it was a crash
if !a.canceller.Cancelled() {
astilog.Debug("App has crashed")
a.dispatcher.dispatch(Event{Name: EventNameAppCrash, TargetID: targetIDApp})
} else {
astilog.Debug("App has closed")
a.dispatcher.dispatch(Event{Name: EventNameAppClose, TargetID: targetIDApp})
}
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
} | go | func (a *Astilectron) watchCmd(cmd *exec.Cmd) {
// Wait
cmd.Wait()
// Check the canceller to check whether it was a crash
if !a.canceller.Cancelled() {
astilog.Debug("App has crashed")
a.dispatcher.dispatch(Event{Name: EventNameAppCrash, TargetID: targetIDApp})
} else {
astilog.Debug("App has closed")
a.dispatcher.dispatch(Event{Name: EventNameAppClose, TargetID: targetIDApp})
}
a.dispatcher.dispatch(Event{Name: EventNameAppCmdStop, TargetID: targetIDApp})
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"watchCmd",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"{",
"// Wait",
"cmd",
".",
"Wait",
"(",
")",
"\n\n",
"// Check the canceller to check whether it was a crash",
"if",
"!",
"a",
".",
"canceller",
".",
"Cancelled... | // watchCmd watches the cmd execution | [
"watchCmd",
"watches",
"the",
"cmd",
"execution"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L305-L318 |
164,258 | asticode/go-astilectron | astilectron.go | Close | func (a *Astilectron) Close() {
astilog.Debug("Closing...")
a.canceller.Cancel()
if a.listener != nil {
a.listener.Close()
}
if a.reader != nil {
a.reader.close()
}
if a.stderrWriter != nil {
a.stderrWriter.Close()
}
if a.stdoutWriter != nil {
a.stdoutWriter.Close()
}
if a.writer != nil {
a.writer.close()
}
} | go | func (a *Astilectron) Close() {
astilog.Debug("Closing...")
a.canceller.Cancel()
if a.listener != nil {
a.listener.Close()
}
if a.reader != nil {
a.reader.close()
}
if a.stderrWriter != nil {
a.stderrWriter.Close()
}
if a.stdoutWriter != nil {
a.stdoutWriter.Close()
}
if a.writer != nil {
a.writer.close()
}
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"Close",
"(",
")",
"{",
"astilog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"a",
".",
"canceller",
".",
"Cancel",
"(",
")",
"\n",
"if",
"a",
".",
"listener",
"!=",
"nil",
"{",
"a",
".",
"listener",
".... | // Close closes Astilectron properly | [
"Close",
"closes",
"Astilectron",
"properly"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L321-L339 |
164,259 | asticode/go-astilectron | astilectron.go | Stop | func (a *Astilectron) Stop() {
astilog.Debug("Stopping...")
a.canceller.Cancel()
a.closeOnce.Do(func() {
close(a.channelQuit)
})
} | go | func (a *Astilectron) Stop() {
astilog.Debug("Stopping...")
a.canceller.Cancel()
a.closeOnce.Do(func() {
close(a.channelQuit)
})
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"Stop",
"(",
")",
"{",
"astilog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"a",
".",
"canceller",
".",
"Cancel",
"(",
")",
"\n",
"a",
".",
"closeOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
... | // Stop orders Astilectron to stop | [
"Stop",
"orders",
"Astilectron",
"to",
"stop"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L354-L360 |
164,260 | asticode/go-astilectron | astilectron.go | Quit | func (a *Astilectron) Quit() error {
return a.writer.write(Event{Name: EventNameAppCmdQuit})
} | go | func (a *Astilectron) Quit() error {
return a.writer.write(Event{Name: EventNameAppCmdQuit})
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"Quit",
"(",
")",
"error",
"{",
"return",
"a",
".",
"writer",
".",
"write",
"(",
"Event",
"{",
"Name",
":",
"EventNameAppCmdQuit",
"}",
")",
"\n",
"}"
] | // Quit quits the app | [
"Quit",
"quits",
"the",
"app"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L368-L370 |
164,261 | asticode/go-astilectron | astilectron.go | NewMenu | func (a *Astilectron) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(nil, targetIDApp, i, a.canceller, a.dispatcher, a.identifier, a.writer)
} | go | func (a *Astilectron) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(nil, targetIDApp, i, a.canceller, a.dispatcher, a.identifier, a.writer)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"NewMenu",
"(",
"i",
"[",
"]",
"*",
"MenuItemOptions",
")",
"*",
"Menu",
"{",
"return",
"newMenu",
"(",
"nil",
",",
"targetIDApp",
",",
"i",
",",
"a",
".",
"canceller",
",",
"a",
".",
"dispatcher",
",",
"a... | // NewMenu creates a new app menu | [
"NewMenu",
"creates",
"a",
"new",
"app",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L393-L395 |
164,262 | asticode/go-astilectron | astilectron.go | NewWindow | func (a *Astilectron) NewWindow(url string, o *WindowOptions) (*Window, error) {
return newWindow(a.options, a.Paths(), url, o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | go | func (a *Astilectron) NewWindow(url string, o *WindowOptions) (*Window, error) {
return newWindow(a.options, a.Paths(), url, o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"NewWindow",
"(",
"url",
"string",
",",
"o",
"*",
"WindowOptions",
")",
"(",
"*",
"Window",
",",
"error",
")",
"{",
"return",
"newWindow",
"(",
"a",
".",
"options",
",",
"a",
".",
"Paths",
"(",
")",
",",
... | // NewWindow creates a new window | [
"NewWindow",
"creates",
"a",
"new",
"window"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L398-L400 |
164,263 | asticode/go-astilectron | astilectron.go | NewWindowInDisplay | func (a *Astilectron) NewWindowInDisplay(d *Display, url string, o *WindowOptions) (*Window, error) {
if o.X != nil {
*o.X += d.Bounds().X
} else {
o.X = PtrInt(d.Bounds().X)
}
if o.Y != nil {
*o.Y += d.Bounds().Y
} else {
o.Y = PtrInt(d.Bounds().Y)
}
return newWindow(a.options, a.Paths(), url, o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | go | func (a *Astilectron) NewWindowInDisplay(d *Display, url string, o *WindowOptions) (*Window, error) {
if o.X != nil {
*o.X += d.Bounds().X
} else {
o.X = PtrInt(d.Bounds().X)
}
if o.Y != nil {
*o.Y += d.Bounds().Y
} else {
o.Y = PtrInt(d.Bounds().Y)
}
return newWindow(a.options, a.Paths(), url, o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"NewWindowInDisplay",
"(",
"d",
"*",
"Display",
",",
"url",
"string",
",",
"o",
"*",
"WindowOptions",
")",
"(",
"*",
"Window",
",",
"error",
")",
"{",
"if",
"o",
".",
"X",
"!=",
"nil",
"{",
"*",
"o",
"."... | // NewWindowInDisplay creates a new window in a specific display
// This overrides the center attribute | [
"NewWindowInDisplay",
"creates",
"a",
"new",
"window",
"in",
"a",
"specific",
"display",
"This",
"overrides",
"the",
"center",
"attribute"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L404-L416 |
164,264 | asticode/go-astilectron | astilectron.go | NewTray | func (a *Astilectron) NewTray(o *TrayOptions) *Tray {
return newTray(o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | go | func (a *Astilectron) NewTray(o *TrayOptions) *Tray {
return newTray(o, a.canceller, a.dispatcher, a.identifier, a.writer)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"NewTray",
"(",
"o",
"*",
"TrayOptions",
")",
"*",
"Tray",
"{",
"return",
"newTray",
"(",
"o",
",",
"a",
".",
"canceller",
",",
"a",
".",
"dispatcher",
",",
"a",
".",
"identifier",
",",
"a",
".",
"writer",... | // NewTray creates a new tray | [
"NewTray",
"creates",
"a",
"new",
"tray"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L419-L421 |
164,265 | asticode/go-astilectron | astilectron.go | NewNotification | func (a *Astilectron) NewNotification(o *NotificationOptions) *Notification {
return newNotification(o, a.supported != nil && a.supported.Notification != nil && *a.supported.Notification, a.canceller, a.dispatcher, a.identifier, a.writer)
} | go | func (a *Astilectron) NewNotification(o *NotificationOptions) *Notification {
return newNotification(o, a.supported != nil && a.supported.Notification != nil && *a.supported.Notification, a.canceller, a.dispatcher, a.identifier, a.writer)
} | [
"func",
"(",
"a",
"*",
"Astilectron",
")",
"NewNotification",
"(",
"o",
"*",
"NotificationOptions",
")",
"*",
"Notification",
"{",
"return",
"newNotification",
"(",
"o",
",",
"a",
".",
"supported",
"!=",
"nil",
"&&",
"a",
".",
"supported",
".",
"Notificati... | // NewNotification creates a new notification | [
"NewNotification",
"creates",
"a",
"new",
"notification"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/astilectron.go#L424-L426 |
164,266 | asticode/go-astilectron | object.go | newObject | func newObject(parentCtx context.Context, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer, id string) (o *object) {
o = &object{
c: c,
d: d,
i: i,
id: id,
w: w,
}
if parentCtx != nil {
o.ctx, o.cancel = context.WithCancel(parentCtx)
} else {
o.ctx, o.cancel = c.NewContext()
}
return
} | go | func newObject(parentCtx context.Context, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer, id string) (o *object) {
o = &object{
c: c,
d: d,
i: i,
id: id,
w: w,
}
if parentCtx != nil {
o.ctx, o.cancel = context.WithCancel(parentCtx)
} else {
o.ctx, o.cancel = c.NewContext()
}
return
} | [
"func",
"newObject",
"(",
"parentCtx",
"context",
".",
"Context",
",",
"c",
"*",
"asticontext",
".",
"Canceller",
",",
"d",
"*",
"dispatcher",
",",
"i",
"*",
"identifier",
",",
"w",
"*",
"writer",
",",
"id",
"string",
")",
"(",
"o",
"*",
"object",
")... | // newObject returns a new base object | [
"newObject",
"returns",
"a",
"new",
"base",
"object"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/object.go#L28-L42 |
164,267 | asticode/go-astilectron | object.go | isActionable | func (o *object) isActionable() error {
if o.c.Cancelled() {
return ErrCancellerCancelled
} else if o.IsDestroyed() {
return ErrObjectDestroyed
}
return nil
} | go | func (o *object) isActionable() error {
if o.c.Cancelled() {
return ErrCancellerCancelled
} else if o.IsDestroyed() {
return ErrObjectDestroyed
}
return nil
} | [
"func",
"(",
"o",
"*",
"object",
")",
"isActionable",
"(",
")",
"error",
"{",
"if",
"o",
".",
"c",
".",
"Cancelled",
"(",
")",
"{",
"return",
"ErrCancellerCancelled",
"\n",
"}",
"else",
"if",
"o",
".",
"IsDestroyed",
"(",
")",
"{",
"return",
"ErrObje... | // isActionable checks whether any type of action is allowed on the window | [
"isActionable",
"checks",
"whether",
"any",
"type",
"of",
"action",
"is",
"allowed",
"on",
"the",
"window"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/object.go#L45-L52 |
164,268 | asticode/go-astilectron | sub_menu.go | newSubMenu | func newSubMenu(parentCtx context.Context, rootID string, items []*MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) *subMenu {
// Init
var m = &subMenu{
object: newObject(parentCtx, c, d, i, w, i.new()),
rootID: rootID,
}
// Parse items
for _, o := range items {
m.items = append(m.items, newMenuItem(m.ctx, rootID, o, c, d, i, w))
}
return m
} | go | func newSubMenu(parentCtx context.Context, rootID string, items []*MenuItemOptions, c *asticontext.Canceller, d *dispatcher, i *identifier, w *writer) *subMenu {
// Init
var m = &subMenu{
object: newObject(parentCtx, c, d, i, w, i.new()),
rootID: rootID,
}
// Parse items
for _, o := range items {
m.items = append(m.items, newMenuItem(m.ctx, rootID, o, c, d, i, w))
}
return m
} | [
"func",
"newSubMenu",
"(",
"parentCtx",
"context",
".",
"Context",
",",
"rootID",
"string",
",",
"items",
"[",
"]",
"*",
"MenuItemOptions",
",",
"c",
"*",
"asticontext",
".",
"Canceller",
",",
"d",
"*",
"dispatcher",
",",
"i",
"*",
"identifier",
",",
"w"... | // newSubMenu creates a new sub menu | [
"newSubMenu",
"creates",
"a",
"new",
"sub",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L40-L52 |
164,269 | asticode/go-astilectron | sub_menu.go | toEvent | func (m *subMenu) toEvent() (e *EventSubMenu) {
e = &EventSubMenu{
ID: m.id,
RootID: m.rootID,
}
for _, i := range m.items {
e.Items = append(e.Items, i.toEvent())
}
return
} | go | func (m *subMenu) toEvent() (e *EventSubMenu) {
e = &EventSubMenu{
ID: m.id,
RootID: m.rootID,
}
for _, i := range m.items {
e.Items = append(e.Items, i.toEvent())
}
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"toEvent",
"(",
")",
"(",
"e",
"*",
"EventSubMenu",
")",
"{",
"e",
"=",
"&",
"EventSubMenu",
"{",
"ID",
":",
"m",
".",
"id",
",",
"RootID",
":",
"m",
".",
"rootID",
",",
"}",
"\n",
"for",
"_",
",",
"i",
... | // toEvent returns the sub menu in the proper event format | [
"toEvent",
"returns",
"the",
"sub",
"menu",
"in",
"the",
"proper",
"event",
"format"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L55-L64 |
164,270 | asticode/go-astilectron | sub_menu.go | NewItem | func (m *subMenu) NewItem(o *MenuItemOptions) *MenuItem {
return newMenuItem(m.ctx, m.rootID, o, m.c, m.d, m.i, m.w)
} | go | func (m *subMenu) NewItem(o *MenuItemOptions) *MenuItem {
return newMenuItem(m.ctx, m.rootID, o, m.c, m.d, m.i, m.w)
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"NewItem",
"(",
"o",
"*",
"MenuItemOptions",
")",
"*",
"MenuItem",
"{",
"return",
"newMenuItem",
"(",
"m",
".",
"ctx",
",",
"m",
".",
"rootID",
",",
"o",
",",
"m",
".",
"c",
",",
"m",
".",
"d",
",",
"m",
... | // NewItem returns a new menu item | [
"NewItem",
"returns",
"a",
"new",
"menu",
"item"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L67-L69 |
164,271 | asticode/go-astilectron | sub_menu.go | SubMenu | func (m *subMenu) SubMenu(indexes ...int) (s *SubMenu, err error) {
var is = m
var processedIndexes = []string{}
for _, index := range indexes {
if index >= len(is.items) {
return nil, fmt.Errorf("Submenu at %s has %d items, invalid index %d", strings.Join(processedIndexes, ":"), len(is.items), index)
}
s = is.items[index].s
processedIndexes = append(processedIndexes, strconv.Itoa(index))
if s == nil {
return nil, fmt.Errorf("No submenu at %s", strings.Join(processedIndexes, ":"))
}
is = s.subMenu
}
return
} | go | func (m *subMenu) SubMenu(indexes ...int) (s *SubMenu, err error) {
var is = m
var processedIndexes = []string{}
for _, index := range indexes {
if index >= len(is.items) {
return nil, fmt.Errorf("Submenu at %s has %d items, invalid index %d", strings.Join(processedIndexes, ":"), len(is.items), index)
}
s = is.items[index].s
processedIndexes = append(processedIndexes, strconv.Itoa(index))
if s == nil {
return nil, fmt.Errorf("No submenu at %s", strings.Join(processedIndexes, ":"))
}
is = s.subMenu
}
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"SubMenu",
"(",
"indexes",
"...",
"int",
")",
"(",
"s",
"*",
"SubMenu",
",",
"err",
"error",
")",
"{",
"var",
"is",
"=",
"m",
"\n",
"var",
"processedIndexes",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
... | // SubMenu returns the sub menu at the specified indexes | [
"SubMenu",
"returns",
"the",
"sub",
"menu",
"at",
"the",
"specified",
"indexes"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L72-L87 |
164,272 | asticode/go-astilectron | sub_menu.go | Item | func (m *subMenu) Item(indexes ...int) (mi *MenuItem, err error) {
var is = m
if len(indexes) > 1 {
var s *SubMenu
if s, err = m.SubMenu(indexes[:len(indexes)-1]...); err != nil {
return
}
is = s.subMenu
}
var index = indexes[len(indexes)-1]
if index >= len(is.items) {
return nil, fmt.Errorf("Submenu has %d items, invalid index %d", len(is.items), index)
}
mi = is.items[index]
return
} | go | func (m *subMenu) Item(indexes ...int) (mi *MenuItem, err error) {
var is = m
if len(indexes) > 1 {
var s *SubMenu
if s, err = m.SubMenu(indexes[:len(indexes)-1]...); err != nil {
return
}
is = s.subMenu
}
var index = indexes[len(indexes)-1]
if index >= len(is.items) {
return nil, fmt.Errorf("Submenu has %d items, invalid index %d", len(is.items), index)
}
mi = is.items[index]
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"Item",
"(",
"indexes",
"...",
"int",
")",
"(",
"mi",
"*",
"MenuItem",
",",
"err",
"error",
")",
"{",
"var",
"is",
"=",
"m",
"\n",
"if",
"len",
"(",
"indexes",
")",
">",
"1",
"{",
"var",
"s",
"*",
"SubMe... | // Item returns the item at the specified indexes | [
"Item",
"returns",
"the",
"item",
"at",
"the",
"specified",
"indexes"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L90-L105 |
164,273 | asticode/go-astilectron | sub_menu.go | Append | func (m *subMenu) Append(i *MenuItem) (err error) {
if err = m.isActionable(); err != nil {
return
}
if _, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameSubMenuCmdAppend, TargetID: m.id, MenuItem: i.toEvent()}, EventNameSubMenuEventAppended); err != nil {
return
}
m.items = append(m.items, i)
return
} | go | func (m *subMenu) Append(i *MenuItem) (err error) {
if err = m.isActionable(); err != nil {
return
}
if _, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameSubMenuCmdAppend, TargetID: m.id, MenuItem: i.toEvent()}, EventNameSubMenuEventAppended); err != nil {
return
}
m.items = append(m.items, i)
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"Append",
"(",
"i",
"*",
"MenuItem",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"_",
",",
"er... | // Append appends a menu item into the sub menu | [
"Append",
"appends",
"a",
"menu",
"item",
"into",
"the",
"sub",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L108-L117 |
164,274 | asticode/go-astilectron | sub_menu.go | Insert | func (m *subMenu) Insert(pos int, i *MenuItem) (err error) {
if err = m.isActionable(); err != nil {
return
}
if pos > len(m.items) {
err = fmt.Errorf("Submenu has %d items, position %d is invalid", len(m.items), pos)
return
}
if _, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameSubMenuCmdInsert, TargetID: m.id, MenuItem: i.toEvent(), MenuItemPosition: PtrInt(pos)}, EventNameSubMenuEventInserted); err != nil {
return
}
m.items = append(m.items[:pos], append([]*MenuItem{i}, m.items[pos:]...)...)
return
} | go | func (m *subMenu) Insert(pos int, i *MenuItem) (err error) {
if err = m.isActionable(); err != nil {
return
}
if pos > len(m.items) {
err = fmt.Errorf("Submenu has %d items, position %d is invalid", len(m.items), pos)
return
}
if _, err = synchronousEvent(m.c, m, m.w, Event{Name: EventNameSubMenuCmdInsert, TargetID: m.id, MenuItem: i.toEvent(), MenuItemPosition: PtrInt(pos)}, EventNameSubMenuEventInserted); err != nil {
return
}
m.items = append(m.items[:pos], append([]*MenuItem{i}, m.items[pos:]...)...)
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"Insert",
"(",
"pos",
"int",
",",
"i",
"*",
"MenuItem",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
... | // Insert inserts a menu item to the position of the sub menu | [
"Insert",
"inserts",
"a",
"menu",
"item",
"to",
"the",
"position",
"of",
"the",
"sub",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L120-L133 |
164,275 | asticode/go-astilectron | sub_menu.go | Popup | func (m *subMenu) Popup(o *MenuPopupOptions) error {
return m.PopupInWindow(nil, o)
} | go | func (m *subMenu) Popup(o *MenuPopupOptions) error {
return m.PopupInWindow(nil, o)
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"Popup",
"(",
"o",
"*",
"MenuPopupOptions",
")",
"error",
"{",
"return",
"m",
".",
"PopupInWindow",
"(",
"nil",
",",
"o",
")",
"\n",
"}"
] | // Popup pops up the menu as a context menu in the focused window | [
"Popup",
"pops",
"up",
"the",
"menu",
"as",
"a",
"context",
"menu",
"in",
"the",
"focused",
"window"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L142-L144 |
164,276 | asticode/go-astilectron | sub_menu.go | PopupInWindow | func (m *subMenu) PopupInWindow(w *Window, o *MenuPopupOptions) (err error) {
if err = m.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameSubMenuCmdPopup, TargetID: m.id, MenuPopupOptions: o}
if w != nil {
e.WindowID = w.id
}
_, err = synchronousEvent(m.c, m, m.w, e, EventNameSubMenuEventPoppedUp)
return
} | go | func (m *subMenu) PopupInWindow(w *Window, o *MenuPopupOptions) (err error) {
if err = m.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameSubMenuCmdPopup, TargetID: m.id, MenuPopupOptions: o}
if w != nil {
e.WindowID = w.id
}
_, err = synchronousEvent(m.c, m, m.w, e, EventNameSubMenuEventPoppedUp)
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"PopupInWindow",
"(",
"w",
"*",
"Window",
",",
"o",
"*",
"MenuPopupOptions",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
... | // PopupInWindow pops up the menu as a context menu in the specified window | [
"PopupInWindow",
"pops",
"up",
"the",
"menu",
"as",
"a",
"context",
"menu",
"in",
"the",
"specified",
"window"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L147-L157 |
164,277 | asticode/go-astilectron | sub_menu.go | ClosePopupInWindow | func (m *subMenu) ClosePopupInWindow(w *Window) (err error) {
if err = m.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameSubMenuCmdClosePopup, TargetID: m.id}
if w != nil {
e.WindowID = w.id
}
_, err = synchronousEvent(m.c, m, m.w, e, EventNameSubMenuEventClosedPopup)
return
} | go | func (m *subMenu) ClosePopupInWindow(w *Window) (err error) {
if err = m.isActionable(); err != nil {
return
}
var e = Event{Name: EventNameSubMenuCmdClosePopup, TargetID: m.id}
if w != nil {
e.WindowID = w.id
}
_, err = synchronousEvent(m.c, m, m.w, e, EventNameSubMenuEventClosedPopup)
return
} | [
"func",
"(",
"m",
"*",
"subMenu",
")",
"ClosePopupInWindow",
"(",
"w",
"*",
"Window",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"m",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"var",
"e",
... | // ClosePopupInWindow close the context menu in the specified window | [
"ClosePopupInWindow",
"close",
"the",
"context",
"menu",
"in",
"the",
"specified",
"window"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/sub_menu.go#L165-L175 |
164,278 | asticode/go-astilectron | display_pool.go | newDisplayPool | func newDisplayPool() *displayPool {
return &displayPool{
d: make(map[int64]*Display),
m: &sync.Mutex{},
}
} | go | func newDisplayPool() *displayPool {
return &displayPool{
d: make(map[int64]*Display),
m: &sync.Mutex{},
}
} | [
"func",
"newDisplayPool",
"(",
")",
"*",
"displayPool",
"{",
"return",
"&",
"displayPool",
"{",
"d",
":",
"make",
"(",
"map",
"[",
"int64",
"]",
"*",
"Display",
")",
",",
"m",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n",
"}"
] | // newDisplayPool creates a new display pool | [
"newDisplayPool",
"creates",
"a",
"new",
"display",
"pool"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display_pool.go#L12-L17 |
164,279 | asticode/go-astilectron | display_pool.go | all | func (p *displayPool) all() (ds []*Display) {
p.m.Lock()
defer p.m.Unlock()
ds = []*Display{}
for _, d := range p.d {
ds = append(ds, d)
}
return
} | go | func (p *displayPool) all() (ds []*Display) {
p.m.Lock()
defer p.m.Unlock()
ds = []*Display{}
for _, d := range p.d {
ds = append(ds, d)
}
return
} | [
"func",
"(",
"p",
"*",
"displayPool",
")",
"all",
"(",
")",
"(",
"ds",
"[",
"]",
"*",
"Display",
")",
"{",
"p",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"ds",
"=",
"[",
"]",
"*",
"Displ... | // all returns all the displays | [
"all",
"returns",
"all",
"the",
"displays"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display_pool.go#L20-L28 |
164,280 | asticode/go-astilectron | display_pool.go | primary | func (p *displayPool) primary() (d *Display) {
p.m.Lock()
defer p.m.Unlock()
for _, d = range p.d {
if d.primary {
return
}
}
return
} | go | func (p *displayPool) primary() (d *Display) {
p.m.Lock()
defer p.m.Unlock()
for _, d = range p.d {
if d.primary {
return
}
}
return
} | [
"func",
"(",
"p",
"*",
"displayPool",
")",
"primary",
"(",
")",
"(",
"d",
"*",
"Display",
")",
"{",
"p",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"d",
"=",
"range",
"p",
... | // primary returns the primary display
// It defaults to the last display | [
"primary",
"returns",
"the",
"primary",
"display",
"It",
"defaults",
"to",
"the",
"last",
"display"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display_pool.go#L32-L41 |
164,281 | asticode/go-astilectron | display_pool.go | update | func (p *displayPool) update(e *EventDisplays) {
p.m.Lock()
defer p.m.Unlock()
var ids = make(map[int64]bool)
for _, o := range e.All {
ids[*o.ID] = true
var primary bool
if *o.ID == *e.Primary.ID {
primary = true
}
if d, ok := p.d[*o.ID]; ok {
d.primary = primary
*d.o = *o
} else {
p.d[*o.ID] = newDisplay(o, primary)
}
}
for id := range p.d {
if _, ok := ids[id]; !ok {
delete(p.d, id)
}
}
} | go | func (p *displayPool) update(e *EventDisplays) {
p.m.Lock()
defer p.m.Unlock()
var ids = make(map[int64]bool)
for _, o := range e.All {
ids[*o.ID] = true
var primary bool
if *o.ID == *e.Primary.ID {
primary = true
}
if d, ok := p.d[*o.ID]; ok {
d.primary = primary
*d.o = *o
} else {
p.d[*o.ID] = newDisplay(o, primary)
}
}
for id := range p.d {
if _, ok := ids[id]; !ok {
delete(p.d, id)
}
}
} | [
"func",
"(",
"p",
"*",
"displayPool",
")",
"update",
"(",
"e",
"*",
"EventDisplays",
")",
"{",
"p",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"var",
"ids",
"=",
"make",
"(",
"map",
"[",
"int... | // update updates the pool based on event displays | [
"update",
"updates",
"the",
"pool",
"based",
"on",
"event",
"displays"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/display_pool.go#L44-L66 |
164,282 | asticode/go-astilectron | notification.go | Create | func (n *Notification) Create() (err error) {
if !n.isSupported {
return
}
if err = n.isActionable(); err != nil {
return
}
_, err = synchronousEvent(n.c, n, n.w, Event{Name: eventNameNotificationCmdCreate, TargetID: n.id, NotificationOptions: n.o}, EventNameNotificationEventCreated)
return
} | go | func (n *Notification) Create() (err error) {
if !n.isSupported {
return
}
if err = n.isActionable(); err != nil {
return
}
_, err = synchronousEvent(n.c, n, n.w, Event{Name: eventNameNotificationCmdCreate, TargetID: n.id, NotificationOptions: n.o}, EventNameNotificationEventCreated)
return
} | [
"func",
"(",
"n",
"*",
"Notification",
")",
"Create",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"n",
".",
"isSupported",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"n",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{... | // Create creates the notification | [
"Create",
"creates",
"the",
"notification"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/notification.go#L45-L54 |
164,283 | asticode/go-astilectron | notification.go | Show | func (n *Notification) Show() (err error) {
if !n.isSupported {
return
}
if err = n.isActionable(); err != nil {
return
}
_, err = synchronousEvent(n.c, n, n.w, Event{Name: eventNameNotificationCmdShow, TargetID: n.id}, EventNameNotificationEventShown)
return
} | go | func (n *Notification) Show() (err error) {
if !n.isSupported {
return
}
if err = n.isActionable(); err != nil {
return
}
_, err = synchronousEvent(n.c, n, n.w, Event{Name: eventNameNotificationCmdShow, TargetID: n.id}, EventNameNotificationEventShown)
return
} | [
"func",
"(",
"n",
"*",
"Notification",
")",
"Show",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"n",
".",
"isSupported",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"n",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",... | // Show shows the notification | [
"Show",
"shows",
"the",
"notification"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/notification.go#L57-L66 |
164,284 | asticode/go-astilectron | provisioner.go | ProvisionStatus | func (p *defaultProvisioner) ProvisionStatus(paths Paths) (s ProvisionStatus, err error) {
// Open the file
var f *os.File
s.Electron = make(map[string]*ProvisionStatusPackage)
if f, err = os.Open(paths.ProvisionStatus()); err != nil {
if !os.IsNotExist(err) {
err = errors.Wrapf(err, "opening file %s failed", paths.ProvisionStatus())
} else {
err = nil
}
return
}
defer f.Close()
// Unmarshal
if errLocal := json.NewDecoder(f).Decode(&s); errLocal != nil {
// For backward compatibility purposes, if there's an unmarshal error we delete the status file and make the
// assumption that provisioning has to be done all over again
astilog.Error(errors.Wrapf(errLocal, "json decoding from %s failed", paths.ProvisionStatus()))
astilog.Debugf("Removing %s", f.Name())
if errLocal = os.RemoveAll(f.Name()); errLocal != nil {
astilog.Error(errors.Wrapf(errLocal, "removing %s failed", f.Name()))
}
return
}
return
} | go | func (p *defaultProvisioner) ProvisionStatus(paths Paths) (s ProvisionStatus, err error) {
// Open the file
var f *os.File
s.Electron = make(map[string]*ProvisionStatusPackage)
if f, err = os.Open(paths.ProvisionStatus()); err != nil {
if !os.IsNotExist(err) {
err = errors.Wrapf(err, "opening file %s failed", paths.ProvisionStatus())
} else {
err = nil
}
return
}
defer f.Close()
// Unmarshal
if errLocal := json.NewDecoder(f).Decode(&s); errLocal != nil {
// For backward compatibility purposes, if there's an unmarshal error we delete the status file and make the
// assumption that provisioning has to be done all over again
astilog.Error(errors.Wrapf(errLocal, "json decoding from %s failed", paths.ProvisionStatus()))
astilog.Debugf("Removing %s", f.Name())
if errLocal = os.RemoveAll(f.Name()); errLocal != nil {
astilog.Error(errors.Wrapf(errLocal, "removing %s failed", f.Name()))
}
return
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"ProvisionStatus",
"(",
"paths",
"Paths",
")",
"(",
"s",
"ProvisionStatus",
",",
"err",
"error",
")",
"{",
"// Open the file",
"var",
"f",
"*",
"os",
".",
"File",
"\n",
"s",
".",
"Electron",
"=",
"make",
... | // ProvisionStatus returns the provision status | [
"ProvisionStatus",
"returns",
"the",
"provision",
"status"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L99-L125 |
164,285 | asticode/go-astilectron | provisioner.go | updateProvisionStatus | func (p *defaultProvisioner) updateProvisionStatus(paths Paths, s *ProvisionStatus) (err error) {
// Create the file
var f *os.File
if f, err = os.Create(paths.ProvisionStatus()); err != nil {
err = errors.Wrapf(err, "creating file %s failed", paths.ProvisionStatus())
return
}
defer f.Close()
// Marshal
if err = json.NewEncoder(f).Encode(s); err != nil {
err = errors.Wrapf(err, "json encoding into %s failed", paths.ProvisionStatus())
return
}
return
} | go | func (p *defaultProvisioner) updateProvisionStatus(paths Paths, s *ProvisionStatus) (err error) {
// Create the file
var f *os.File
if f, err = os.Create(paths.ProvisionStatus()); err != nil {
err = errors.Wrapf(err, "creating file %s failed", paths.ProvisionStatus())
return
}
defer f.Close()
// Marshal
if err = json.NewEncoder(f).Encode(s); err != nil {
err = errors.Wrapf(err, "json encoding into %s failed", paths.ProvisionStatus())
return
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"updateProvisionStatus",
"(",
"paths",
"Paths",
",",
"s",
"*",
"ProvisionStatus",
")",
"(",
"err",
"error",
")",
"{",
"// Create the file",
"var",
"f",
"*",
"os",
".",
"File",
"\n",
"if",
"f",
",",
"err",... | // ProvisionStatus updates the provision status | [
"ProvisionStatus",
"updates",
"the",
"provision",
"status"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L128-L143 |
164,286 | asticode/go-astilectron | provisioner.go | provisionAstilectron | func (p *defaultProvisioner) provisionAstilectron(ctx context.Context, paths Paths, s ProvisionStatus) error {
return p.provisionPackage(ctx, paths, s.Astilectron, p.moverAstilectron, "Astilectron", VersionAstilectron, paths.AstilectronUnzipSrc(), paths.AstilectronDirectory(), nil)
} | go | func (p *defaultProvisioner) provisionAstilectron(ctx context.Context, paths Paths, s ProvisionStatus) error {
return p.provisionPackage(ctx, paths, s.Astilectron, p.moverAstilectron, "Astilectron", VersionAstilectron, paths.AstilectronUnzipSrc(), paths.AstilectronDirectory(), nil)
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionAstilectron",
"(",
"ctx",
"context",
".",
"Context",
",",
"paths",
"Paths",
",",
"s",
"ProvisionStatus",
")",
"error",
"{",
"return",
"p",
".",
"provisionPackage",
"(",
"ctx",
",",
"paths",
",",
"... | // provisionAstilectron provisions astilectron | [
"provisionAstilectron",
"provisions",
"astilectron"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L146-L148 |
164,287 | asticode/go-astilectron | provisioner.go | provisionElectron | func (p *defaultProvisioner) provisionElectron(ctx context.Context, paths Paths, s ProvisionStatus, appName, os, arch string) error {
return p.provisionPackage(ctx, paths, s.Electron[provisionStatusElectronKey(os, arch)], p.moverElectron, "Electron", VersionElectron, paths.ElectronUnzipSrc(), paths.ElectronDirectory(), func() (err error) {
switch os {
case "darwin":
if err = p.provisionElectronFinishDarwin(appName, paths); err != nil {
return errors.Wrap(err, "finishing provisioning electron for darwin systems failed")
}
default:
astilog.Debug("System doesn't require finshing provisioning electron, moving on...")
}
return
})
} | go | func (p *defaultProvisioner) provisionElectron(ctx context.Context, paths Paths, s ProvisionStatus, appName, os, arch string) error {
return p.provisionPackage(ctx, paths, s.Electron[provisionStatusElectronKey(os, arch)], p.moverElectron, "Electron", VersionElectron, paths.ElectronUnzipSrc(), paths.ElectronDirectory(), func() (err error) {
switch os {
case "darwin":
if err = p.provisionElectronFinishDarwin(appName, paths); err != nil {
return errors.Wrap(err, "finishing provisioning electron for darwin systems failed")
}
default:
astilog.Debug("System doesn't require finshing provisioning electron, moving on...")
}
return
})
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionElectron",
"(",
"ctx",
"context",
".",
"Context",
",",
"paths",
"Paths",
",",
"s",
"ProvisionStatus",
",",
"appName",
",",
"os",
",",
"arch",
"string",
")",
"error",
"{",
"return",
"p",
".",
"pr... | // provisionElectron provisions electron | [
"provisionElectron",
"provisions",
"electron"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L151-L163 |
164,288 | asticode/go-astilectron | provisioner.go | provisionPackage | func (p *defaultProvisioner) provisionPackage(ctx context.Context, paths Paths, s *ProvisionStatusPackage, m mover, name, version, pathUnzipSrc, pathDirectory string, finish func() error) (err error) {
// Package has already been provisioned
if s != nil && s.Version == version {
astilog.Debugf("%s has already been provisioned to version %s, moving on...", name, version)
return
}
astilog.Debugf("Provisioning %s...", name)
// Remove previous install
astilog.Debugf("Removing directory %s", pathDirectory)
if err = os.RemoveAll(pathDirectory); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "removing %s failed", pathDirectory)
}
// Move
if err = m(ctx, paths); err != nil {
return errors.Wrapf(err, "moving %s failed", name)
}
// Create directory
astilog.Debugf("Creating directory %s", pathDirectory)
if err = os.MkdirAll(pathDirectory, 0755); err != nil {
return errors.Wrapf(err, "mkdirall %s failed", pathDirectory)
}
// Unzip
if err = Unzip(ctx, pathUnzipSrc, pathDirectory); err != nil {
return errors.Wrapf(err, "unzipping %s into %s failed", pathUnzipSrc, pathDirectory)
}
// Finish
if finish != nil {
if err = finish(); err != nil {
return errors.Wrap(err, "finishing failed")
}
}
return
} | go | func (p *defaultProvisioner) provisionPackage(ctx context.Context, paths Paths, s *ProvisionStatusPackage, m mover, name, version, pathUnzipSrc, pathDirectory string, finish func() error) (err error) {
// Package has already been provisioned
if s != nil && s.Version == version {
astilog.Debugf("%s has already been provisioned to version %s, moving on...", name, version)
return
}
astilog.Debugf("Provisioning %s...", name)
// Remove previous install
astilog.Debugf("Removing directory %s", pathDirectory)
if err = os.RemoveAll(pathDirectory); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "removing %s failed", pathDirectory)
}
// Move
if err = m(ctx, paths); err != nil {
return errors.Wrapf(err, "moving %s failed", name)
}
// Create directory
astilog.Debugf("Creating directory %s", pathDirectory)
if err = os.MkdirAll(pathDirectory, 0755); err != nil {
return errors.Wrapf(err, "mkdirall %s failed", pathDirectory)
}
// Unzip
if err = Unzip(ctx, pathUnzipSrc, pathDirectory); err != nil {
return errors.Wrapf(err, "unzipping %s into %s failed", pathUnzipSrc, pathDirectory)
}
// Finish
if finish != nil {
if err = finish(); err != nil {
return errors.Wrap(err, "finishing failed")
}
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionPackage",
"(",
"ctx",
"context",
".",
"Context",
",",
"paths",
"Paths",
",",
"s",
"*",
"ProvisionStatusPackage",
",",
"m",
"mover",
",",
"name",
",",
"version",
",",
"pathUnzipSrc",
",",
"pathDirect... | // provisionPackage provisions a package | [
"provisionPackage",
"provisions",
"a",
"package"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L166-L203 |
164,289 | asticode/go-astilectron | provisioner.go | provisionElectronFinishDarwinCopy | func (p *defaultProvisioner) provisionElectronFinishDarwinCopy(paths Paths) (err error) {
// Icon
var src, dst = paths.AppIconDarwinSrc(), filepath.Join(paths.ElectronDirectory(), "Electron.app", "Contents", "Resources", "electron.icns")
if src != "" {
astilog.Debugf("Copying %s to %s", src, dst)
if err = astios.Copy(context.Background(), src, dst); err != nil {
return errors.Wrapf(err, "copying %s to %s failed", src, dst)
}
}
return
} | go | func (p *defaultProvisioner) provisionElectronFinishDarwinCopy(paths Paths) (err error) {
// Icon
var src, dst = paths.AppIconDarwinSrc(), filepath.Join(paths.ElectronDirectory(), "Electron.app", "Contents", "Resources", "electron.icns")
if src != "" {
astilog.Debugf("Copying %s to %s", src, dst)
if err = astios.Copy(context.Background(), src, dst); err != nil {
return errors.Wrapf(err, "copying %s to %s failed", src, dst)
}
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionElectronFinishDarwinCopy",
"(",
"paths",
"Paths",
")",
"(",
"err",
"error",
")",
"{",
"// Icon",
"var",
"src",
",",
"dst",
"=",
"paths",
".",
"AppIconDarwinSrc",
"(",
")",
",",
"filepath",
".",
"J... | // provisionElectronFinishDarwinCopy copies the proper darwin files | [
"provisionElectronFinishDarwinCopy",
"copies",
"the",
"proper",
"darwin",
"files"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L234-L244 |
164,290 | asticode/go-astilectron | provisioner.go | provisionElectronFinishDarwinReplace | func (p *defaultProvisioner) provisionElectronFinishDarwinReplace(appName string, paths Paths) (err error) {
for _, p := range []string{
filepath.Join(paths.electronDirectory, "Electron.app", "Contents", "Info.plist"),
filepath.Join(paths.electronDirectory, "Electron.app", "Contents", "Frameworks", "Electron Helper.app", "Contents", "Info.plist"),
} {
// Log
astilog.Debugf("Replacing in %s", p)
// Read file
var b []byte
if b, err = ioutil.ReadFile(p); err != nil {
return errors.Wrapf(err, "reading %s failed", p)
}
// Open and truncate file
var f *os.File
if f, err = os.Create(p); err != nil {
return errors.Wrapf(err, "creating %s failed", p)
}
defer f.Close()
// Replace
astiregexp.ReplaceAll(regexpDarwinInfoPList, &b, []byte("<string>"+appName))
// Write
if _, err = f.Write(b); err != nil {
return errors.Wrapf(err, "writing to %s failed", p)
}
}
return
} | go | func (p *defaultProvisioner) provisionElectronFinishDarwinReplace(appName string, paths Paths) (err error) {
for _, p := range []string{
filepath.Join(paths.electronDirectory, "Electron.app", "Contents", "Info.plist"),
filepath.Join(paths.electronDirectory, "Electron.app", "Contents", "Frameworks", "Electron Helper.app", "Contents", "Info.plist"),
} {
// Log
astilog.Debugf("Replacing in %s", p)
// Read file
var b []byte
if b, err = ioutil.ReadFile(p); err != nil {
return errors.Wrapf(err, "reading %s failed", p)
}
// Open and truncate file
var f *os.File
if f, err = os.Create(p); err != nil {
return errors.Wrapf(err, "creating %s failed", p)
}
defer f.Close()
// Replace
astiregexp.ReplaceAll(regexpDarwinInfoPList, &b, []byte("<string>"+appName))
// Write
if _, err = f.Write(b); err != nil {
return errors.Wrapf(err, "writing to %s failed", p)
}
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionElectronFinishDarwinReplace",
"(",
"appName",
"string",
",",
"paths",
"Paths",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"[",
"]",
"string",
"{",
"filepath",
".",
... | // provisionElectronFinishDarwinReplace makes the proper replacements in the proper darwin files | [
"provisionElectronFinishDarwinReplace",
"makes",
"the",
"proper",
"replacements",
"in",
"the",
"proper",
"darwin",
"files"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L247-L277 |
164,291 | asticode/go-astilectron | provisioner.go | provisionElectronFinishDarwinRename | func (p *defaultProvisioner) provisionElectronFinishDarwinRename(appName string, paths Paths) (err error) {
var appDirectory = filepath.Join(paths.electronDirectory, appName+".app")
var frameworksDirectory = filepath.Join(appDirectory, "Contents", "Frameworks")
var helper = filepath.Join(frameworksDirectory, appName+" Helper.app")
for _, r := range []rename{
{src: filepath.Join(paths.electronDirectory, "Electron.app"), dst: appDirectory},
{src: filepath.Join(appDirectory, "Contents", "MacOS", "Electron"), dst: paths.AppExecutable()},
{src: filepath.Join(frameworksDirectory, "Electron Helper.app"), dst: filepath.Join(helper)},
{src: filepath.Join(helper, "Contents", "MacOS", "Electron Helper"), dst: filepath.Join(helper, "Contents", "MacOS", appName+" Helper")},
} {
astilog.Debugf("Renaming %s into %s", r.src, r.dst)
if err = os.Rename(r.src, r.dst); err != nil {
return errors.Wrapf(err, "renaming %s into %s failed", r.src, r.dst)
}
}
return
} | go | func (p *defaultProvisioner) provisionElectronFinishDarwinRename(appName string, paths Paths) (err error) {
var appDirectory = filepath.Join(paths.electronDirectory, appName+".app")
var frameworksDirectory = filepath.Join(appDirectory, "Contents", "Frameworks")
var helper = filepath.Join(frameworksDirectory, appName+" Helper.app")
for _, r := range []rename{
{src: filepath.Join(paths.electronDirectory, "Electron.app"), dst: appDirectory},
{src: filepath.Join(appDirectory, "Contents", "MacOS", "Electron"), dst: paths.AppExecutable()},
{src: filepath.Join(frameworksDirectory, "Electron Helper.app"), dst: filepath.Join(helper)},
{src: filepath.Join(helper, "Contents", "MacOS", "Electron Helper"), dst: filepath.Join(helper, "Contents", "MacOS", appName+" Helper")},
} {
astilog.Debugf("Renaming %s into %s", r.src, r.dst)
if err = os.Rename(r.src, r.dst); err != nil {
return errors.Wrapf(err, "renaming %s into %s failed", r.src, r.dst)
}
}
return
} | [
"func",
"(",
"p",
"*",
"defaultProvisioner",
")",
"provisionElectronFinishDarwinRename",
"(",
"appName",
"string",
",",
"paths",
"Paths",
")",
"(",
"err",
"error",
")",
"{",
"var",
"appDirectory",
"=",
"filepath",
".",
"Join",
"(",
"paths",
".",
"electronDirec... | // provisionElectronFinishDarwinRename renames the proper darwin folders | [
"provisionElectronFinishDarwinRename",
"renames",
"the",
"proper",
"darwin",
"folders"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L285-L301 |
164,292 | asticode/go-astilectron | provisioner.go | NewDisembedderProvisioner | func NewDisembedderProvisioner(d Disembedder, pathAstilectron, pathElectron string) Provisioner {
return &defaultProvisioner{
moverAstilectron: func(ctx context.Context, p Paths) (err error) {
if err = Disembed(ctx, d, pathAstilectron, p.AstilectronDownloadDst()); err != nil {
return errors.Wrapf(err, "disembedding %s into %s failed", pathAstilectron, p.AstilectronDownloadDst())
}
return
},
moverElectron: func(ctx context.Context, p Paths) (err error) {
if err = Disembed(ctx, d, pathElectron, p.ElectronDownloadDst()); err != nil {
return errors.Wrapf(err, "disembedding %s into %s failed", pathElectron, p.ElectronDownloadDst())
}
return
},
}
} | go | func NewDisembedderProvisioner(d Disembedder, pathAstilectron, pathElectron string) Provisioner {
return &defaultProvisioner{
moverAstilectron: func(ctx context.Context, p Paths) (err error) {
if err = Disembed(ctx, d, pathAstilectron, p.AstilectronDownloadDst()); err != nil {
return errors.Wrapf(err, "disembedding %s into %s failed", pathAstilectron, p.AstilectronDownloadDst())
}
return
},
moverElectron: func(ctx context.Context, p Paths) (err error) {
if err = Disembed(ctx, d, pathElectron, p.ElectronDownloadDst()); err != nil {
return errors.Wrapf(err, "disembedding %s into %s failed", pathElectron, p.ElectronDownloadDst())
}
return
},
}
} | [
"func",
"NewDisembedderProvisioner",
"(",
"d",
"Disembedder",
",",
"pathAstilectron",
",",
"pathElectron",
"string",
")",
"Provisioner",
"{",
"return",
"&",
"defaultProvisioner",
"{",
"moverAstilectron",
":",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"p"... | // NewDisembedderProvisioner creates a provisioner that can provision based on embedded data | [
"NewDisembedderProvisioner",
"creates",
"a",
"provisioner",
"that",
"can",
"provision",
"based",
"on",
"embedded",
"data"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/provisioner.go#L307-L322 |
164,293 | asticode/go-astilectron | dock.go | Bounce | func (d *Dock) Bounce(bounceType string) (id int, err error) {
if err = d.isActionable(); err != nil {
return
}
var e Event
if e, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounce, TargetID: d.id, BounceType: bounceType}, eventNameDockEventBouncing); err != nil {
return
}
if e.ID != nil {
id = *e.ID
}
return
} | go | func (d *Dock) Bounce(bounceType string) (id int, err error) {
if err = d.isActionable(); err != nil {
return
}
var e Event
if e, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounce, TargetID: d.id, BounceType: bounceType}, eventNameDockEventBouncing); err != nil {
return
}
if e.ID != nil {
id = *e.ID
}
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"Bounce",
"(",
"bounceType",
"string",
")",
"(",
"id",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"var... | // Bounce bounces the dock | [
"Bounce",
"bounces",
"the",
"dock"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L40-L52 |
164,294 | asticode/go-astilectron | dock.go | BounceDownloads | func (d *Dock) BounceDownloads(filePath string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounceDownloads, TargetID: d.id, FilePath: filePath}, eventNameDockEventDownloadsBouncing)
return
} | go | func (d *Dock) BounceDownloads(filePath string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdBounceDownloads, TargetID: d.id, FilePath: filePath}, eventNameDockEventDownloadsBouncing)
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"BounceDownloads",
"(",
"filePath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
... | // BounceDownloads bounces the downloads part of the dock | [
"BounceDownloads",
"bounces",
"the",
"downloads",
"part",
"of",
"the",
"dock"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L55-L61 |
164,295 | asticode/go-astilectron | dock.go | CancelBounce | func (d *Dock) CancelBounce(id int) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdCancelBounce, TargetID: d.id, ID: PtrInt(id)}, eventNameDockEventBouncingCancelled)
return
} | go | func (d *Dock) CancelBounce(id int) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdCancelBounce, TargetID: d.id, ID: PtrInt(id)}, eventNameDockEventBouncingCancelled)
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"CancelBounce",
"(",
"id",
"int",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"sy... | // CancelBounce cancels the dock bounce | [
"CancelBounce",
"cancels",
"the",
"dock",
"bounce"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L64-L70 |
164,296 | asticode/go-astilectron | dock.go | Hide | func (d *Dock) Hide() (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdHide, TargetID: d.id}, eventNameDockEventHidden)
return
} | go | func (d *Dock) Hide() (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdHide, TargetID: d.id}, eventNameDockEventHidden)
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"Hide",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"synchronousEvent",
"(",
... | // Hide hides the dock | [
"Hide",
"hides",
"the",
"dock"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L73-L79 |
164,297 | asticode/go-astilectron | dock.go | NewMenu | func (d *Dock) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(d.ctx, d.id, i, d.c, d.d, d.i, d.w)
} | go | func (d *Dock) NewMenu(i []*MenuItemOptions) *Menu {
return newMenu(d.ctx, d.id, i, d.c, d.d, d.i, d.w)
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"NewMenu",
"(",
"i",
"[",
"]",
"*",
"MenuItemOptions",
")",
"*",
"Menu",
"{",
"return",
"newMenu",
"(",
"d",
".",
"ctx",
",",
"d",
".",
"id",
",",
"i",
",",
"d",
".",
"c",
",",
"d",
".",
"d",
",",
"d",
... | // NewMenu creates a new dock menu | [
"NewMenu",
"creates",
"a",
"new",
"dock",
"menu"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L82-L84 |
164,298 | asticode/go-astilectron | dock.go | SetBadge | func (d *Dock) SetBadge(badge string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetBadge, TargetID: d.id, Badge: badge}, eventNameDockEventBadgeSet)
return
} | go | func (d *Dock) SetBadge(badge string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetBadge, TargetID: d.id, Badge: badge}, eventNameDockEventBadgeSet)
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"SetBadge",
"(",
"badge",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"... | // SetBadge sets the badge of the dock | [
"SetBadge",
"sets",
"the",
"badge",
"of",
"the",
"dock"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L87-L93 |
164,299 | asticode/go-astilectron | dock.go | SetIcon | func (d *Dock) SetIcon(image string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetIcon, TargetID: d.id, Image: image}, eventNameDockEventIconSet)
return
} | go | func (d *Dock) SetIcon(image string) (err error) {
if err = d.isActionable(); err != nil {
return
}
_, err = synchronousEvent(d.c, d, d.w, Event{Name: eventNameDockCmdSetIcon, TargetID: d.id, Image: image}, eventNameDockEventIconSet)
return
} | [
"func",
"(",
"d",
"*",
"Dock",
")",
"SetIcon",
"(",
"image",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"d",
".",
"isActionable",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"s... | // SetIcon sets the icon of the dock | [
"SetIcon",
"sets",
"the",
"icon",
"of",
"the",
"dock"
] | 5d5f1436743467b9a7cd9e9c90dc4ab47b96be90 | https://github.com/asticode/go-astilectron/blob/5d5f1436743467b9a7cd9e9c90dc4ab47b96be90/dock.go#L96-L102 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.