Add DND while on battery to DND plugin

This commit is contained in:
Gobinath 2018-06-22 15:11:09 -04:00
parent 3187864ec6
commit 68ea1c4677
36 changed files with 211 additions and 38 deletions

2
.gitignore vendored
View File

@ -99,6 +99,6 @@ ENV/
# Visual Studio Code settings
.vscode/
*.safeeyes.po~
safeeyes/config/locale/*/LC_MESSAGES/safeeyes.po~
node_modules/

View File

@ -271,6 +271,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -269,6 +269,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-02-01 11:34+0000\n"
"Last-Translator: Joan Montané <joan@montane.cat>\n"
"Language-Team: Catalan <https://hosted.weblate.org/projects/safe-"
"eyes/translations/ca/>\n"
"Language-Team: Catalan <https://hosted.weblate.org/projects/safe-eyes/"
"translations/ca/>\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -273,6 +273,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-01-29 06:30+0000\n"
"Last-Translator: Pavel Borecki <pavel.borecki@gmail.com>\n"
"Language-Team: Czech <https://hosted.weblate.org/projects/safe-"
"eyes/translations/cs/>\n"
"Language-Team: Czech <https://hosted.weblate.org/projects/safe-eyes/"
"translations/cs/>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -273,6 +273,10 @@ msgstr "Přerušovat tato okna nehledě na jejich stav"
msgid "Switch the interruptible windows to normal mode"
msgstr "Přepnout nepřerušitelná okna do normálního režimu"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Zdravotní statistiky"

View File

@ -270,6 +270,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -273,6 +273,10 @@ msgstr "Diese Fenster in jedem Fall unterbrechen"
msgid "Switch the interruptible windows to normal mode"
msgstr "Unterbrechbare Fenster in normalen Modus umschalten"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Statistik Gesundheit"

View File

@ -273,6 +273,10 @@ msgstr "Interrupt these windows regardless of their state"
msgid "Switch the interruptible windows to normal mode"
msgstr "Switch the interruptible windows to normal mode"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr "Do not disturb while on battery"
# plugin/healthstats
msgid "Health Statistics"
msgstr "Health Statistics"

View File

@ -272,6 +272,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Estadísticas de salud"

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-02-03 07:53+0000\n"
"Last-Translator: Kristjan Räts <kristjanrats@gmail.com>\n"
"Language-Team: Estonian <https://hosted.weblate.org/projects/safe-"
"eyes/translations/et/>\n"
"Language-Team: Estonian <https://hosted.weblate.org/projects/safe-eyes/"
"translations/et/>\n"
"Language: et\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -272,6 +272,10 @@ msgstr "Nende akende puhul seisundit ei kontrollita"
msgid "Switch the interruptible windows to normal mode"
msgstr "Lülita katkestatavad aknad tavarežiimi"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Statistika"

View File

@ -272,6 +272,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-01-29 14:24+0000\n"
"Last-Translator: French Coordinator OTF/LocLab <french.coordinator@rbox.me>\n"
"Language-Team: French <https://hosted.weblate.org/projects/safe-"
"eyes/translations/fr/>\n"
"Language-Team: French <https://hosted.weblate.org/projects/safe-eyes/"
"translations/fr/>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -276,6 +276,10 @@ msgstr "Interrompre ces fenêtres, quel que soit leur état"
msgid "Switch the interruptible windows to normal mode"
msgstr "Passer les fenêtres interruptibles en mode normal"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Statistiques de santé"

View File

@ -271,6 +271,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -271,6 +271,10 @@ msgstr "Szakítsd meg ezeket az ablakokat az állapotuktól függetlenül"
msgid "Switch the interruptible windows to normal mode"
msgstr "A megszakítható ablakokat váltsd át normál módba"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Egészség Statisztikák"

View File

@ -269,6 +269,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-02-01 00:38+0000\n"
"Last-Translator: Guglielmo Wilmup <wilmup67@gmail.com>\n"
"Language-Team: Italian <https://hosted.weblate.org/projects/safe-"
"eyes/translations/it/>\n"
"Language-Team: Italian <https://hosted.weblate.org/projects/safe-eyes/"
"translations/it/>\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -276,6 +276,10 @@ msgstr "Interrompe le finestre in oggetto in base al loro stato"
msgid "Switch the interruptible windows to normal mode"
msgstr "Passa le finestre interrompibili a modalità normale"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Statistiche"

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-03-06 00:52+0000\n"
"Last-Translator: Moo <hazap@hotmail.com>\n"
"Language-Team: Lithuanian <https://hosted.weblate.org/projects/safe-"
"eyes/translations/lt/>\n"
"Language-Team: Lithuanian <https://hosted.weblate.org/projects/safe-eyes/"
"translations/lt/>\n"
"Language: lt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -275,6 +275,10 @@ msgstr "Pertraukti šiuos langus nepriklausomai nuo jų būsenos"
msgid "Switch the interruptible windows to normal mode"
msgstr "Perjungti nepertraukiamus langus į normalią veikseną"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Sveikatos statistika"

View File

@ -272,6 +272,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-05-14 19:53+0000\n"
"Last-Translator: Håkon Solbjørg <hlsolbjorg@gmail.com>\n"
"Language-Team: Norwegian Bokmål <https://hosted.weblate.org/projects/"
"safe-eyes/translations/nb/>\n"
"Language-Team: Norwegian Bokmål <https://hosted.weblate.org/projects/safe-"
"eyes/translations/nb/>\n"
"Language: nb\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -270,6 +270,10 @@ msgstr "Forstyrr disse vinduene uavhengig av tilstand"
msgid "Switch the interruptible windows to normal mode"
msgstr "Bytt avbruddsfritt vindu til normalt modus"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Helsestatistikk"

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-01-29 09:57+0000\n"
"Last-Translator: Heimen Stoffels <vistausss@outlook.com>\n"
"Language-Team: Dutch <https://hosted.weblate.org/projects/safe-"
"eyes/translations/nl/>\n"
"Language-Team: Dutch <https://hosted.weblate.org/projects/safe-eyes/"
"translations/nl/>\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -276,6 +276,10 @@ msgstr "Deze vensters storen, ongeacht hun status"
msgid "Switch the interruptible windows to normal mode"
msgstr "Stoorbare vensters overschakelen naar normale modus"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Gezondheidsstatistieken"

View File

@ -273,6 +273,10 @@ msgstr "Przerywaj okna niezależnie od ich stanu"
msgid "Switch the interruptible windows to normal mode"
msgstr "Przełącz przerwane okna do trybu normalnego"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Statystyki Zdrowotne"

View File

@ -275,6 +275,10 @@ msgstr "Interrompa essas janelas, independentemente do seu estado"
msgid "Switch the interruptible windows to normal mode"
msgstr "Mude as janelas interruptíveis para o modo normal"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Estatísticas de saúde"

View File

@ -8,14 +8,14 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-02-15 09:11+0000\n"
"Last-Translator: Paul <paulku@yandex.ru>\n"
"Language-Team: Russian <https://hosted.weblate.org/projects/safe-"
"eyes/translations/ru/>\n"
"Language-Team: Russian <https://hosted.weblate.org/projects/safe-eyes/"
"translations/ru/>\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<="
"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 2.19-dev\n"
# Short break
@ -271,6 +271,10 @@ msgstr "Прерывать эти окна независимо от их сос
msgid "Switch the interruptible windows to normal mode"
msgstr "Преключать прерываемые окна в нормальный режим"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Статистика здоровья"

View File

@ -258,6 +258,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-01-31 20:18+0000\n"
"Last-Translator: Radek Sprta <mail@radeksprta.eu>\n"
"Language-Team: Slovak <https://hosted.weblate.org/projects/safe-"
"eyes/translations/sk/>\n"
"Language-Team: Slovak <https://hosted.weblate.org/projects/safe-eyes/"
"translations/sk/>\n"
"Language: sk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -272,6 +272,10 @@ msgstr "Vždy prerušuj tieto okná"
msgid "Switch the interruptible windows to normal mode"
msgstr "Přepnút prerušiteľné okná do normálu"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Zdravotné štatistiky"

View File

@ -269,6 +269,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -275,6 +275,10 @@ msgstr "இந்த சாளரங்களின் நிலையை பொ
msgid "Switch the interruptible windows to normal mode"
msgstr "குறுக்கீடு செய்யும் போது சாளரங்களை சாதாரண நிலைக்கு மாற்றுக"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr "மின்கலத்தில் இயங்கும் போது குறுக்கீடு செய்ய வேண்டாம்"
# plugin/healthstats
msgid "Health Statistics"
msgstr "ஆரோக்கிய புள்ளிவிவரங்கள்"

View File

@ -8,8 +8,8 @@ msgstr ""
"POT-Creation-Date: \n"
"PO-Revision-Date: 2018-01-31 17:50+0000\n"
"Last-Translator: Koray Biçer <solayagim@gmail.com>\n"
"Language-Team: Turkish <https://hosted.weblate.org/projects/safe-"
"eyes/translations/tr/>\n"
"Language-Team: Turkish <https://hosted.weblate.org/projects/safe-eyes/"
"translations/tr/>\n"
"Language: tr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -273,6 +273,10 @@ msgstr "Bu pencerelerin durumuna bakmaksızın engelle"
msgid "Switch the interruptible windows to normal mode"
msgstr "Engellenebilir pencereleri normal kipe geçir"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Sağlık İstatistikleri"

View File

@ -7,14 +7,14 @@ msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: ug\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.7.1\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Language: ug\n"
# Short break
msgid "Tightly close your eyes"
@ -269,6 +269,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -14,8 +14,8 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<="
"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 2.20-dev\n"
# Short break
@ -228,7 +228,8 @@ msgstr "Будь ласка, встановіть засіб командног
# Settings dialog
msgid "Please add the resource %(resource)s to %(config_resource)s directory"
msgstr "Будь ласка, додайте ресурс %(resource)s до каталогу %(config_resource)s"
msgstr ""
"Будь ласка, додайте ресурс %(resource)s до каталогу %(config_resource)s"
# Settings dialog
msgid "New Break"
@ -275,6 +276,10 @@ msgstr "Переривати ці вікна незалежно від їх ст
msgid "Switch the interruptible windows to normal mode"
msgstr "Перемикати ці недоступні для переривання вікна в нормальний режим"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Статистика здоров'я"

View File

@ -274,6 +274,10 @@ msgstr "Tạm ngắt những cửa sổ này bất kể trạng thái của nó"
msgid "Switch the interruptible windows to normal mode"
msgstr "Chuyển các cửa sổ có thể ngắt được sang chế độ bình thường"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "Thống kê sức khoẻ"

View File

@ -272,6 +272,10 @@ msgstr "中断这些窗口无视其状态"
msgid "Switch the interruptible windows to normal mode"
msgstr "将可中断窗口切换到正常模式"
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr "健康统计"

View File

@ -270,6 +270,10 @@ msgstr ""
msgid "Switch the interruptible windows to normal mode"
msgstr ""
# plugin/donotdisturb
msgid "Do not disturb while on battery"
msgstr ""
# plugin/healthstats
msgid "Health Statistics"
msgstr ""

View File

@ -50,11 +50,12 @@
{
"id": "donotdisturb",
"enabled": true,
"version": "0.0.1",
"version": "0.0.2",
"settings": {
"skip_break_windows": "",
"take_break_windows": "",
"unfullscreen": true
"unfullscreen": true,
"while_on_battery": false
}
},
{

View File

@ -2,7 +2,7 @@
"meta": {
"name": "Do Not Disturb",
"description": "Skip break if the active window is in fullscreen mode",
"version": "0.0.1"
"version": "0.0.2"
},
"dependencies": {
"python_modules": [],
@ -28,6 +28,12 @@
"label": "Switch the interruptible windows to normal mode",
"type": "BOOL",
"default": true
},
{
"id": "while_on_battery",
"label": "Do not disturb while on battery",
"type": "BOOL",
"default": false
}
],
"break_override_allowed": true

View File

@ -21,6 +21,7 @@ Skip Fullscreen plugin skips the break if the active window is fullscreen.
NOTE: Do not remove the unused import 'GdkX11' becuase it is required in Ubuntu 14.04
"""
import os
import logging
import re
import subprocess
@ -39,7 +40,7 @@ unfullscreen_allowed = True
def is_active_window_skipped(pre_break):
"""
Check for full-screen applications.
This method must be executed by the main thread. If not, it will cause to random failure.
This method must be executed by the main thread. If not, it will cause random failure.
"""
logging.info('Searching for full-screen application')
screen = Gdk.Screen.get_default()
@ -47,7 +48,8 @@ def is_active_window_skipped(pre_break):
active_window = screen.get_active_window()
if active_window:
active_xid = str(active_window.get_xid())
cmdlist = ['xprop', '-root', '-notype', '-id', active_xid, 'WM_CLASS', '_NET_WM_STATE']
cmdlist = ['xprop', '-root', '-notype', '-id',
active_xid, 'WM_CLASS', '_NET_WM_STATE']
try:
stdout = subprocess.check_output(cmdlist).decode('utf-8')
@ -67,7 +69,8 @@ def is_active_window_skipped(pre_break):
try:
active_window.unfullscreen()
except BaseException:
logging.error('Error in unfullscreen the window ' + process)
logging.error(
'Error in unfullscreen the window ' + process)
return False
return is_fullscreen
@ -75,25 +78,59 @@ def is_active_window_skipped(pre_break):
return False
def is_on_battery():
"""
Check if the computer is running on battery.
"""
charging = True
available_power_sources = os.listdir('/sys/class/power_supply')
for power_source in available_power_sources:
if 'BAT' in power_source:
# Found battery
battery_status = os.path.join(
'/sys/class/power_supply', power_source, 'status')
if os.path.isfile(battery_status):
# Additional check to confirm that the status file exists
try:
with open(battery_status, 'r') as status_file:
status = status_file.read()
if status:
charging = 'charging' in status.lower()
except BaseException:
logging.error('Failed to read %s' % battery_status)
break
return not charging
def init(ctx, safeeyes_config, plugin_config):
global context
global skip_break_window_classes
global take_break_window_classes
global unfullscreen_allowed
global dnd_while_on_battery
logging.debug('Initialize Skip Fullscreen plugin')
context = ctx
skip_break_window_classes = plugin_config['skip_break_windows'].split()
take_break_window_classes = plugin_config['take_break_windows'].split()
unfullscreen_allowed = plugin_config['unfullscreen']
dnd_while_on_battery = plugin_config['while_on_battery']
def on_pre_break(break_obj):
"""
Lifecycle method executes before the pre-break period.
"""
return is_active_window_skipped(True)
skip_break = is_active_window_skipped(True)
if dnd_while_on_battery and not skip_break:
skip_break = is_on_battery()
return skip_break
def on_start_break(break_obj):
"""
Lifecycle method executes just before the break.
"""
return is_active_window_skipped(False)
skip_break = is_active_window_skipped(False)
if dnd_while_on_battery and not skip_break:
skip_break = is_on_battery()
return skip_break