Skip to content

Add real desktop notifications and systemd autostart for Gmail tray app - #6

Draft
shrutsureja wants to merge 15 commits into
mainfrom
claude/ubuntu-email-notifications-bak0b8
Draft

shrutsureja wants to merge 15 commits into
mainfrom
claude/ubuntu-email-notifications-bak0b8

Conversation

@shrutsureja

Copy link
Copy Markdown
Owner

Summary

This branch was originally a minimal skeleton (cmd/notifier + internal/...) that only had config loading and a one-shot IMAP connection test. The ai branch had a much more complete implementation (multi-account IMAP IDLE monitoring, encrypted app-password storage, systray UI, .deb packaging), so this PR:

  • Replaces the old skeleton with the ai branch's implementation as the new base
  • Adds the one thing that implementation was missing: actual desktop popup notifications. Previously the tray only updated an unread-count badge — nothing ever called notify-send/similar for new mail. Each account's last-seen IMAP UID is now tracked in state.json so genuinely new messages (not the existing unread backlog on first run) trigger a popup showing sender + subject.
  • Adds a systemd --user unit (gmail-notifier.service) for autostart on login. The existing .desktop file's X-GNOME-Autostart-enabled=true had no effect since it lived under /usr/share/applications rather than /etc/xdg/autostart or ~/.config/autostart.
  • Updates build.sh and README.md accordingly (dependency on libnotify-bin, autostart instructions for both .deb and from-source installs).

Changes

  • state.go: track LastUID per account, add GetLastUID/SetLastUID
  • imap.go: new Refresh()/checkNewMail() that detects newly-arrived UIDs via UidFetch, fetches sender/subject, and calls back into the UI; replaces ad-hoc GetUnreadCount() call sites
  • ui.go: wires the new-mail callback to notify-send
  • gmail-notifier.service: new systemd user unit
  • build.sh: packages the systemd unit into the .deb, adds libnotify-bin dependency
  • README.md: documents notifications behavior and autostart setup

Test plan

  • go build ./..., go vet ./..., go test ./... all pass
  • gofmt -l . clean
  • Manual test on a real Ubuntu desktop: configure a Gmail App Password, confirm tray icon shows unread counts, send a test email and confirm a popup notification appears with correct sender/subject, confirm systemd unit autostarts on login

Generated by Claude Code

Copilot AI and others added 15 commits October 4, 2025 14:51
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
…-875a-bbd6a93df320

Implement complete Gmail notifier with multi-account support, IMAP IDLE, and system tray integration
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
…ld-time keys

Co-authored-by: shrutsureja <92169549+shrutsureja@users.noreply.github.com>
…-b422-eaf61a2b11cd

Add AES-256-GCM password encryption with persistent user-specific keys
The ai branch's systray app tracked unread counts but never actually
popped up a notification for new mail. Track each account's last-seen
IMAP UID in state.json so genuinely new messages (not existing unread
mail on first run) trigger a notify-send popup with sender + subject.

Also add a systemd --user unit for autostart on login, since the
existing .desktop's X-GNOME-Autostart-enabled key had no effect sitting
under /usr/share/applications (autostart requires the file to live
under /etc/xdg/autostart or ~/.config/autostart).

Copy link
Copy Markdown
Owner Author

How to test this locally on Ubuntu

1. Install build dependencies

sudo apt-get update
sudo apt-get install -y libayatana-appindicator3-dev libnotify-bin golang
  • libayatana-appindicator3-dev — needed to compile the systray icon
  • libnotify-bin — provides notify-send, which is what pops up the new-mail notification
  • golang — Go 1.21+ is fine; go.mod targets 1.24 but older toolchains that support modules will still build it

2. Get a Gmail App Password (skip if you already have one)

  1. Gmail → Settings → Forwarding and POP/IMAP → enable IMAP
  2. Google Account → Security → turn on 2-Step Verification (required for App Passwords)
  3. Google Account → Security → App passwords → generate one for "Mail" → copy the 16-character password

3. Clone this branch and build

git clone -b claude/ubuntu-email-notifications-bak0b8 https://github.com/shrutsureja/gmail-notifier.git
cd gmail-notifier
go build -o gmail-notifier

This produces a gmail-notifier binary in the current directory. go vet ./... and go test ./... should also pass clean if you want to double check.

4. Configure your account(s)

Create ~/.config/gmail-notifier/config.json (the app also auto-creates an empty one on first run if it doesn't exist):

{
  "accounts": [
    {
      "email": "your-email@gmail.com",
      "password": "your-16-char-app-password"
    }
  ]
}

Enter the App Password in plaintext here — it gets encrypted in place (AES-GCM, key at ~/.config/gmail-notifier/.encryption_key, 0600 perms) the first time the app reads/writes the config.

5. Run it

./gmail-notifier
  • A mail icon should appear in your system tray with the total unread count.
  • Clicking it shows per-account unread counts, Refresh, and Quit.
  • Logs go to ~/.config/gmail-notifier/gmail-notifier.log — useful if the tray icon doesn't show up or login fails.

Important on first run: existing unread mail in your inbox will NOT pop up a notification — that backlog is used to set the "last seen" baseline (state.json) so you don't get flooded with notifications for old mail. Only mail that arrives after that first run triggers a popup.

6. Test the actual notification

With the app running, send yourself a test email (from another account, or via curl/swaks to your monitored address) and wait for IMAP IDLE to pick it up — usually a few seconds. You should see:

  • A desktop notification via notify-send with the sender and subject
  • The tray unread count incrementing

If no popup appears but the count updates, check that a notification daemon is running (built into GNOME/KDE; minimal WMs like i3/bspwm need something like dunst) and that notify-send hello works standalone.

7. (Optional) Enable autostart

mkdir -p ~/.local/bin && cp gmail-notifier ~/.local/bin/
mkdir -p ~/.config/systemd/user
sed "s|/usr/bin/gmail-notifier|$HOME/.local/bin/gmail-notifier|" gmail-notifier.service > ~/.config/systemd/user/gmail-notifier.service
systemctl --user daemon-reload
systemctl --user enable --now gmail-notifier.service
systemctl --user status gmail-notifier.service   # confirm it's active
journalctl --user -u gmail-notifier.service -f   # tail logs

Things I couldn't verify myself

This PR was built and go build/vet/test verified in a sandboxed container without a graphical session, so I could not confirm the tray icon renders correctly or that a real notify-send popup fires end-to-end against a live Gmail inbox. That real-world check is the main thing left before merging — happy to help debug if anything doesn't behave as described above.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants