fix: observe KeyStatusChanged event and correctly update hasProtections info
This commit is contained in:
@@ -14,7 +14,7 @@ const Protections: FunctionalComponent<Props> = ({ application }) => {
|
|||||||
application.clearProtectionSession();
|
application.clearProtectionSession();
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasProtections = application.hasProtectionSources();
|
const [hasProtections, setHasProtections] = useState(() => application.hasProtectionSources());
|
||||||
|
|
||||||
const getProtectionsDisabledUntil = useCallback((): string | null => {
|
const getProtectionsDisabledUntil = useCallback((): string | null => {
|
||||||
const protectionExpiry = application.getProtectionSessionExpiryDate();
|
const protectionExpiry = application.getProtectionSessionExpiryDate();
|
||||||
@@ -51,8 +51,16 @@ const Protections: FunctionalComponent<Props> = ({ application }) => {
|
|||||||
ApplicationEvent.ProtectionSessionExpiryDateChanged
|
ApplicationEvent.ProtectionSessionExpiryDateChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const removeKeyStatusChangedObserver = application.addEventObserver(
|
||||||
|
async () => {
|
||||||
|
setHasProtections(application.hasProtectionSources());
|
||||||
|
},
|
||||||
|
ApplicationEvent.KeyStatusChanged
|
||||||
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
removeProtectionSessionExpiryDateChangedObserver();
|
removeProtectionSessionExpiryDateChangedObserver();
|
||||||
|
removeKeyStatusChangedObserver();
|
||||||
};
|
};
|
||||||
}, [application, getProtectionsDisabledUntil]);
|
}, [application, getProtectionsDisabledUntil]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user