Fix notifications and keyboard shortcut on Firefox

This commit is contained in:
Corbin Davenport 2023-02-20 17:55:55 -05:00
parent 4c414f729a
commit 64eb4ea632
3 changed files with 30 additions and 14 deletions

View File

@ -7,15 +7,18 @@ chrome.runtime.onInstalled.addListener(function (details) {
type: 'basic',
iconUrl: chrome.runtime.getURL('img/icon_x128.png'),
title: 'Share to Mastodon ' + chrome.runtime.getManifest().version + ' installed!',
buttons: [
message: "Click here to see what's new in this version."
}
// Firefox doesn't support buttons in notifications
if (!window.navigator.userAgent.includes('Firefox')) {
notification.buttons = [
{
title: 'Open Settings'
},
{
title: 'Join Discord'
}
],
message: "Click here to see what's new in this version."
]
}
// Send notification
chrome.notifications.create(notification, () => {
@ -24,6 +27,7 @@ chrome.runtime.onInstalled.addListener(function (details) {
chrome.tabs.create({ url: 'https://corbin.io/introducing-share-to-mastodon/' })
})
// Handle notification button clicks
if (!window.navigator.userAgent.includes('Firefox')) {
chrome.notifications.onButtonClicked.addListener(function (_, buttonIndex) {
if (buttonIndex === 0) {
chrome.runtime.openOptionsPage()
@ -32,6 +36,7 @@ chrome.runtime.onInstalled.addListener(function (details) {
chrome.tabs.create({ url: 'https://discord.com/invite/59wfy5cNHw' })
}
})
}
})
}
// Initialize context menu
@ -43,7 +48,7 @@ chrome.runtime.onInstalled.addListener(function (details) {
// Function for migrating data from version 1.0
async function migrateOldData() {
// Chrome/Edge version saved a single server in a "userServer" string in chrome.storage.sync
// Firefox version saved it in "userServer" string but in chrome.local.sync
// Firefox version saved it in the same "userServer" string, but in chrome.local.sync
if (window.navigator.userAgent.includes('Firefox')) {
var data = await chrome.storage.local.get()
} else {
@ -134,7 +139,7 @@ function createPopup(serverUrl, shareLink, shareText, tab) {
var popupHeight = 500
var y = Math.round((tab.height / 2) - (popupHeight / 2))
var x = Math.round((tab.width / 2) - (popupWidth / 2))
console.log(popupWidth, popupHeight, y, x)
console.log('Popup dimensions:', popupWidth, popupHeight, y, x)
chrome.windows.create({
url: popupPage,
width: popupWidth,

View File

@ -51,7 +51,13 @@ document.querySelector('#server-remove-btn').addEventListener('click', function
// Open keyboard shortcut
document.querySelector('#mastodon-keyboard-shortcut').addEventListener('click', function () {
// Firefox cannot automatically navigate to the keyboard shortcut configuration page
if (window.navigator.userAgent.includes('Firefox')) {
const bsCollapse = new bootstrap.Collapse('#firefoxShortcutCollapse').show()
} else {
chrome.tabs.create({ url: 'chrome://extensions/shortcuts#:~:text=Share%20to%20Mastodon' })
}
})
loadSettings()

View File

@ -36,6 +36,11 @@
<div class="mb-3">
<label class="form-label">Other settings</label>
<button type="button" class="btn btn-sm btn-primary w-100" id="mastodon-keyboard-shortcut">Change keyboard shortcut</button>
<div class="collapse mt-1" id="firefoxShortcutCollapse">
<div class="card card-body">
Open about:addons in a new tab, click the settings gear button, then select "Manage extension shortcuts."
</div>
</div>
</div>
<hr>
<p>If you find Share to Mastodon useful, please donate to support continued development. It would mean a lot!</p>