diff --git a/README.md b/README.md index 94a6d86e..c92b4643 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Read books in style. ### Run Time Dependencies - `gjs` (>= 1.72) -- `gtk4` +- `gtk4` (>= 4.10) - `libadwaita` (`gir1.2-adw-1` in Debian-based distros) - `webkitgtk-6.0` (`gir1.2-webkit-6.0` in Debian-based distros) diff --git a/src/annotations.js b/src/annotations.js index 2fff2a6b..6c563c0f 100644 --- a/src/annotations.js +++ b/src/annotations.js @@ -400,18 +400,16 @@ GObject.registerClass({ const selected = this.selected const item = this.selected_item if (item.type === 'choose') { - const chooser = new Gtk.ColorChooserDialog({ - modal: true, - transient_for: this.root, - }) - chooser.show() - chooser.connect('response', (_, res) => { - if (res === Gtk.ResponseType.OK) { - const color = chooser.get_rgba().to_string() + new Gtk.ColorDialog().choose_rgba(this.root, null, null, (self, res) => { + try { + const color = self.choose_rgba_finish(res).to_string() this.selectColor(color) this.emit('color-changed', color) - } else this.selected = this.#prevSelected - chooser.close() + } catch (e) { + if (e instanceof Gtk.DialogError) console.debug(e) + else console.error(e) + this.selected = this.#prevSelected + } }) } else { this.emit('color-changed', item.value) @@ -521,23 +519,21 @@ export const exportAnnotations = (window, data) => { builder.get_object('ok-button').connect('clicked', () => { const { selected } = builder.get_object('format-combo') const format = ['json', 'html', 'md'][selected] - const chooser = new Gtk.FileChooserNative({ - title: _('Save File'), - action: Gtk.FileChooserAction.SAVE, - transient_for: window, - modal: true, - }) const { metadata = {} } = data const title = vprintf(_('Annotations for ā€œ%sā€'), [metadata.title]) const total = vprintf(ngettext('%d Annotation', '%d Annotations', n), [n]) - chooser.set_current_name(title + '.' + format) - chooser.show() - chooser.connect('response', (_, res) => { - if (res !== Gtk.ResponseType.ACCEPT) return - const contents = exportFunctions[format](data, title, total) - chooser.get_file().replace_contents(contents, null, false, - Gio.FileCreateFlags.REPLACE_DESTINATION, null) - }) + new Gtk.FileDialog({ initial_name: title + '.' + format }) + .save(window, null, (self, res) => { + try { + const file = self.save_finish(res) + const contents = exportFunctions[format](data, title, total) + file.replace_contents(contents, null, false, + Gio.FileCreateFlags.REPLACE_DESTINATION, null) + } catch (e) { + if (e instanceof Gtk.DialogError) console.debug(e) + else console.error(e) + } + }) dialog.close() }) builder.get_object('cancel-button').connect('clicked', () => dialog.close()) diff --git a/src/app.js b/src/app.js index 507d7447..f54dcd15 100644 --- a/src/app.js +++ b/src/app.js @@ -91,36 +91,34 @@ const ApplicationWindow = GObject.registerClass({ this.#bookViewer.open(file) } open() { - const chooser = new Gtk.FileChooserNative({ - title: _('Open File'), - action: Gtk.FileChooserAction.OPEN, - transient_for: this, - modal: true, + const dialog = new Gtk.FileDialog() + const ebooks = new Gtk.FileFilter({ + name: _('E-Book Files'), + mime_types: [ + 'application/epub+zip', + 'application/x-mobipocket-ebook', + 'application/vnd.amazon.mobi8-ebook', + 'application/x-mobi8-ebook', + 'application/x-fictionbook+xml', + 'application/x-zip-compressed-fb2', + 'application/vnd.comicbook+zip', + ], }) - - const all = new Gtk.FileFilter() - all.set_name(_('All Files')) - all.add_pattern('*') - - const ebook = new Gtk.FileFilter() - ebook.set_name(_('E-book Files')) - for (const type of [ - 'application/epub+zip', - 'application/x-mobipocket-ebook', - 'application/vnd.amazon.mobi8-ebook', - 'application/x-mobi8-ebook', - 'application/x-fictionbook+xml', - 'application/x-zip-compressed-fb2', - 'application/vnd.comicbook+zip', - ]) ebook.add_mime_type(type) - - chooser.add_filter(all) - chooser.add_filter(ebook) - chooser.set_filter(ebook) - - chooser.show() - chooser.connect('response', (_, res) => { - if (res === Gtk.ResponseType.ACCEPT) this.openFile(chooser.get_file()) + dialog.filters = new Gio.ListStore() + dialog.filters.append(new Gtk.FileFilter({ + name: _('All Files'), + patterns: ['*'], + })) + dialog.filters.append(ebooks) + dialog.default_filter = ebooks + dialog.open(this, null, (_, res) => { + try { + const file = dialog.open_finish(res) + this.openFile(file) + } catch (e) { + if (e instanceof Gtk.DialogError) console.debug(e) + else console.error(e) + } }) } showLibrary() { diff --git a/src/book-viewer.js b/src/book-viewer.js index 78d32d8a..e69f048d 100644 --- a/src/book-viewer.js +++ b/src/book-viewer.js @@ -814,20 +814,18 @@ export const BookViewer = GObject.registerClass({ new Adw.Toast({ title: _('Copied to clipboard') })) }, 'save-as': () => { - const chooser = new Gtk.FileChooserNative({ - title: _('Save File'), - action: Gtk.FileChooserAction.SAVE, - transient_for: win, - modal: true, - }) const ext = /\/([^+]*)/.exec(mimetype)?.[1] - chooser.set_current_name(win.title + (ext ? `.${ext}` : '')) - chooser.connect('response', (_, res) => { - if (res === Gtk.ResponseType.ACCEPT) chooser.get_file() - .replace_contents(bytes, null, false, - Gio.FileCreateFlags.REPLACE_DESTINATION, null) - }) - chooser.show() + new Gtk.FileDialog({ initial_name: win.title + (ext ? `.${ext}` : '') }) + .save(win, null, (self, res) => { + try { + const file = self.save_finish(res) + file.replace_contents(bytes, null, false, + Gio.FileCreateFlags.REPLACE_DESTINATION, null) + } catch (e) { + if (e instanceof Gtk.DialogError) console.debug(e) + else console.error(e) + } + }) }, }) win.add_controller(utils.addShortcuts({ 'w': () => win.close() }))