Skip to content

Commit 8e723da

Browse files
committed
Update to relm 0.24 and disable video autoplay
1 parent 4b19d6e commit 8e723da

File tree

8 files changed

+286
-376
lines changed

8 files changed

+286
-376
lines changed

Cargo.lock

+99-128
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ repository = "https://github.com/antoyo/titanium"
88
version = "0.1.1"
99

1010
[dependencies]
11-
cairo-rs = "^0.15.0"
12-
gdk = "^0.15.0"
13-
gio = "^0.15.0"
14-
glib = "^0.15.0"
15-
gtk = "^0.15.0"
11+
cairo-rs = "^0.16.0"
12+
gdk = "^0.16.0"
13+
gio = "^0.16.0"
14+
glib = "^0.16.0"
15+
gtk = "^0.16.0"
1616
gumdrop = "0.4"
1717
log = "0.4"
1818
log-panics = "2"
19-
mg = "0.15"
19+
mg = "0.16"
2020
mg-settings = "^0.4.0"
2121
mg-settings-macros = "^0.4.0"
2222
number_prefix = "^0.2"
2323
open = "^1.1"
2424
password-store = "^0.4.0"
2525
percent-encoding = "^1.0.0"
26-
relm = "0.23"
27-
relm-derive = "0.23"
26+
relm = "0.24.1"
27+
relm-derive = "0.24"
2828
rusqlite = "0.27"
2929
simplelog = "0.5"
3030
syslog = "4"
3131
tempfile = "3"
3232
url = "^1.2"
33-
webkit2gtk = "^0.18.0"
33+
webkit2gtk = "^1.0.0"
3434
xdg = "^2.0"
3535
zip = "0.3"
3636

3737
# TODO: remove since https://github.com/gtk-rs/gio/issues/99 is fixed.
38-
gio-sys = "^0.15.0"
39-
glib-sys = "^0.15.0"
40-
gobject-sys = "^0.15.0"
38+
gio-sys = "^0.16.0"
39+
glib-sys = "^0.16.0"
40+
gobject-sys = "^0.16.0"
4141

4242
[dependencies.titanium-common]
4343
path = "titanium-common"
@@ -50,5 +50,5 @@ libxdo = "0.6"
5050
default = [
5151
"cairo-rs/png",
5252
"log-panics/with-backtrace",
53-
"webkit2gtk/v2_28",
53+
"webkit2gtk/v2_30",
5454
]

src/main.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
*/
2121

