Use a custom GtkApplication instead of GtkApplication direct
This commit is contained in:
parent
a0a78c95f7
commit
459fed5cc6
@ -9,7 +9,6 @@ chrono = "0.4.6"
|
|||||||
crossbeam-channel = "0.3.8"
|
crossbeam-channel = "0.3.8"
|
||||||
gdk = "0.11.0"
|
gdk = "0.11.0"
|
||||||
gdk-pixbuf = "0.7.0"
|
gdk-pixbuf = "0.7.0"
|
||||||
glib = "0.8.0"
|
|
||||||
gst = { version = "0.14.0", package = "gstreamer" }
|
gst = { version = "0.14.0", package = "gstreamer" }
|
||||||
gst-player = { version = "0.14.0", package = "gstreamer-player" }
|
gst-player = { version = "0.14.0", package = "gstreamer-player" }
|
||||||
humansize = "1.1.0"
|
humansize = "1.1.0"
|
||||||
@ -28,13 +27,18 @@ serde_json = "1.0.39"
|
|||||||
# html2text = "0.1.8"
|
# html2text = "0.1.8"
|
||||||
html2text = { git = "https://github.com/jugglerchris/rust-html2text" }
|
html2text = { git = "https://github.com/jugglerchris/rust-html2text" }
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies.glib]
|
||||||
|
features = ["subclassing"]
|
||||||
|
version = "0.8.0"
|
||||||
|
|
||||||
[dependencies.gettext-rs]
|
[dependencies.gettext-rs]
|
||||||
git = "https://github.com/danigm/gettext-rs"
|
git = "https://github.com/danigm/gettext-rs"
|
||||||
branch = "no-gettext"
|
branch = "no-gettext"
|
||||||
features = ["gettext-system"]
|
features = ["gettext-system"]
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
features = ["v3_24"]
|
features = ["v3_24", "subclassing"]
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[dependencies.gio]
|
[dependencies.gio]
|
||||||
|
|||||||
@ -20,8 +20,13 @@
|
|||||||
|
|
||||||
#![allow(new_without_default)]
|
#![allow(new_without_default)]
|
||||||
|
|
||||||
use gio::{self, prelude::*, ActionMapExt, SettingsExt};
|
use glib;
|
||||||
use glib::{self, Variant};
|
use glib::subclass;
|
||||||
|
use glib::subclass::prelude::*;
|
||||||
|
use glib::translate::*;
|
||||||
|
use glib::{glib_object_impl, glib_object_subclass, glib_object_wrapper, glib_wrapper, Variant};
|
||||||
|
|
||||||
|
use gio::{self, prelude::*, ActionMapExt, ApplicationFlags, SettingsExt};
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
@ -43,11 +48,56 @@ use crate::widgets::show_menu::{mark_all_notif, remove_show_notif, ShowMenu};
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::config::{APP_ID, LOCALEDIR};
|
use crate::config::{APP_ID, LOCALEDIR};
|
||||||
use crate::i18n::i18n;
|
use crate::i18n::i18n;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct AppState {
|
||||||
|
some_window: gtk::Window,
|
||||||
|
some_label: gtk::Label,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HmdApplicationPrivate {
|
||||||
|
state: Mutex<Option<AppState>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectSubclass for HmdApplicationPrivate {
|
||||||
|
const NAME: &'static str = "HmdApplication";
|
||||||
|
type ParentType = gtk::Application;
|
||||||
|
type Instance = subclass::simple::InstanceStruct<Self>;
|
||||||
|
type Class = subclass::simple::ClassStruct<Self>;
|
||||||
|
|
||||||
|
glib_object_subclass!();
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state: Mutex::new(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for HmdApplicationPrivate {
|
||||||
|
glib_object_impl!();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl gio::subclass::prelude::ApplicationImpl for HmdApplicationPrivate {
|
||||||
|
fn activate(&self, app: &gio::Application) {
|
||||||
|
println!("activated!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl gtk::subclass::application::GtkApplicationImpl for HmdApplicationPrivate {}
|
||||||
|
|
||||||
|
glib_wrapper! {
|
||||||
|
pub struct HmdApplication(Object<subclass::simple::InstanceStruct<HmdApplicationPrivate>, subclass::simple::ClassStruct<HmdApplicationPrivate>, HmdApplicationClass>) @extends gio::Application, gtk::Application;
|
||||||
|
|
||||||
|
match fn {
|
||||||
|
get_type => || HmdApplicationPrivate::get_type().to_glib(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates an action named `name` in the action map `T with the handler `F`
|
/// Creates an action named `name` in the action map `T with the handler `F`
|
||||||
fn action<T, F>(thing: &T, name: &str, action: F)
|
fn action<T, F>(thing: &T, name: &str, action: F)
|
||||||
where
|
where
|
||||||
@ -87,7 +137,7 @@ pub(crate) enum Action {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct App {
|
pub(crate) struct App {
|
||||||
instance: gtk::Application,
|
instance: HmdApplication,
|
||||||
window: gtk::ApplicationWindow,
|
window: gtk::ApplicationWindow,
|
||||||
overlay: gtk::Overlay,
|
overlay: gtk::Overlay,
|
||||||
settings: gio::Settings,
|
settings: gio::Settings,
|
||||||
@ -100,7 +150,7 @@ pub(crate) struct App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(crate) fn new(application: >k::Application) -> Rc<Self> {
|
pub(crate) fn new(application: &HmdApplication) -> Rc<Self> {
|
||||||
let settings = gio::Settings::new("org.gnome.Podcasts");
|
let settings = gio::Settings::new("org.gnome.Podcasts");
|
||||||
|
|
||||||
let (sender, receiver) = unbounded();
|
let (sender, receiver) = unbounded();
|
||||||
@ -401,8 +451,17 @@ impl App {
|
|||||||
bindtextdomain("gnome-podcasts", LOCALEDIR);
|
bindtextdomain("gnome-podcasts", LOCALEDIR);
|
||||||
textdomain("gnome-podcasts");
|
textdomain("gnome-podcasts");
|
||||||
|
|
||||||
let application = gtk::Application::new(Some(APP_ID), gio::ApplicationFlags::empty())
|
let application = glib::Object::new(
|
||||||
.expect("Application initialization failed...");
|
HmdApplication::static_type(),
|
||||||
|
&[
|
||||||
|
("application-id", &Some(APP_ID)),
|
||||||
|
("flags", &ApplicationFlags::empty()),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.expect("Application initialization failed...")
|
||||||
|
.downcast::<HmdApplication>()
|
||||||
|
.expect("Congrats, you have won a prize for triggering an impossible outcome");
|
||||||
|
|
||||||
application.set_resource_base_path(Some("/org/gnome/Podcasts"));
|
application.set_resource_base_path(Some("/org/gnome/Podcasts"));
|
||||||
|
|
||||||
let weak_app = application.downgrade();
|
let weak_app = application.downgrade();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user