Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add trayicon with ping #1

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Release
on:
push:
branches:
- main

permissions:
contents: read

jobs:
macos-build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-13, macos-14 ]
steps:
- name: Determine architecture
id: architecture
run: echo "arch=$(uname -m)" >> "${GITHUB_ENV}"

- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'

- run: go build -o ipingtray
- run: go install github.com/machinebox/appify@latest

- name: Create macOS app
run: appify -name "IPingTray" -icon docs/icon.png ipingtray

- name: Prepare DMG
run: mkdir dmg && mv IPingTray.app dmg/ && ln -s /Applications dmg/Applications

- name: Install create-dmg
run: brew install create-dmg

- name: Create DMG
run: create-dmg IPingTray.dmg dmg

- name: Upload DMG artifact
uses: actions/upload-artifact@v4
with:
name: ipingtray-${{ env.arch }}.dmg
path: IPingTray.dmg

release:
permissions:
contents: write
issues: write
pull-requests: write
needs:
- macos-build

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
cache: npm
node-version: lts/*

- name: Download binaries
uses: actions/download-artifact@v2
with:
path: dist

- name: "configure semantic-release"
run: |
npm install @semantic-release/github -D
cat <<EOF > .releaserc.yml
branches:
- 'main'
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/github'
- '@semantic-release/changelog'
- "@semantic-release/git":
message: "chore(release): v\${nextRelease.version}\n\n\${nextRelease.notes}"
- "@semantic-release/github":
assets:
- path: dist/*












publish:
- '@semantic-release/gitlab'
verifyConditions:
- '@semantic-release/gitlab'
success: false
fail: false
npmPublish: false

EOF
- run: npm clean-install
- run: corepack npm audit signatures
- run: npx [email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Pull request"

on:
pull_request:
types: [ opened, synchronize, reopened ]

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest

permissions:
contents: read
packages: read
statuses: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Super-linter
uses: super-linter/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: wagoid/commitlint-github-action@v6
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# iPingTray
A tray icon on MacOS with status of networking (ping, dns, etc.. )
<h1>
<img src="/docs/icon.png" alt="Project Logo" width="50" style="vertical-align:middle;">
IPingTray
</h1>

This program permit to have your current ping in `ms` inside your menu bar on your computer !
( cf [Screenshots](#screenshots))

This tool is useful when traveling with an unstable connection to know if you can try to work or not 🙂.

## Installation

You can download the last release of the project in the
[project releases](https://github.com/henri9813/iPingTray/releases).

## Usage

Running the app will automatically add you a tray in your menu bar.

The reference to determine your ping is the Google DNS server (`8.8.8.8`),
this option cannot be configured at this time)

### Thresholds

| Indicator | Latency Range |
|:---------:|:---------------:|
| 🟢 | Latency < 40ms |
| 🟠 | Latency < 75ms |
| 🔴 | Latency >= 75ms |


## Screenshots

![./docs/screenshot.png](/docs/screenshot.png)

## Contribution

Feel free to contribute !
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ipingtray

go 1.22.0

require (
fyne.io/systray v1.10.0
github.com/prometheus-community/pro-bing v0.4.0
)

require (
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/tevino/abool v1.2.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fyne.io/systray v1.10.0 h1:Yr1D9Lxeiw3+vSuZWPlaHC8BMjIHZXJKkek706AfYQk=
fyne.io/systray v1.10.0/go.mod h1:oM2AQqGJ1AMo4nNqZFYU8xYygSBZkW2hmdJ7n4yjedE=
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/prometheus-community/pro-bing v0.4.0 h1:YMbv+i08gQz97OZZBwLyvmmQEEzyfyrrjEaAchdy3R4=
github.com/prometheus-community/pro-bing v0.4.0/go.mod h1:b7wRYZtCcPmt4Sz319BykUU241rWLe1VFXyiyWK/dH4=
github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA=
github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
81 changes: 81 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"fmt"
"log"
"strings"

"fyne.io/systray"
probing "github.com/prometheus-community/pro-bing"
)

var pinger *probing.Pinger

func main() {
systray.Run(onReady, onExit)
}

func onReady() {
systray.SetTitle("Initializing...")

mLatencyLabel := systray.AddMenuItem("Latency", "Current Latency")
mLatencyLabel.Disable()

systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quit the app")

var err error
pinger, err = probing.NewPinger("8.8.8.8")
if err != nil {
panic(err)
}
pinger.SetLogger(nil)

// Update tray title
pinger.OnRecv = func(pkt *probing.Packet) {
latency := pkt.Rtt.Milliseconds()

switch {
case latency < 50:
systray.SetTitle(fmt.Sprintf("🟢 %d ms", latency))
case latency < 75:
systray.SetTitle(fmt.Sprintf("🟠 %d ms", latency))
default:
systray.SetTitle(fmt.Sprintf("🔴 %d ms", latency))
}

mLatencyLabel.SetTitle(fmt.Sprintf("%s: %d ms", pinger.IPAddr().String(), latency))
}

pinger.OnSendError = func(_ *probing.Packet, err error) {
systray.SetTitle("🔴 Network unavailable")

if strings.Contains(err.Error(), "sendto") {
parts := strings.Split(err.Error(), ": ")
if len(parts) >= 2 {
mLatencyLabel.SetTitle(fmt.Sprintf("8.8.8.8: %s", parts[len(parts)-1]))
return
}
}

mLatencyLabel.SetTitle(fmt.Sprintf("8.8.8.8: %s", err.Error()))
}

// Running the ping
go func() {
if err := pinger.Run(); err != nil {
log.Println("Pinger has crashed")
systray.Quit()
}
}()

// mQuit click
go func() {
<-mQuit.ClickedCh
systray.Quit()
}()
}

func onExit() {
pinger.Stop()
}