Fix export dialog that disappears
When pressing the EXPORT button, the file dialog randomly
disappears before being able to specify a place where to store
the file. This is because the Gtk.FileChooser dialog is stored
in a local variable, which, as soon as the callback where it is
created returns, becomes unreferenced, and is reclaimed by the
garbage collector (which happens at random intervals). This
bug can be reproduced just by recording something, pressing
the "export" button, and waiting.
This patch fixes it by storing the dialog as a property in the
row object.
Fix https://gitlab.gnome.org/GNOME/gnome-sound-recorder/-/merge_requests/164
Sergio Costas authored 3 years ago
Bilal Elmoussaoui committed 3 years ago
67 | 67 | let exportAction = new Gio.SimpleAction({ name: 'export' }); |
68 | 68 | exportAction.connect('activate', () => { |
69 | 69 | const window = Gio.Application.get_default().get_active_window(); |
70 | const dialog = Gtk.FileChooserNative.new(_('Export Recording'), window, Gtk.FileChooserAction.SAVE, _('_Export'), _('_Cancel')); | |
71 | dialog.set_current_name(`${this._recording.name}.${this._recording.extension}`); | |
72 | dialog.connect('response', (_dialog, response) => { | |
70 | this.exportDialog = Gtk.FileChooserNative.new(_('Export Recording'), window, Gtk.FileChooserAction.SAVE, _('_Export'), _('_Cancel')); | |
71 | this.exportDialog.set_current_name(`${this._recording.name}.${this._recording.extension}`); | |
72 | this.exportDialog.connect('response', (_dialog, response) => { | |
73 | 73 | if (response === Gtk.ResponseType.ACCEPT) { |
74 | const dest = dialog.get_file(); | |
74 | const dest = this.exportDialog.get_file(); | |
75 | 75 | this._recording.save(dest); |
76 | 76 | } |
77 | dialog.destroy(); | |
77 | this.exportDialog.destroy(); | |
78 | this.exportDialog = null; | |
78 | 79 | }); |
79 | dialog.show(); | |
80 | this.exportDialog.show(); | |
80 | 81 | }); |
81 | 82 | this.actionGroup.add_action(exportAction); |
82 | 83 |