mirror of
https://github.com/XFox111/PasswordGeneratorExtension.git
synced 2026-04-22 08:08:01 +03:00
Major 2.0 (#8)
* Migrated to React 18 and FluentUI 9 * Added Ukranian translation * Updated GitHub templates * Updated CI/CD - Added CodeQL and Dependabot pipelines - Removed Whitesource Bolt integration - Added PR pipeline - Update release pipeline to meet ReactJS - Added Edge publish to pipeline - Updated PR checklist * Updated repo docs * Moved dependabot yml to the right place * Update README.md * Added path filters to pipelines
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// BackgroundService.ts
|
||||
// Background script that handles the context menu visibility
|
||||
|
||||
import { loc } from "../Utils/Localization";
|
||||
|
||||
function UpdateContextMenu(isEnabled: boolean) : void
|
||||
{
|
||||
console.log("BackgroundService.UpdateContextMenu", isEnabled);
|
||||
chrome.contextMenus.update("generatePassword", { visible: isEnabled });
|
||||
}
|
||||
|
||||
async function OnContextClick(info : chrome.contextMenus.OnClickData) : Promise<void>
|
||||
{
|
||||
console.log("BackgroundService.OnContextClick", info);
|
||||
|
||||
let tabInfo : chrome.tabs.Tab[] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
|
||||
console.log("BackgroundService.OnContextClick", tabInfo);
|
||||
|
||||
chrome.tabs.sendMessage<string>(tabInfo[0].id, info.menuItemId as string);
|
||||
}
|
||||
|
||||
if (!chrome.runtime.onInstalled.hasListeners())
|
||||
chrome.runtime.onInstalled.addListener(async () =>
|
||||
{
|
||||
console.log("[BackgroundService] chrome.runtime.onInstalled");
|
||||
chrome.contextMenus.removeAll();
|
||||
|
||||
chrome.contextMenus.create(
|
||||
{
|
||||
title: loc("Quick generate password"),
|
||||
contexts: [ "editable" ],
|
||||
id: "generatePassword"
|
||||
}
|
||||
);
|
||||
|
||||
let settings : { [key : string]: any } = await chrome.storage.sync.get({ AddContext: true });
|
||||
|
||||
UpdateContextMenu(settings.AddContext);
|
||||
});
|
||||
|
||||
if (!chrome.contextMenus.onClicked.hasListeners())
|
||||
chrome.contextMenus.onClicked.addListener(OnContextClick);
|
||||
|
||||
if (!chrome.storage.sync.onChanged.hasListeners())
|
||||
chrome.storage.sync.onChanged.addListener(changes =>
|
||||
{
|
||||
console.log("[BackgroundService] chrome.storage.sync.onChanged", changes);
|
||||
if (changes.AddContext?.newValue !== undefined)
|
||||
UpdateContextMenu(changes.AddContext.newValue);
|
||||
});
|
||||
Reference in New Issue
Block a user