Merge branch 'main' into native-update

This commit is contained in:
rebloor
2024-10-19 05:48:50 +13:00
committed by GitHub
5 changed files with 617 additions and 650 deletions

View File

@@ -39,7 +39,7 @@ browser.browserAction.onClicked.addListener(toggleBookmark);
/* /*
* Switches currentTab and currentBookmark to reflect the currently active tab * Switches currentTab and currentBookmark to reflect the currently active tab
*/ */
function updateActiveTab(tabs) { function updateAddonStateForActiveTab(tabs) {
function isSupportedProtocol(urlString) { function isSupportedProtocol(urlString) {
let supportedProtocols = ["https:", "http:", "ftp:", "file:"]; let supportedProtocols = ["https:", "http:", "ftp:", "file:"];
@@ -68,19 +68,19 @@ function updateActiveTab(tabs) {
} }
// listen for bookmarks being created // listen for bookmarks being created
browser.bookmarks.onCreated.addListener(updateActiveTab); browser.bookmarks.onCreated.addListener(updateAddonStateForActiveTab);
// listen for bookmarks being removed // listen for bookmarks being removed
browser.bookmarks.onRemoved.addListener(updateActiveTab); browser.bookmarks.onRemoved.addListener(updateAddonStateForActiveTab);
// listen to tab URL changes // listen to tab URL changes
browser.tabs.onUpdated.addListener(updateActiveTab); browser.tabs.onUpdated.addListener(updateAddonStateForActiveTab);
// listen to tab switching // listen to tab switching
browser.tabs.onActivated.addListener(updateActiveTab); browser.tabs.onActivated.addListener(updateAddonStateForActiveTab);
// listen for window switching // listen for window switching
browser.windows.onFocusChanged.addListener(updateActiveTab); browser.windows.onFocusChanged.addListener(updateAddonStateForActiveTab);
// update when the extension loads initially // update when the extension loads initially
updateActiveTab(); updateAddonStateForActiveTab();

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,15 @@
# Favourite Colour # Favourite Colour
Shows and stores your favourite colour, in storage.sync in the about:addons page for the add-on. Shows and stores your favourite colour, in storage.sync in the extension's about:addons page.
Demonstrates: Demonstrates:
* storing data with storage.sync * storing data with storage.sync
* reading data from storage.managed
* creating an options page and opening it with `runtime.openOptionsPage()`
* best practice for supporting automatic theme switching (dark theme) in the options page
* reading data from storage.managed, To have Firefox read data from storage.managed, create a file with this content:
* creating an options page and opening it with `runtime.openOptionsPage()`.
To have Firefox read data from storage.managed, create a file with the following contents:
{ {
"name": "favourite-colour-examples@mozilla.org", "name": "favourite-colour-examples@mozilla.org",

View File

@@ -3,6 +3,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="color-scheme" content="dark light">
</head> </head>
<body> <body>

View File

@@ -16,21 +16,15 @@ key_path = 'Software\\Mozilla\\NativeMessagingHosts\\ping_pong'
# Assuming current user overrides local machine. # Assuming current user overrides local machine.
key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE'] key_roots = ['HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE']
found_key = False for key_root in key_roots:
for root in key_roots:
key = winreg.OpenKey(getattr(winreg, root), key_path)
try: try:
print('Checking:', root, key_path) print('Checking:', key_root, key_path)
key = winreg.OpenKey(getattr(winreg, key_root), key_path)
res = winreg.QueryValueEx(key, '') res = winreg.QueryValueEx(key, '')
break
except FileNotFoundError: except FileNotFoundError:
print('...error finding key') print('... error finding key')
continue else:
found_key = True
break
if not found_key:
raise ValueError('Could not find a registry entry, aborting.') raise ValueError('Could not find a registry entry, aborting.')
json_path = res[0] json_path = res[0]