Created
September 4, 2024 17:25
-
-
Save v6ak/af4526d90f8cad7753b8b900d85528a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definuju skupinu. Tu nepoužívám přímo, ale přes FirefoxOptions. Mohu použít více různých FirefoxOptions, pak se mi to automaticky spojí do jedné skupiny, jako bych vše nacpal do jednoho FirefoxOptions. | |
class FirefoxOptionsGroup(MandatoryGroup, NamedTuple('FirefoxOptionsGroup', [('rw', bool)])): | |
def create_sequence(self, target: Target, name: NameCollection, specs: List[Spec], index: int) -> List[Tuple[NameCollection, Group, Task]]: | |
if not isinstance(target, QubeTarget): | |
raise Exception("Bad target: "+str(target)) | |
if index == 0: | |
dicts = list(map(lambda f: f.options, specs)) | |
options_len_sum = sum(map(len, dicts)) | |
options = {key: value for d in dicts for key, value in d.items()} | |
if options_len_sum != len(options): | |
raise Exception('You seem to have overriden some option: '+str(dicts)) | |
pref_data = "".join(['pref('+json.dumps(k)+', '+json.dumps(v)+');\n' for k, v in options.items()]) | |
prefix = '/rw/bind-dirs' if self.rw else '' | |
# This should ensure the files don't override each other when used in both template and appvm | |
config_filename = 'firefox-custom-options.js' if self.rw else 'firefox-global-custom-options.js' | |
return list(itertools.chain(*map(lambda x: (x.group().create_sequence(target, name.add_to_all_right('Firefox options'), [x], 0)), [ | |
*( | |
[ | |
Put('/rw/config/qubes-bind-dirs.d', Dir(create_as='root')), | |
Put('/rw/bind-dirs/etc', Dir(create_as='root')), | |
Put('/rw/bind-dirs/etc/firefox-esr', Dir(create_as='root')), | |
Put('/rw/config/qubes-bind-dirs.d/50_firefox-options.conf', File( | |
create_as='root', | |
content=b''' | |
if [ -e /etc/firefox-esr/ ]; then | |
binds+=( "/etc/firefox-esr/firefox-custom-options.js" ) | |
fi | |
if [ -e /etc/firefox/defaults/pref/ ]; then | |
binds+=( "/etc/firefox/defaults/pref/firefox-custom-options.js" ) | |
fi | |
if [ -e /usr/lib64/firefox/browser/defaults/preferences ]; then | |
binds+=( "/usr/lib64/firefox/browser/defaults/preferences/_firefox-custom-options.js" ) | |
fi | |
''' | |
)), | |
] if self.rw else [] | |
), | |
# Tady to rvu do více míst. Možná některá z těch míst už nejsou potřeba, v minulosti se to přesouvalo, plus jsem řešil Fedoru a Debian. | |
Put(prefix + '/etc/firefox', Dir(create_as='root')), | |
Put(prefix + '/etc/firefox/defaults', Dir(create_as='root')), | |
Put(prefix + '/etc/firefox/defaults/pref', Dir(create_as='root')), | |
Put(prefix + '/etc/firefox/defaults/pref/' + config_filename, File(create_as='root', content=pref_data.encode('utf-8'))), | |
Put(prefix + '/usr', Dir(create_as='root')), | |
Put(prefix + '/usr/lib64', Dir(create_as='root')), | |
Put(prefix + '/usr/lib64/firefox', Dir(create_as='root')), | |
Put(prefix + '/usr/lib64/firefox/defaults', Dir(create_as='root')), | |
Put(prefix + '/usr/lib64/firefox/defaults/pref', Dir(create_as='root')), | |
Put(prefix + '/usr/lib64/firefox/defaults/pref/_' + config_filename, File(create_as='root', content=pref_data.encode('utf-8'))), | |
#Put(prefix + '/etc/firefox-esr/firefox-custom-options.js', File(create_as='root', content=pref_data.encode('utf-8'))), | |
]))) | |
else: | |
return [] | |
# Toto používám přímo. V template nastavím rw=False, aby se to zapsalo na správné místo. | |
class FirefoxOptions(Spec, NamedTupleWithDefaults('FirefoxOptions', [ | |
('options', Dict[str, Union[str, int, bool]]), | |
('rw', bool, True), | |
])): | |
def group(self): | |
return FirefoxOptionsGroup(self.rw) | |
# Zkratka pro homepage… | |
def FirefoxHomePage(url: str): | |
return FirefoxOptions({"browser.startup.homepage": url}) | |
#### A takto se to používá… | |
# Nastavím homepage | |
FirefoxHomePage('http://localhost:8123') | |
# Nastavím defaultní chování v template… | |
FirefoxOptions({ | |
# annoyances | |
"devtools.selfxss.count": 5, | |
"browser.aboutConfig.showWarning": False, | |
# privacy | |
"browser.urlbar.suggest.searches": False, | |
# homepage | |
"browser.startup.homepage": "about:newtab", | |
# tab UX | |
"browser.ctrlTab.previews": True, | |
"browser.ctrlTab.sortByRecentlyUsed": True, | |
# theme | |
"extensions.activeThemeID": "[email protected]", | |
"browser.theme.content-theme": 0, | |
"browser.theme.toolbar-theme": 0, | |
}, rw=False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment