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
44 changes: 44 additions & 0 deletions lib/core/storage/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const double kDefaultConnectionsPanelWidth = 260;
const double kMinConnectionsPanelWidth = 180;
const double kMaxConnectionsPanelWidth = 500;

/// How many recently selected connections to surface on the empty workspace.
const int kMaxRecentConnections = 5;

/// Fixed tick marks on the interface scale slider (75% … 200%).
const List<double> kUiScalePresets = [
0.75,
Expand Down Expand Up @@ -119,6 +122,7 @@ abstract final class AppSettingsKeys {
static const themeAnimationEnabled = 'theme_animation_enabled';
static const uiScale = 'ui_scale';
static const connectionsPanelWidth = 'connections_panel_width';
static const recentConnectionIds = 'recent_connection_ids';
static const motionLevel = 'motion_level';
static const updateChannel = 'update_channel';
static const checkForUpdatesOnStartup = 'check_for_updates_on_startup';
Expand Down Expand Up @@ -268,6 +272,46 @@ class AppSettings {
);
}

/// Most recently selected connection ids (newest first).
Future<List<int>> getRecentConnectionIds() async {
final raw = await LocalDb.instance.getAppSetting(
AppSettingsKeys.recentConnectionIds,
);
if (raw == null || raw.isEmpty) return const [];
try {
final decoded = jsonDecode(raw);
if (decoded is! List) return const [];
final ids = <int>[];
for (final item in decoded) {
final id = item is int ? item : int.tryParse('$item');
if (id != null && id > 0 && !ids.contains(id)) {
ids.add(id);
}
if (ids.length >= kMaxRecentConnections) break;
}
return ids;
} catch (_) {
return const [];
}
}

/// Records [connectionId] as the most recently selected connection.
Future<void> recordRecentConnection(int connectionId) async {
if (connectionId <= 0) return;
final current = await getRecentConnectionIds();
final next = <int>[
connectionId,
...current.where((id) => id != connectionId),
];
if (next.length > kMaxRecentConnections) {
next.removeRange(kMaxRecentConnections, next.length);
}
await LocalDb.instance.setAppSetting(
AppSettingsKeys.recentConnectionIds,
jsonEncode(next),
);
}

/// Max SQL history rows kept per connection + database (oldest trimmed).
Future<int> getSqlHistoryMaxEntries() async {
final v = await LocalDb.instance.getAppSetting(
Expand Down
6 changes: 3 additions & 3 deletions lib/features/extensions/extension_table_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ class _ExtensionTableViewState extends material.State<ExtensionTableView> {
}

Future<void> _openDdlDialog() async {
material.showDialog<void>(
unawaited(showAppDialog<void>(
context: context,
barrierDismissible: false,
builder: (ctx) => const material.Center(
child: material.CircularProgressIndicator(),
),
);
));

try {
final meta = await ExtensionDriverSession.instance.getObjectMetadata(
Expand All @@ -198,7 +198,7 @@ class _ExtensionTableViewState extends material.State<ExtensionTableView> {
? meta.ddl!
: '-- No DDL metadata returned by extension driver for ${widget.tableName}\nSELECT * FROM $_qualifiedName LIMIT 10;';

await material.showDialog<void>(
await showAppDialog<void>(
context: context,
builder: (ctx) => material.AlertDialog(
title: material.Text(
Expand Down
8 changes: 8 additions & 0 deletions lib/features/main_screen/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class _MainScreenState extends State<MainScreen> {

void _onConnectionSelected(ConnectionRow connection) {
_workspace.value = _workspace.value.selectConnection(connection);
final id = connection.id;
if (id != null) {
unawaited(AppSettings.instance.recordRecentConnection(id));
}
}

void _onPostgresObjectSelected(
Expand Down Expand Up @@ -264,6 +268,7 @@ class _MainScreenState extends State<MainScreen> {
onRequestNewConnectionFromUrl:
_onNewDatabaseConnectionFromUrl,
onRequestOpenSqlite: _openSqliteFromHero,
onOpenConnection: _onConnectionSelected,
),
),
],
Expand Down Expand Up @@ -295,6 +300,7 @@ class _MainContentSplit extends StatefulWidget {
required this.onRequestNewConnection,
required this.onRequestNewConnectionFromUrl,
required this.onRequestOpenSqlite,
required this.onOpenConnection,
});

final GlobalKey<ConnectionsPanelState> connectionsPanelKey;
Expand Down Expand Up @@ -331,6 +337,7 @@ class _MainContentSplit extends StatefulWidget {
final VoidCallback onRequestNewConnection;
final VoidCallback onRequestNewConnectionFromUrl;
final VoidCallback onRequestOpenSqlite;
final void Function(ConnectionRow) onOpenConnection;

@override
State<_MainContentSplit> createState() => _MainContentSplitState();
Expand Down Expand Up @@ -442,6 +449,7 @@ class _MainContentSplitState extends State<_MainContentSplit> {
onRequestNewConnectionFromUrl:
widget.onRequestNewConnectionFromUrl,
onRequestOpenSqlite: widget.onRequestOpenSqlite,
onOpenConnection: widget.onOpenConnection,
);
},
),
Expand Down
Loading
Loading