Fix provider sync, left mouse event handling

This commit is contained in:
2025-07-16 17:18:43 +00:00
parent c0d2cd4599
commit d3cd06cd7f
4 changed files with 277 additions and 43 deletions

112
prefs.js
View File

@ -51,6 +51,28 @@ export default class QuotesPreferences extends ExtensionPreferences {
});
timingGroup.add(syncRow);
// Show change indicator
const indicatorRow = new Adw.SwitchRow({
title: 'Show Change Indicator',
subtitle: 'Display countdown before quote changes',
active: settings.get_boolean('show-change-indicator'),
});
timingGroup.add(indicatorRow);
// Indicator duration
const indicatorDurationRow = new Adw.SpinRow({
title: 'Indicator Duration',
subtitle: 'Countdown duration in seconds',
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 30,
step_increment: 1,
page_increment: 5,
value: settings.get_int('indicator-duration'),
}),
});
timingGroup.add(indicatorDurationRow);
// API Group
const apiGroup = new Adw.PreferencesGroup({
title: 'API Settings',
@ -58,12 +80,72 @@ export default class QuotesPreferences extends ExtensionPreferences {
});
behaviorPage.add(apiGroup);
// API URL
const apiRow = new Adw.EntryRow({
title: 'API URL',
text: settings.get_string('api-url'),
// API Providers
const apiProvidersRow = new Adw.ExpanderRow({
title: 'API Providers Configuration',
subtitle: 'Configure multiple quote providers',
});
apiGroup.add(apiRow);
const providersTextView = new Gtk.TextView({
buffer: new Gtk.TextBuffer(),
hexpand: true,
vexpand: true,
css_classes: ['card'],
monospace: true,
});
const scrolledProviders = new Gtk.ScrolledWindow({
child: providersTextView,
hexpand: true,
min_content_height: 200,
max_content_height: 400,
});
const providersContainer = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 12,
margin_top: 12,
margin_bottom: 12,
margin_start: 12,
margin_end: 12,
});
const providersLabel = new Gtk.Label({
label: 'Provider Configuration (JSON):',
xalign: 0,
});
providersContainer.append(providersLabel);
providersContainer.append(scrolledProviders);
const providersPrefsRow = new Adw.PreferencesRow({
child: providersContainer,
});
apiProvidersRow.add_row(providersPrefsRow);
apiGroup.add(apiProvidersRow);
// Load current providers
const currentProviders = settings.get_string('api-providers');
try {
const formatted = JSON.stringify(JSON.parse(currentProviders), null, 2);
providersTextView.buffer.text = formatted;
} catch (e) {
providersTextView.buffer.text = currentProviders;
}
// Save on focus out
const focusController = new Gtk.EventControllerFocus();
focusController.connect('leave', () => {
const text = providersTextView.buffer.text;
try {
JSON.parse(text); // Validate JSON
settings.set_string('api-providers', text);
} catch (e) {
console.error('Invalid JSON in providers configuration');
}
});
providersTextView.add_controller(focusController);
// Appearance Settings Page
const appearancePage = new Adw.PreferencesPage({
@ -400,12 +482,6 @@ export default class QuotesPreferences extends ExtensionPreferences {
Gio.SettingsBindFlags.DEFAULT
);
settings.bind(
'api-url',
apiRow,
'text',
Gio.SettingsBindFlags.DEFAULT
);
settings.bind(
'font-size',
@ -442,5 +518,19 @@ export default class QuotesPreferences extends ExtensionPreferences {
Gio.SettingsBindFlags.DEFAULT
);
settings.bind(
'show-change-indicator',
indicatorRow,
'active',
Gio.SettingsBindFlags.DEFAULT
);
settings.bind(
'indicator-duration',
indicatorDurationRow,
'value',
Gio.SettingsBindFlags.DEFAULT
);
}
}