Giter Club home page Giter Club logo

gnome-shell-extension-blocker's Introduction

Blocker

A content blocker for your entire computer.

Getting started

Installation

Important

This extension depends on hBlock and will NOT WORK if you don't have it installed on your computer. Follow the instructions here to install it.

After installing hBlock, you can install Blocker itself through the GNOME Extensions website.

Usage

Caution

Blocker replaces your system's /etc/hosts file. Consider making a backup of it!

Click the Quick Settings toggle and input your user's password to activate Blocker (it will take a while to download all its denylists). Once Blocker is active, it will display a system indicator of a shield. To turn it off, simply click the toggle and input your password again.

Screenshot of the Quick Settings menu with the Blocker toggle

FAQ

How does it work?

This GNOME Shell extension is just a convenient frontend for hBlock, which does all the heavy lifting. Here's what happens when you toggle Blocker:

First, Blocker uses pkexec (the program that prompts you for your password) to gain super user privilege, which is required to run hBlock. Then, if you enabled Blocker, it enables hBlock by running hblock. If you disabled Blocker, it disables hBlock by running hblock -S none -D none. I couldn't resist a flowchart...

flowchart TD

A["Blocker toggled"] --> B["Gain privilege with pkexec"]
B -- Blocker disabled --> C["Execute  `hblock -S none -D none`"]
B -- Blocker enabled --> D["Execute  `hblock`"]
Loading

What are its limitations?

Blocker is powered by hBlock, so its limitations are Blocker's limitations.

The content blocking strategy used by hBlock is DNS blocking. That means that any connections that do not depend on name resolution cannot be blocked using this approach, such as accessing an IP address directly. Additionally, certain applications may set their own DNS settings (e.g. Firefox, when it uses DNS over HTTPS) instead of adhering to the system's configuration. Finally, your DNS settings may be affected if you are using a VPN, which tipically route your DNS queries to its own resolvers.

How do I know it's working?

Visit https://hblock.molinero.dev, it tells you whether hBlock is active or not. This is does that by checking if connections to https://hblock-check.molinero.dev are blocked, which is the case for hBlock's default configuration.

Can I customize the denylist?

Blocker does not provide, not plans to provide, that kind of customization. However, you can do that if you hBlock directly in the terminal, using -A, -D, and -S flags. Run hblock --help for more details.

Where should I report problems?

For false positives, report in hBlock's issue tracker. For everything else, report in Blocker's issue tracker.

Contributing

To build and install the extension run:

gnome-extensions pack --force --extra-source=icons [email protected] &&  gnome-extensions install [email protected] --force

You can run a nested session of GNOME Shell to test the extension out with:

dbus-run-session -- gnome-shell --nested --wayland

If you want to change the size of the window of the nested session, set the MUTTER_DEBUG_DUMMY_MODE_SPECS environment variable (as advised here), like so:

env MUTTER_DEBUG_DUMMY_MODE_SPECS=1024x768 dbus-run-session -- gnome-shell --nested --wayland

Attribution

Code

  • Assign a custom icon to a Quick Settings toggle: based on the codebase from Caffeine.
  • Run shell commands asynchronously: heavily inspired by the GJS docs and GSConnect.
  • Send customized notifications: reused from Gravatar and Picture of the day extensions.

Assets

Documentation

  • How to install hBlock: copied and pasted staright from hBlock's README and docs

Gratitude

This project would not exist if it weren't for hBlock, so I thank its maintainer and all its contributors. I'm also grateful to everyone in the GNOME Extensions matrix room, who kindly answered the many questions that came up while I was writing this program.

License

This project is licensed under the terms of the GPLv3.

gnome-shell-extension-blocker's People

Contributors

pesader avatar

Stargazers

 avatar

Watchers

 avatar

gnome-shell-extension-blocker's Issues

Figure out why polkit is freezing GNOME Shell

For some reason, the extension works when being ran in a nested GNOME Shell session, but it doesn't work when ran on an actual GNOME Shell session.

I had no luck looking at the logs with:

journalctl --no-pager --since "1 hour ago" | grep pkexec

Save state in a gsettings schema

Right now, the extension doesn't remember what state it was in when a GNOME Shell session starts. We should save that in a gsettings schema.

Add a README.md

Here's what it needs to contain:

  • How it works (why it needs authentication, limitations, etc)
  • How to install
  • Where to report errors
    • False positives: hBlock
    • Everything else: right here
  • Attribution
    • GSConnect: code examples of Subprocess
    • GJS documentation: code examples of Subprocess
    • Caffeine: code examples of custom icons
    • hBlock: all the heavy lifting
  • How to know if it's working

Split `extension.js` in multiple files

Move all source files to /src, then have separate files for:

  • BlockerIcons (icons.js)
  • BlockerNotifier (notifier.js)
  • BlockerRunner (runner.js)
  • BlockerIndicator (indicator.js)

Only BlockerExtension should remain in extension.js.
The GJS guide on importing modules is here.

Handle failed commands

Many things are tied to the checked property of the toggle (the "blocked-enabled" preference, the visibility of Blocker indicator, etc). The problem is that this property changes as soon as the toggle is clicked, although the command that it triggers may fail.

We need to figure a way to "rollback" the change in the checked property if the command failed, but I don't know I could do that. Another idea would be reacting to a clicked signal and only change checked if the command was successful.

Don't notify on success

Now that we use a different icon for when hBlock is running, a notification is a bit too intrusive. We can start using notifications only when the command fails.

Possibly "rebrand" to something else

Although hBlock is MIT licensed, that only covers the software, not the brand. Besides, it's also really hard to tell the purpose of an extension called "hBlock toggle" if someone doesn't know what hBlock is. Here are some ideas:

  • Blocker
  • Blockade
  • Barricade
  • Bastion
  • Fort
  • Fortress
  • Rampart
  • Ward
  • Warden
  • Bulwark
  • Fence
  • Guard
  • Crest
  • Harbor
  • Haven
  • Herald (perhaps Harold, as a wordplay?)

Find a way to run the comand asynchronously

Running hblock populates the /etc/hosts file with hundreds of thousands of entries, so it can take a while. It's better to run this async, so it doesn't lock the whole UI of GNOME Shell.

Improve handling of notification sources

Currently, a new notification is created and added to Main on every notification. Besides, they don't self-destruct when their pointers are nullified (as far as I know). For that to happen, we need to add:

source.connect('destroy', ()=>{this.notifSource = null;});

This comes from here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.