Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ go install github.com/wailsapp/wails/v2/cmd/wails@latest
make install # builds and installs to ~/.local (binary, .desktop file, icon)
```

### Updating

dbro checks for a new release on startup (turn it off in Settings) and offers to update itself: it downloads the release for your platform, checks its SHA-256 and replaces itself, and the new version runs after a restart. `dbro update` does the same from a terminal. A copy installed by a package manager (under `/usr`) is left to that package manager.

## Themes

Seven built-in themes, light or dark from your system, live [Omarchy](https://omarchy.org) sync, and your own themes as TOML files. See [docs/themes.md](docs/themes.md) for the gallery and the theme format.
Expand Down
31 changes: 31 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"
Expand All @@ -23,6 +24,7 @@ import (
"github.com/ExeQue/dbro/internal/sqllog"
"github.com/ExeQue/dbro/internal/sshtunnel"
"github.com/ExeQue/dbro/internal/theme"
"github.com/ExeQue/dbro/internal/update"
)

// App is bound to the frontend; every exported method is callable from TypeScript.
Expand Down Expand Up @@ -849,3 +851,32 @@ func (a *App) TableInfo(name, database, schema, table string) ([]db.InfoItem, er
}
return c.TableInfo(a.ctx, database, schema, table)
}

// CheckUpdate looks up the latest release on GitHub.
func (a *App) CheckUpdate() (update.Release, error) {
return update.Latest(a.ctx, version)
}

// InstallUpdate replaces dbro with the latest release; it runs from the next start.
func (a *App) InstallUpdate() (string, error) {
r, err := update.Latest(a.ctx, version)
if err != nil {
return "", err
}
if !r.Available {
return "", fmt.Errorf("dbro %s is the latest version", version)
}
return r.Version, update.Install(a.ctx, r)
}

// Restart starts the installed version and closes this one.
func (a *App) Restart() error {
if a.headless != nil {
return errors.New("restart dbro serve to run the new version")
}
if err := exec.Command(update.Executable(), os.Args[1:]...).Start(); err != nil {
return err
}
runtime.Quit(a.ctx)
return nil
}
41 changes: 39 additions & 2 deletions frontend/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { modal, confirm, prompt, toast, showError, errorMessage, field, type Men
import { state, emit, connInfo, dialect, quoteIdent, displayName, type Selection } from './state';
import { applyTheme, currentTheme, applyFont } from './theme';
import type { Tree } from './tree';
import { config, db } from '../wailsjs/go/models';
import { config, db, type update } from '../wailsjs/go/models';
import { BrowserOpenURL } from '../wailsjs/runtime/runtime';

let tree: Tree;
export function bindTree(t: Tree) {
Expand Down Expand Up @@ -492,6 +493,7 @@ export async function settings() {
const lerdConnect = h('input', { type: 'checkbox', checked: boot.settings.lerdAutoConnect });
const font = h('input', { class: 'input', value: boot.settings.font ?? '', placeholder: 'monospace (from fontconfig)' });
const timeout = h('input', { class: 'input', value: boot.settings.queryTimeout, inputmode: 'numeric' });
const updates = h('input', { type: 'checkbox', checked: boot.settings.checkUpdates });
const exe = boot.executable || 'dbro';
const mcpCmd = `claude mcp add dbro -- ${exe} mcp`;
const r = await modal('Settings', h('div', { class: 'form' },
Expand All @@ -507,12 +509,16 @@ export async function settings() {
h('div', { class: 'form-row' }, field('Font', font), field('Agent query timeout (seconds)', timeout)),
h('label', { class: 'check' }, lerd, ' Show lerd database services in the tree'),
h('label', { class: 'check' }, lerdConnect, ' Connect to lerd on startup'),
h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
h('label', { class: 'check' }, updates, ' Check for updates on startup'),
h('span', { class: 'muted' }, `dbro ${boot.version}`),
h('button', { type: 'button', class: 'btn small', onclick: () => checkUpdate(true) }, 'Check now')),
h('fieldset', {}, h('legend', {}, 'MCP server for agents'),
h('p', { class: 'muted' }, 'Agents get read-only access to your saved connections. Writes need "Allow agents to change data" on the connection.'),
h('div', { style: { display: 'flex', gap: '6px' } }, h('code', { style: { flex: '1', userSelect: 'all' } }, mcpCmd), h('button', { type: 'button', class: 'btn small', onclick: () => { Go.CopyText(mcpCmd); toast('Copied'); } }, 'Copy')),
h('p', { class: 'muted' }, 'Over HTTP: ', h('code', {}, `${exe} mcp --http`), ' or the headless ', h('code', {}, `${exe} serve`), ' (also at /mcp).')),
), [{ label: 'Cancel' }, { label: 'Save', primary: true, action: async () => {
const s = { ...boot.settings, lerd: lerd.checked, lerdAutoConnect: lerdConnect.checked, font: font.value.trim(), queryTimeout: Number(timeout.value) || 30 };
const s = { ...boot.settings, lerd: lerd.checked, lerdAutoConnect: lerdConnect.checked, checkUpdates: updates.checked, font: font.value.trim(), queryTimeout: Number(timeout.value) || 30 };
await Go.SaveSettings(s as any);
const t = await Go.SetTheme(chosen);
applyTheme(t);
Expand Down Expand Up @@ -559,3 +565,34 @@ export async function generateSQL(sel: Selection, kind: 'SELECT' | 'INSERT' | 'U
showError(e);
}
}

// ---- updates ----

/** checkUpdate looks for a newer release; quiet on startup, with feedback when asked for. */
export async function checkUpdate(manual = false) {
try {
const r = await Go.CheckUpdate();
if (r.available) emit('updateAvailable', r);
if (manual) {
if (r.available) await installUpdate(r);
else toast(`dbro ${state.boot.version} is the latest version`);
}
} catch (e) {
if (manual) showError(e, 'Could not check for updates');
}
}

export async function installUpdate(r: update.Release) {
const notes = h('a', { href: r.url, onclick: (e: Event) => { e.preventDefault(); BrowserOpenURL(r.url); } }, 'Release notes');
if (!r.installable) {
await modal(`dbro ${r.version} is available`, h('div', {}, h('p', {}, `You have ${state.boot.version}. dbro cannot update itself here: ${r.reason}.`), h('p', {}, notes)));
return;
}
const ok = await modal(`dbro ${r.version} is available`, h('div', {}, h('p', {}, `You have ${state.boot.version}. dbro downloads the new version, checks it and replaces itself.`), h('p', {}, notes)),
[{ label: 'Later' }, { label: 'Update', primary: true, action: () => Go.InstallUpdate() }]);
if (ok !== 1) return;
emit('updateInstalled', r);
if (await confirm('Update installed', `dbro ${r.version} is installed. Restart now to use it?`, 'Restart')) {
await Go.Restart().catch((e) => showError(e, 'Could not restart'));
}
}
19 changes: 17 additions & 2 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { QueryTab } from './query';
import { dialogOpen, confirm, toast, showError } from './dialogs';
import * as actions from './actions';
import { logo } from './logo';
import type { theme } from '../wailsjs/go/models';
import type { theme, update } from '../wailsjs/go/models';

type TabId = 'data' | 'structure' | string;

Expand All @@ -29,6 +29,8 @@ const content = h('div', { class: 'pane' });
const logBox = h('section', { class: 'log', 'aria-label': 'SQL log' });
const statusLeft = h('span');
const statusRight = h('span', { class: 'right' });
const versionButton = h('button', { type: 'button', class: 'btn small', title: 'Check for updates', onclick: () => (pendingUpdate ? actions.installUpdate(pendingUpdate) : actions.checkUpdate(true)) });
let pendingUpdate: update.Release | null = null;

function layout() {
const sidebar = h('div', { class: 'sidebar' }, tree.root);
Expand Down Expand Up @@ -60,7 +62,7 @@ function layout() {
toolbar,
h('div', { class: 'body' }, sidebar, resizer, main),
logBox,
h('footer', { class: 'statusbar' }, statusLeft, h('span', { class: 'right' }, statusRight, logToggle)));
h('footer', { class: 'statusbar' }, statusLeft, h('span', { class: 'right' }, statusRight, versionButton, logToggle)));
}

function renderTabs() {
Expand Down Expand Up @@ -199,6 +201,16 @@ on('reloadData', () => data.load());
on('schemaChanged', () => {
if (state.selection?.table) data.show(state.selection, true);
});
on('updateAvailable', (r: update.Release) => {
pendingUpdate = r;
versionButton.textContent = `Update to ${r.version}`;
versionButton.classList.add('primary');
});
on('updateInstalled', (r: update.Release) => {
pendingUpdate = null;
versionButton.textContent = `${r.version} on restart`;
versionButton.classList.remove('primary');
});
on('themeChanged', (t: theme.Theme) => {
state.boot.theme = t;
updateStatus();
Expand Down Expand Up @@ -261,6 +273,7 @@ async function commandPalette() {
{ label: 'Refresh', icon: 'refresh', shortcut: 'F5', run: () => refresh() },
{ label: 'Settings', icon: 'gear', shortcut: 'Ctrl+,', run: () => actions.settings() },
{ label: 'Toggle SQL log', run: () => logBox.classList.toggle('collapsed') },
{ label: 'Check for updates', icon: 'refresh', run: () => actions.checkUpdate(true) },
];
if (sel && (sel.kind === 'table' || sel.kind === 'view')) {
const t = sel.table!;
Expand Down Expand Up @@ -327,6 +340,8 @@ async function start() {
showTab('data');
updateStatus();
if (state.boot.askOmarchy) actions.askOmarchy();
versionButton.textContent = state.boot.version;
if (state.boot.settings.checkUpdates && state.boot.version !== 'dev') actions.checkUpdate();
}

start();
Expand Down
7 changes: 7 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {theme} from '../models';
import {db} from '../models';
import {main} from '../models';
import {update} from '../models';
import {config} from '../models';
import {history} from '../models';

Expand All @@ -16,6 +17,8 @@ export function Browse(arg1:string,arg2:string,arg3:string,arg4:string,arg5:stri

export function CancelQuery(arg1:string):Promise<void>;

export function CheckUpdate():Promise<update.Release>;

export function Clone(arg1:string,arg2:string,arg3:Array<db.TableInfo>,arg4:string,arg5:string,arg6:string,arg7:db.CloneOptions):Promise<string>;

export function CloseQueryTab(arg1:string,arg2:string,arg3:string):Promise<void>;
Expand Down Expand Up @@ -62,6 +65,8 @@ export function ImportCSV(arg1:string,arg2:string,arg3:string,arg4:string,arg5:s

export function ImportSQL(arg1:string,arg2:string,arg3:boolean):Promise<string>;

export function InstallUpdate():Promise<string>;

export function ListConnections():Promise<main.ConnectionList>;

export function ListThemes():Promise<Array<theme.Info>>;
Expand All @@ -86,6 +91,8 @@ export function ProvidePassword(arg1:string,arg2:string,arg3:string,arg4:boolean

export function ResolveLaravel(arg1:string):Promise<config.Connection>;

export function Restart():Promise<void>;

export function RoutineSource(arg1:string,arg2:string,arg3:db.Routine):Promise<string>;

export function RunQuery(arg1:string,arg2:string,arg3:string,arg4:string,arg5:number,arg6:Record<string, any>):Promise<main.QueryRun>;
Expand Down
12 changes: 12 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function CancelQuery(arg1) {
return window['go']['main']['App']['CancelQuery'](arg1);
}

export function CheckUpdate() {
return window['go']['main']['App']['CheckUpdate']();
}

export function Clone(arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
return window['go']['main']['App']['Clone'](arg1, arg2, arg3, arg4, arg5, arg6, arg7);
}
Expand Down Expand Up @@ -114,6 +118,10 @@ export function ImportSQL(arg1, arg2, arg3) {
return window['go']['main']['App']['ImportSQL'](arg1, arg2, arg3);
}

export function InstallUpdate() {
return window['go']['main']['App']['InstallUpdate']();
}

export function ListConnections() {
return window['go']['main']['App']['ListConnections']();
}
Expand Down Expand Up @@ -162,6 +170,10 @@ export function ResolveLaravel(arg1) {
return window['go']['main']['App']['ResolveLaravel'](arg1);
}

export function Restart() {
return window['go']['main']['App']['Restart']();
}

export function RoutineSource(arg1, arg2, arg3) {
return window['go']['main']['App']['RoutineSource'](arg1, arg2, arg3);
}
Expand Down
27 changes: 27 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export namespace config {
lerdAutoConnect: boolean;
firstRunDone: boolean;
queryTimeout: number;
checkUpdates: boolean;

static createFrom(source: any = {}) {
return new Settings(source);
Expand All @@ -107,6 +108,7 @@ export namespace config {
this.lerdAutoConnect = source["lerdAutoConnect"];
this.firstRunDone = source["firstRunDone"];
this.queryTimeout = source["queryTimeout"];
this.checkUpdates = source["checkUpdates"];
}
}

Expand Down Expand Up @@ -710,3 +712,28 @@ export namespace theme {

}

export namespace update {

export class Release {
version: string;
url: string;
available: boolean;
installable: boolean;
reason?: string;

static createFrom(source: any = {}) {
return new Release(source);
}

constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.version = source["version"];
this.url = source["url"];
this.available = source["available"];
this.installable = source["installable"];
this.reason = source["reason"];
}
}

}

3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Settings struct {
LerdConnect bool `toml:"lerd_auto_connect" json:"lerdAutoConnect"` // connect to them on startup
FirstRunDone bool `toml:"first_run_done,omitempty" json:"firstRunDone"`
QueryTimeout int `toml:"query_timeout,omitempty" json:"queryTimeout"` // seconds
CheckUpdates bool `toml:"check_updates" json:"checkUpdates"` // look for a new release on startup
}

// Dir returns the config directory, honoring DBRO_CONFIG_DIR and XDG_CONFIG_HOME.
Expand Down Expand Up @@ -121,7 +122,7 @@ func SaveConnections(conns []Connection) error {

// LoadSettings reads config.toml with defaults for missing values.
func LoadSettings() (Settings, error) {
s := Settings{Lerd: true, LerdConnect: true, QueryTimeout: 30}
s := Settings{Lerd: true, LerdConnect: true, QueryTimeout: 30, CheckUpdates: true}
_, err := toml.DecodeFile(filepath.Join(Dir(), "config.toml"), &s)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return s, fmt.Errorf("read config.toml: %w", err)
Expand Down
Loading
Loading