general: Use gtk_macros::spawn!()
Makes the code a tad cleaner because we're not manually getting `glib::MainContext` every time we want to spawn a future.
This commit is contained in:
parent
386b41e482
commit
d99215bfd1
4 changed files with 14 additions and 13 deletions
|
|
@ -25,6 +25,8 @@ use gtk::prelude::*;
|
|||
use gtk::subclass::prelude::*;
|
||||
use gtk::CompositeTemplate;
|
||||
|
||||
use gtk_macros::spawn;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
|
||||
use crate::widgets::LpImage;
|
||||
|
|
@ -106,8 +108,7 @@ impl LpImagePage {
|
|||
// via the file chooser portal. I'm not sure how to make this work.
|
||||
gtk::RecentManager::default().add_item(&file.uri());
|
||||
|
||||
let ctx = glib::MainContext::default();
|
||||
ctx.spawn_local(clone!(@weak obj, @weak file => async move {
|
||||
spawn!(clone!(@weak obj, @weak file => async move {
|
||||
let imp = obj.imp();
|
||||
match load_texture_from_file(&file).await {
|
||||
Ok(texture) => {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ use ashpd::WindowIdentifier;
|
|||
use once_cell::sync::Lazy;
|
||||
use std::cell::{Cell, RefCell};
|
||||
|
||||
use gtk_macros::spawn;
|
||||
|
||||
use crate::file_model::LpFileModel;
|
||||
use crate::thumbnail::Thumbnail;
|
||||
use crate::widgets::LpImagePage;
|
||||
|
|
@ -360,8 +362,7 @@ impl LpImageView {
|
|||
|
||||
pub fn set_wallpaper(&self) -> anyhow::Result<()> {
|
||||
let wallpaper = self.uri().context("No URI for current file")?;
|
||||
let ctx = glib::MainContext::default();
|
||||
ctx.spawn_local(clone!(@weak self as view => async move {
|
||||
spawn!(clone!(@weak self as view => async move {
|
||||
let id = WindowIdentifier::from_native(
|
||||
&view.native().expect("View should have a GtkNative"),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ use futures::future::{AbortHandle, Abortable};
|
|||
use once_cell::sync::Lazy;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use gtk_macros::spawn;
|
||||
|
||||
const MB: f64 = 1_000_000.0;
|
||||
const KB: f64 = 1_000.0;
|
||||
const FALLBACK: &str = "-";
|
||||
|
|
@ -186,7 +188,6 @@ impl LpPropertiesView {
|
|||
|
||||
fn build_file_info(&self, file: &gio::File) {
|
||||
let imp = self.imp();
|
||||
let ctx = glib::MainContext::default();
|
||||
|
||||
// We need to be able to cancel this future so that
|
||||
// changing files before the metadata loads does not cause
|
||||
|
|
@ -222,7 +223,7 @@ impl LpPropertiesView {
|
|||
imp.info_handle.replace(Some(handle));
|
||||
|
||||
// ...then spawn the future.
|
||||
ctx.spawn_local(async {
|
||||
spawn!(async {
|
||||
let _ = fut.await;
|
||||
});
|
||||
}
|
||||
|
|
@ -239,7 +240,6 @@ impl LpPropertiesView {
|
|||
|
||||
fn build_dimensions(&self, info: &gio::FileInfo, file: &gio::File) {
|
||||
let imp = self.imp();
|
||||
let ctx = glib::MainContext::default();
|
||||
|
||||
// Here we do the same thing we do for the rest of the file info.
|
||||
let (handle, reg) = AbortHandle::new_pair();
|
||||
|
|
@ -281,7 +281,7 @@ impl LpPropertiesView {
|
|||
|
||||
imp.dimensions_handle.replace(Some(handle));
|
||||
|
||||
ctx.spawn_local(async {
|
||||
spawn!(async {
|
||||
let _ = fut.await;
|
||||
});
|
||||
}
|
||||
|
|
@ -298,9 +298,7 @@ impl LpPropertiesView {
|
|||
.and_then(|f| f.peek_path())
|
||||
.and_then(|p| std::fs::File::open(p).ok())
|
||||
{
|
||||
let ctx = glib::MainContext::default();
|
||||
|
||||
ctx.spawn_local(clone!(@weak self as view => async move {
|
||||
spawn!(clone!(@weak self as view => async move {
|
||||
let id = WindowIdentifier::from_native(&view.native().expect("No GtkNative for view")).await;
|
||||
if let Err(e) = open_uri::open_directory(&id, &directory).await {
|
||||
log::error!("Could not open parent directory: {e}");
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ use gtk::CompositeTemplate;
|
|||
use ashpd::desktop::open_uri;
|
||||
use ashpd::WindowIdentifier;
|
||||
|
||||
use gtk_macros::spawn;
|
||||
|
||||
use crate::config;
|
||||
use crate::util;
|
||||
use crate::widgets::{LpImageView, LpPropertiesView};
|
||||
|
|
@ -253,7 +255,6 @@ impl LpWindow {
|
|||
|
||||
fn open_with(&self) {
|
||||
let imp = self.imp();
|
||||
let ctx = glib::MainContext::default();
|
||||
|
||||
if let Some(file) = imp
|
||||
.image_view
|
||||
|
|
@ -261,7 +262,7 @@ impl LpWindow {
|
|||
.and_then(|f| f.peek_path())
|
||||
.and_then(|p| std::fs::File::open(p).ok())
|
||||
{
|
||||
ctx.spawn_local(clone!(@weak self as win => async move {
|
||||
spawn!(clone!(@weak self as win => async move {
|
||||
if let Err(e) =
|
||||
open_uri::open_file(&WindowIdentifier::from_native(&win).await, &file, true, true).await
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue