Skip to content

Commit 3a5f937

Browse files
Mahyar DarvishiMahyar Darvishi
authored andcommitted
Removed some unnecessery try/catches
1 parent 6d75a0e commit 3a5f937

3 files changed

Lines changed: 50 additions & 85 deletions

File tree

yetanotherradio@io.github.buddysirjava/modules/metadataDisplay.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export function createMetadataItem(playPauseCallback, stopCallback, recordCallba
242242
item._playPauseBtn = playPauseBtn;
243243
item._copyTrackBtn = copyTrackBtn;
244244
item._recordBtn = recordBtn;
245+
item._recordBlinkId = 0;
246+
247+
// Defensive teardown: stop blink regardless of recording event flow.
248+
item.connect('destroy', () => {
249+
_stopRecordBlink(item);
250+
});
245251

246252
return item;
247253
}

yetanotherradio@io.github.buddysirjava/prefs.js

Lines changed: 42 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,12 @@ const AddStationsPage = GObject.registerClass(
688688
return;
689689
}
690690

691-
try {
692-
this._stations.push(entry);
693-
this._stations = saveStations(this._stations);
694-
this._manualNameRow.text = '';
695-
this._manualUrlRow.text = '';
696-
if (this._refreshCallback) {
697-
this._refreshCallback(this._stations);
698-
}
699-
} catch (error) {
700-
logError(error, 'Failed to save manual station');
691+
this._stations.push(entry);
692+
this._stations = saveStations(this._stations);
693+
this._manualNameRow.text = '';
694+
this._manualUrlRow.text = '';
695+
if (this._refreshCallback) {
696+
this._refreshCallback(this._stations);
701697
}
702698
}
703699
});
@@ -722,11 +718,7 @@ const RecordingsPage = GObject.registerClass(
722718
this.add(this._group);
723719

724720
connectRecordingsDirChanged(this._settings, () => {
725-
try {
726-
this.refresh();
727-
} catch (error) {
728-
logError(error, 'Failed to refresh recordings page');
729-
}
721+
this.refresh();
730722
});
731723

732724
const refreshIfVisible = () => {
@@ -752,11 +744,7 @@ const RecordingsPage = GObject.registerClass(
752744

753745
_clearContentRows() {
754746
for (const row of this._contentRows) {
755-
try {
756-
this._group.remove(row);
757-
} catch (error) {
758-
logError(error, 'Failed to remove recordings row');
759-
}
747+
this._group.remove(row);
760748
}
761749
this._contentRows = [];
762750
}
@@ -1239,13 +1227,8 @@ const GeneralSettingsPage = GObject.registerClass(
12391227
if (!path)
12401228
return;
12411229

1242-
try {
1243-
this._settings.set_string('recordings-directory', path);
1244-
this._showToast(_('Recordings folder updated'));
1245-
} catch (error) {
1246-
logError(error, 'Failed to save recordings folder setting');
1247-
this._showToast(_('Could not save recordings folder setting'));
1248-
}
1230+
this._settings.set_string('recordings-directory', path);
1231+
this._showToast(_('Recordings folder updated'));
12491232
});
12501233

12511234
const window = this.get_root();
@@ -1256,13 +1239,8 @@ const GeneralSettingsPage = GObject.registerClass(
12561239
}
12571240

12581241
_resetRecordingsFolder() {
1259-
try {
1260-
this._settings.set_string('recordings-directory', '');
1261-
this._showToast(_('Using default recordings folder'));
1262-
} catch (error) {
1263-
logError(error, 'Failed to reset recordings folder setting');
1264-
this._showToast(_('Could not reset recordings folder setting'));
1265-
}
1242+
this._settings.set_string('recordings-directory', '');
1243+
this._showToast(_('Using default recordings folder'));
12661244
}
12671245

12681246
_showToast(title, timeout = 3) {
@@ -1276,46 +1254,41 @@ const GeneralSettingsPage = GObject.registerClass(
12761254
}
12771255

12781256
_exportStations() {
1279-
try {
1280-
const json = JSON.stringify(this._stations, null, 2);
1281-
const jsonBytes = new TextEncoder().encode(json);
1282-
const fileChooser = new Gtk.FileChooserNative({
1283-
title: _('Export Stations'),
1284-
action: Gtk.FileChooserAction.SAVE,
1285-
accept_label: _('Save'),
1286-
});
1257+
const json = JSON.stringify(this._stations, null, 2);
1258+
const jsonBytes = new TextEncoder().encode(json);
1259+
const fileChooser = new Gtk.FileChooserNative({
1260+
title: _('Export Stations'),
1261+
action: Gtk.FileChooserAction.SAVE,
1262+
accept_label: _('Save'),
1263+
});
12871264

1288-
fileChooser.set_current_name('radio-stations.json');
1289-
fileChooser.connect('response', (dialog, response) => {
1290-
if (response === Gtk.ResponseType.ACCEPT) {
1291-
const file = fileChooser.get_file();
1292-
if (file) {
1293-
try {
1294-
file.replace_contents(
1295-
jsonBytes,
1296-
null,
1297-
false,
1298-
Gio.FileCreateFlags.REPLACE_DESTINATION,
1299-
null
1300-
);
1301-
this._showToast(_('Stations exported successfully'));
1302-
} catch (error) {
1303-
logError(error, 'Export failed');
1304-
this._showToast(_('Failed to export stations'));
1305-
}
1265+
fileChooser.set_current_name('radio-stations.json');
1266+
fileChooser.connect('response', (dialog, response) => {
1267+
if (response === Gtk.ResponseType.ACCEPT) {
1268+
const file = fileChooser.get_file();
1269+
if (file) {
1270+
try {
1271+
file.replace_contents(
1272+
jsonBytes,
1273+
null,
1274+
false,
1275+
Gio.FileCreateFlags.REPLACE_DESTINATION,
1276+
null
1277+
);
1278+
this._showToast(_('Stations exported successfully'));
1279+
} catch (error) {
1280+
logError(error, 'Export failed');
1281+
this._showToast(_('Failed to export stations'));
13061282
}
13071283
}
1308-
});
1309-
1310-
const window = this.get_root();
1311-
if (window && window instanceof Gtk.Window) {
1312-
fileChooser.set_transient_for(window);
13131284
}
1314-
fileChooser.show();
1315-
} catch (error) {
1316-
logError(error, 'Export failed');
1317-
this._showToast(_('Failed to export stations'));
1285+
});
1286+
1287+
const window = this.get_root();
1288+
if (window && window instanceof Gtk.Window) {
1289+
fileChooser.set_transient_for(window);
13181290
}
1291+
fileChooser.show();
13191292
}
13201293

13211294
_importStations() {

yetanotherradio@io.github.buddysirjava/radioUtils.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,11 @@ export function getDefaultRecordingsDir() {
2424
}
2525

2626
export function getCustomRecordingsDir(settings = null) {
27-
if (!settings)
28-
return '';
29-
30-
try {
31-
return settings.get_string('recordings-directory')?.trim() || '';
32-
} catch (error) {
33-
return '';
34-
}
27+
return settings?.get_string('recordings-directory')?.trim() || '';
3528
}
3629

3730
export function connectRecordingsDirChanged(settings, callback) {
38-
if (!settings)
39-
return 0;
40-
41-
try {
42-
return settings.connect('changed::recordings-directory', callback);
43-
} catch (error) {
44-
return 0;
45-
}
31+
return settings?.connect('changed::recordings-directory', callback) ?? 0;
4632
}
4733

4834
export function getRecordingsDir(settings = null) {

0 commit comments

Comments
 (0)