Something went wrong. Try again.
A KDE Plasma panel widget showing how much Claude Max quota is left, at a glance.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150# dipstick — plasmoid plus daemon. The two halves install together: a widget# without its daemon shows a dash, a daemon without its widget is invisible.## Two ways to install:# make install into the user's home (default)# make install DESTDIR=... PREFIX=/usr SYSTEM=1 for a package## With SYSTEM=1 neither systemd nor kpackagetool6 is touched: inside a# buildroot that would make no sense, and the package scriptlets handle it.
PREFIX ?= $(HOME)/.localDESTDIR ?=SYSTEM ?=
BINDIR ?= $(PREFIX)/binDATADIR ?= $(PREFIX)/shareLOCALEDIR ?= $(DATADIR)/locale
ifeq ($(SYSTEM),)UNITDIR ?= $(HOME)/.config/systemd/userPLASMOIDIR ?=elseUNITDIR ?= $(PREFIX)/lib/systemd/userPLASMOIDIR ?= $(DATADIR)/plasma/plasmoids/org.kde.plasma.dipstickendif
NAME := dipstickVERSION ?= 0.1.0APPLET_ID := org.kde.plasma.dipstickCATALOG := plasma_applet_$(APPLET_ID)
# GO_LDFLAGS and not LDFLAGS: the latter is a standard environment variable# that rpmbuild fills with C linker flags, and with `?=` the environment wins.# Go was handed flags it does not understand, and the build failed only inside# rpmbuild.# Pass --nodeps here if Go is not installed as an RPM (via mise, say): the# BuildRequires stays correct for a real build.RPMBUILD_FLAGS ?=
GOFLAGS ?= -trimpathGO_LDFLAGS ?= -s -w
# Compiled catalogues live inside the plasmoid package: that is where Plasma# looks for them for a third-party applet.PO := $(wildcard translations/*.po)MO := $(patsubst translations/%.po,plasmoid/contents/locale/%/LC_MESSAGES/$(CATALOG).mo,$(PO))
.PHONY: all build test vet fmt extract translations dist rpm \ install install-daemon install-plasmoid install-icon uninstall \ enable disable clean
all: build translations
build: go build $(GOFLAGS) -ldflags '$(GO_LDFLAGS)' -o dipstick ./cmd/dipstick
test: go test ./...
# gofmt -l only lists; the test turns an unformatted file into a failure, so# `make vet` is usable as a gate rather than something to read by eye.vet: go vet ./... @unformatted=$$(gofmt -l cmd internal); \ if [ -n "$$unformatted" ]; then \ echo "not gofmt-ed:"; echo "$$unformatted"; exit 1; \ fi
# Regenerate the .pot from the sources and re-align the catalogues.extract: ./translations/extract.sh
translations: $(MO)
plasmoid/contents/locale/%/LC_MESSAGES/$(CATALOG).mo: translations/%.po @mkdir -p $(dir $@) msgfmt --check -o $@ $<
install: install-daemon install-plasmoidifeq ($(SYSTEM),) @echo @echo "Installed. Two steps are left, and they are yours to take:" @echo @echo " 1. dipstick auth (OAuth login)" @echo " 2. systemctl --user enable --now dipstick" @echo @echo "Then add 'Dipstick' to the panel from the Add Widgets menu."endif
install-daemon: build install -Dm755 dipstick $(DESTDIR)$(BINDIR)/dipstick @mkdir -p $(DESTDIR)$(UNITDIR) sed 's|@BINDIR@|$(BINDIR)|' packaging/dipstick.service.in \ > $(DESTDIR)$(UNITDIR)/dipstick.service chmod 644 $(DESTDIR)$(UNITDIR)/dipstick.serviceifeq ($(SYSTEM),) systemctl --user daemon-reloadendif
# The icon goes into hicolor as well as into the package. KPackage does not# look inside contents/ for the applet icon: metadata.json's Icon is resolved# against the icon theme, so without this the widget shows a blank page in the# "Add Widgets" list. Same file in both places, one source.install-icon: install -Dm644 plasmoid/contents/icons/dipstick.svg \ $(DESTDIR)$(DATADIR)/icons/hicolor/scalable/apps/dipstick.svg
install-plasmoid: translations install-iconifeq ($(SYSTEM),) kpackagetool6 --type Plasma/Applet --install plasmoid \ || kpackagetool6 --type Plasma/Applet --upgrade plasmoidelse @mkdir -p $(DESTDIR)$(PLASMOIDIR) cp -r plasmoid/metadata.json plasmoid/contents $(DESTDIR)$(PLASMOIDIR)/ find $(DESTDIR)$(PLASMOIDIR) -type f -exec chmod 644 {} + find $(DESTDIR)$(PLASMOIDIR) -type d -exec chmod 755 {} +endif
# Touches neither the token nor the state: those are the user's data, and# uninstalling is not the moment to throw them away. Remove them by hand from# ~/.config/dipstick.uninstall: -systemctl --user disable --now dipstick -rm -f $(BINDIR)/dipstick $(UNITDIR)/dipstick.service \ $(DATADIR)/icons/hicolor/scalable/apps/dipstick.svg -systemctl --user daemon-reload -kpackagetool6 --type Plasma/Applet --remove $(APPLET_ID)
enable: systemctl --user enable --now dipstick
disable: systemctl --user disable --now dipstick
# Source tarball, as the spec expects it. Taken from HEAD, not the working# tree: a package must come from something committed.dist: git archive --format=tar.gz --prefix=$(NAME)-$(VERSION)/ \ -o $(NAME)-$(VERSION).tar.gz HEAD
# Build the RPM locally. Requires rpm-build, which is not a project# dependency: it only matters to whoever wants the package.rpm: dist rpmbuild -bb $(RPMBUILD_FLAGS) --define "_sourcedir $(CURDIR)" \ packaging/dipstick.spec
clean: rm -f dipstick $(NAME)-$(VERSION).tar.gz rm -rf plasmoid/contents/locale