Fix infinite loop when pinning/unpinning persistent widgets (#8396)
Pinning or unpinning a persistent widget, such as Jitsi, could cause the PiP view and the app drawer to fight for control over the widget, since the PiP view never realized that it was supposed to relinquish control. This was due to a race between the WidgetLayoutStore update and the AppTile lifecycle tracking update.
This commit is contained in:
@@ -33,6 +33,7 @@ import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelS
|
||||
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
|
||||
import { UPDATE_EVENT } from "../../../../src/stores/AsyncStore";
|
||||
import WidgetStore, { IApp } from "../../../../src/stores/WidgetStore";
|
||||
import ActiveWidgetStore from "../../../../src/stores/ActiveWidgetStore";
|
||||
import AppTile from "../../../../src/components/views/elements/AppTile";
|
||||
import { Container, WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
|
||||
import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer";
|
||||
@@ -116,26 +117,6 @@ describe("AppTile", () => {
|
||||
jest.spyOn(SettingsStore, "getValue").mockRestore();
|
||||
});
|
||||
|
||||
it("tracks live tiles correctly", () => {
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(false);
|
||||
|
||||
// Try removing the tile before it gets added
|
||||
AppTile.removeLiveTile("1", "r1");
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(false);
|
||||
|
||||
AppTile.addLiveTile("1", "r1");
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
AppTile.addLiveTile("1", "r1");
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
AppTile.removeLiveTile("1", "r1");
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
AppTile.removeLiveTile("1", "r1");
|
||||
expect(AppTile.isLive("1", "r1")).toEqual(false);
|
||||
});
|
||||
|
||||
it("destroys non-persisted right panel widget on room change", async () => {
|
||||
// Set up right panel state
|
||||
const realGetValue = SettingsStore.getValue;
|
||||
@@ -170,7 +151,7 @@ describe("AppTile", () => {
|
||||
});
|
||||
await rpsUpdated;
|
||||
|
||||
expect(AppTile.isLive("1", "r1")).toBe(true);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
||||
|
||||
// We want to verify that as we change to room 2, we should close the
|
||||
// right panel and destroy the widget.
|
||||
@@ -190,7 +171,7 @@ describe("AppTile", () => {
|
||||
</MatrixClientContext.Provider>);
|
||||
|
||||
expect(endWidgetActions.mock.calls.length).toBe(1);
|
||||
expect(AppTile.isLive("1", "r1")).toBe(false);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(false);
|
||||
|
||||
mockSettings.mockRestore();
|
||||
});
|
||||
@@ -231,8 +212,8 @@ describe("AppTile", () => {
|
||||
});
|
||||
await rpsUpdated1;
|
||||
|
||||
expect(AppTile.isLive("1", "r1")).toBe(true);
|
||||
expect(AppTile.isLive("1", "r2")).toBe(false);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r2")).toBe(false);
|
||||
|
||||
jest.spyOn(SettingsStore, "getValue").mockImplementation((name, roomId) => {
|
||||
if (name === "RightPanel.phases") {
|
||||
@@ -266,8 +247,8 @@ describe("AppTile", () => {
|
||||
</MatrixClientContext.Provider>);
|
||||
await rpsUpdated2;
|
||||
|
||||
expect(AppTile.isLive("1", "r1")).toBe(false);
|
||||
expect(AppTile.isLive("1", "r2")).toBe(true);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(false);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r2")).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves non-persisted widget on container move", async () => {
|
||||
@@ -300,7 +281,7 @@ describe("AppTile", () => {
|
||||
/>
|
||||
</MatrixClientContext.Provider>);
|
||||
|
||||
expect(AppTile.isLive("1", "r1")).toBe(true);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
||||
|
||||
// We want to verify that as we move the widget to the center container,
|
||||
// the widget frame remains running.
|
||||
@@ -316,7 +297,7 @@ describe("AppTile", () => {
|
||||
});
|
||||
|
||||
expect(endWidgetActions.mock.calls.length).toBe(0);
|
||||
expect(AppTile.isLive("1", "r1")).toBe(true);
|
||||
expect(ActiveWidgetStore.instance.isLive("1", "r1")).toBe(true);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
53
test/stores/ActiveWidgetStore-test.ts
Normal file
53
test/stores/ActiveWidgetStore-test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import ActiveWidgetStore from "../../src/stores/ActiveWidgetStore";
|
||||
|
||||
describe("ActiveWidgetStore", () => {
|
||||
const store = ActiveWidgetStore.instance;
|
||||
|
||||
it("tracks docked and live tiles correctly", () => {
|
||||
expect(store.isDocked("1", "r1")).toEqual(false);
|
||||
expect(store.isLive("1", "r1")).toEqual(false);
|
||||
|
||||
// Try undocking the widget before it gets docked
|
||||
store.undockWidget("1", "r1");
|
||||
expect(store.isDocked("1", "r1")).toEqual(false);
|
||||
expect(store.isLive("1", "r1")).toEqual(false);
|
||||
|
||||
store.dockWidget("1", "r1");
|
||||
expect(store.isDocked("1", "r1")).toEqual(true);
|
||||
expect(store.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
store.dockWidget("1", "r1");
|
||||
expect(store.isDocked("1", "r1")).toEqual(true);
|
||||
expect(store.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
store.undockWidget("1", "r1");
|
||||
expect(store.isDocked("1", "r1")).toEqual(true);
|
||||
expect(store.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
// Ensure that persistent widgets remain live even while undocked
|
||||
store.setWidgetPersistence("1", "r1", true);
|
||||
store.undockWidget("1", "r1");
|
||||
expect(store.isDocked("1", "r1")).toEqual(false);
|
||||
expect(store.isLive("1", "r1")).toEqual(true);
|
||||
|
||||
store.setWidgetPersistence("1", "r1", false);
|
||||
expect(store.isDocked("1", "r1")).toEqual(false);
|
||||
expect(store.isLive("1", "r1")).toEqual(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user