2222
/*
23+
* FIXME: search not working (e.g. results not focused into view) in
24+
* https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/791/diffs?view=parallel (search for
25+
* babl_format).
26+
* Could it be due to using an old webkit2gtk?
27+
* It is not due to my web extension.
28+
*
2329
* TODO: add cosmetic filter support in adblocker: https://github.com/dudik/blockit
2430
* (doc: https://github.com/brave/adblock-rust/issues/152#issuecomment-771259069)
2531
* (that probably requires a MutationObserver: https://github.com/brave/adblock-rust/issues/152#issuecomment-771046487)
@@ -435,15 +441,15 @@ mod webview;
435441

436442
use std::env::args;
437443

438-
use gio::{prelude::ApplicationExtManual, File, traits::{ApplicationExt, FileExt}};
444+
use gio::{prelude::ApplicationExtManual, File, traits::{ApplicationExt, FileExt}, ApplicationHoldGuard};
439445
use gtk::Application;
440446
use gumdrop::Options;
441447
use log::Level::Error;
442-
use relm::{EventStream, Relm, Update, UpdateNew, execute, Component};
448+
use relm::{EventStream, Relm, Update, UpdateNew, execute};
443449
use simplelog::{Config, LevelFilter, TermLogger};
444450
use syslog::Facility;
445451

446-
use app::{App, APP_NAME};
452+
use app::APP_NAME;
447453
use message_server::{create_message_server, MessageServer, Msg::{NewApp, ReleaseApp}, Privacy};
448454

449455
const INVALID_UTF8_ERROR: &str = "invalid utf-8 string";
@@ -503,12 +509,14 @@ struct RelmApp {
503509

504510
struct Model {
505511
application: Application,
512+
app_hold_guard: Option<ApplicationHoldGuard>,
506513
message_server: Option<EventStream<<MessageServer as Update>::Msg>>,
507514
}
508515

509516
#[derive(Msg)]
510517
enum Msg {
511518
Activate,
519+
AppHoldGuard(ApplicationHoldGuard),
512520
Open(Vec<File>),
513521
}
514522

@@ -520,21 +528,24 @@ impl Update for RelmApp {
520528
fn model(_: &Relm<Self>, application: Self::ModelParam) -> Model {
521529
Model {
522530
application,
531+
app_hold_guard: None,
523532
message_server: None,
524533
}
525534
}
526535

527536
fn subscriptions(&mut self, relm: &Relm<Self>) {
537+
let stream = relm.stream().clone();
528538
connect!(self.model.application, connect_activate(app), relm, {
529539
// NOTE: we need to increase the refcount of app because we create the window
530540
// asynchronously.
531-
app.hold();
541+
stream.emit(Msg::AppHoldGuard(app.hold()));
532542
Msg::Activate
533543
});
544+
let stream = relm.stream().clone();
534545
connect!(self.model.application, connect_open(app, files, _), relm, {
535546
// NOTE: we need to increase the refcount of app because we create the window
536547
// asynchronously.
537-
app.hold();
548+
stream.emit(Msg::AppHoldGuard(app.hold()));
538549
Msg::Open(files.to_vec())
539550
});
540551
}
@@ -548,10 +559,13 @@ impl Update for RelmApp {
548559
message_server.stream().emit(ReleaseApp);
549560
},
550561
None => {
551-
self.model.message_server = Some(create_message_server(self.model.application.clone(), vec![], None));
562+
self.model.message_server = Some(create_message_server(self.model.application.clone(), self.model.app_hold_guard.take(), vec![], None));
552563
},
553564
}
554565
},
566+
Msg::AppHoldGuard(app_hold_guard) => {
567+
self.model.app_hold_guard = Some(app_hold_guard);
568+
},
555569
Msg::Open(files) => {
556570
match self.model.message_server {
557571
Some(ref message_server) => {
@@ -570,7 +584,7 @@ impl Update for RelmApp {
570584
let files = files.iter()
571585
.map(|file| file.uri().to_string())
572586
.collect();
573-
self.model.message_server = Some(create_message_server(self.model.application.clone(), files, None));
587+
self.model.message_server = Some(create_message_server(self.model.application.clone(), self.model.app_hold_guard.take(), files, None));
574588
},
575589
}
576590
},

src/message_server.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::io::{BufRead, BufReader};
2727
use std::io::{self, Write};
2828
use std::process;
2929

30-
use gio::prelude::ApplicationExt;
30+
use gio::ApplicationHoldGuard;
3131
use gtk::Application;
3232
use gtk::traits::GtkApplicationExt;
3333
use gtk::{
@@ -65,6 +65,7 @@ pub struct MessageServer {
6565
pub struct Model {
6666
app_count: usize,
6767
application: Application,
68+
app_hold_guard: Option<ApplicationHoldGuard>,
6869
config_dir: ConfigDir,
6970
/// This listener is used to prevent two instances of Titanium to run at the same time.
7071
private_web_context: WebContext,
@@ -86,10 +87,10 @@ pub enum Msg {
8687

8788
impl Update for MessageServer {
8889
type Model = Model;
89-
type ModelParam = (Application, Vec<String>, Option<String>);
90+
type ModelParam = (Application, Option<ApplicationHoldGuard>, Vec<String>, Option<String>);
9091
type Msg = Msg;
9192

92-
fn model(relm: &Relm<Self>, (application, urls, config): (Application, Vec<String>, Option<String>)) -> Model {
93+
fn model(relm: &Relm<Self>, (application, app_hold_guard, urls, config): (Application, Option<ApplicationHoldGuard>, Vec<String>, Option<String>)) -> Model {
9394
let config_dir = ConfigDir::new(&config).unwrap(); // TODO: remove unwrap().
9495
let (web_context, private_web_context) = WebView::initialize_web_extension(&config_dir);
9596
if urls.is_empty() {
@@ -105,6 +106,7 @@ impl Update for MessageServer {
105106
Model {
106107
app_count: 0,
107108
application,
109+
app_hold_guard,
108110
config_dir,
109111
opened_urls: BTreeSet::new(),
110112
previous_opened_urls: BTreeSet::new(),
@@ -125,7 +127,7 @@ impl Update for MessageServer {
125127
NewApp(url, privacy) => self.add_app(url, privacy),
126128
// NOTE: we called hold() on the application in order to create the window
127129
// asynchronously. Now that it is created, we can call release().
128-
ReleaseApp => self.model.application.release(),
130+
ReleaseApp => { self.model.app_hold_guard.take(); },
129131
RemoveApp(url) => self.remove_app(url),
130132
}
131133
}
@@ -140,8 +142,8 @@ impl UpdateNew for MessageServer {
140142
}
141143

142144
impl MessageServer {
143-
pub fn new(application: Application, url: Vec<String>, config_dir: Option<String>) -> Result<EventStream<<Self as Update>::Msg>> {
144-
Ok(execute::<MessageServer>((application, url, config_dir)))
145+
pub fn new(application: Application, app_hold_guard: Option<ApplicationHoldGuard>, url: Vec<String>, config_dir: Option<String>) -> Result<EventStream<<Self as Update>::Msg>> {
146+
Ok(execute::<MessageServer>((application, app_hold_guard, url, config_dir)))
145147
}
146148

147149
fn add_app(&mut self, url: Option<String>, privacy: Privacy) {
@@ -218,8 +220,8 @@ impl MessageServer {
218220

219221
/// Create a new message server.
220222
/// If it is not possible to create one, show the error and exit.
221-
pub fn create_message_server(application: Application, urls: Vec<String>, config_dir: Option<String>) -> EventStream<<MessageServer as Update>::Msg> {
222-
match MessageServer::new(application, urls, config_dir) {
223+
pub fn create_message_server(application: Application, app_hold_guard: Option<ApplicationHoldGuard>, urls: Vec<String>, config_dir: Option<String>) -> EventStream<<MessageServer as Update>::Msg> {
224+
match MessageServer::new(application, app_hold_guard, urls, config_dir) {
223225
Ok(message_server) => message_server,
224226
Err(error) => {
225227
let message = format!("cannot create the message server used to communicate with the web processes: {}",

src/webview/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use webkit2gtk::{
6666
WebContextExt,
6767
WebInspector,
6868
WebInspectorExt,
69-
WebViewExt,
69+
WebViewExt, WebsitePolicies, AutoplayPolicy,
7070
};
7171
use webkit2gtk::NavigationType::{LinkClicked, Other};
7272
use webkit2gtk::PolicyDecisionType::{self, NavigationAction, Response};
@@ -182,7 +182,8 @@ impl Widget for WebView {
182182
#[name="view"]
183183
webkit2gtk::WebView({
184184
user_content_manager: UserContentManager::new(), // FIXME: seems to be deallocated.
185-
web_context: self.model.context
185+
web_context: self.model.context,
186+
website_policies: WebsitePolicies::builder().autoplay(AutoplayPolicy::Deny).build(),
186187
}) {
187188
close => Close,
188189
vexpand: true,

titanium-common/Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ repository = "https://github.com/antoyo/titanium"
77
version = "0.1.0"
88

99
[dependencies]
10-
gio = "^0.15.0"
11-
glib = "^0.15.0"
10+
gio = "^0.16.0"
11+
glib = "^0.16.0"
1212
log = "^0.4.1"
13-
relm = "0.23"
14-
relm-derive = "0.23"
1513
rmp-serialize = "^0.8.0"
1614
rustc-serialize = "^0.3.24"

0 commit comments

Comments
 (0)