Skip to content

Commit

Permalink
Ensure a search window appears (#2743)
Browse files Browse the repository at this point in the history
Only make the search window persistable
  • Loading branch information
jameskerr authored Mar 31, 2023
1 parent f835e04 commit a922703
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/js/electron/windows/about-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {WindowName} from "../windows/types"
import {ZuiWindow} from "./zui-window"

export class AboutWindow extends ZuiWindow {
persistable: false
name: WindowName = "about"
options = {
width: 360,
Expand Down
1 change: 0 additions & 1 deletion src/js/electron/windows/hidden-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {ZuiWindow} from "./zui-window"

export class HiddenWindow extends ZuiWindow {
name: WindowName = "hidden"
persistable = false
options = {
show: false,
width: 0,
Expand Down
1 change: 1 addition & 0 deletions src/js/electron/windows/search/search-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ZuiWindow} from "../zui-window"
import {createMenu, SearchAppMenuState} from "./app-menu"

export class SearchWindow extends ZuiWindow {
persistable = true
name: WindowName = "search"
options: BrowserWindowConstructorOptions = {
titleBarStyle: env.isMac ? "hidden" : undefined,
Expand Down
38 changes: 38 additions & 0 deletions src/js/electron/windows/window-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import initIpcListeners from "src/js/initializers/initIpcListeners"
import initTestStore from "src/test/unit/helpers/initTestStore"
import {encodeSessionState} from "../session-state"
import {WindowManager} from "./window-manager"

let store = initTestStore()
Expand All @@ -29,3 +30,40 @@ test("serialize each window", async () => {
},
])
})

test("does not serialize detail hidden or about window", async () => {
const manager = new WindowManager()
await manager.create("detail")
await manager.create("hidden")
await manager.create("about")
expect(await manager.serialize()).toEqual([])
})

test("brings up a search window if none exists", async () => {
const instance1 = new WindowManager()
await instance1.create("detail")
await instance1.create("hidden")
await instance1.create("about")

const state = await instance1.serialize()
const session = encodeSessionState(state, null)
const instance2 = new WindowManager(session)
await instance2.init()
expect(instance2.all.map((w) => w.name)).toEqual(["search", "hidden"])
})

test("does not brings up a search window if one exists", async () => {
const instance1 = new WindowManager()
await instance1.create("search")
await instance1.create("search")

const state = await instance1.serialize()
const session = encodeSessionState(state, null)
const instance2 = new WindowManager(session)
await instance2.init()
expect(instance2.all.map((w) => w.name)).toEqual([
"search",
"search",
"hidden",
])
})
2 changes: 1 addition & 1 deletion src/js/electron/windows/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WindowManager extends EventEmitter {
.map(deserializeWindow)
await Promise.all(windows.map((w) => this.register(w)))
}
if (this.count === 0) await this.create("search")
if (this.byName("search").length === 0) await this.create("search")
if (this.byName("hidden").length === 0) await this.create("hidden")
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/electron/windows/zui-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export abstract class ZuiWindow {
lastFocused: number
state: State | undefined
dimens: Dimens | null = null
persistable = true
persistable = false
initialized = new TimedPromise(60_000)

constructor(props: WindowProps = {}) {
Expand Down
44 changes: 25 additions & 19 deletions src/test/shared/__mocks__/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class BrowserWindow {
isDestroyed = jest.fn(() => false)
focus = jest.fn()
visible = true
getBounds() {
return {x: 0, y: 0}
}
center() {}
setMenu() {}
on() {
Expand Down Expand Up @@ -108,27 +111,30 @@ export const Menu = {
setApplicationMenu: jest.fn(),
}

const display = {
id: 459098087,
bounds: {x: 0, y: 0, width: 1920, height: 1080},
workArea: {x: 0, y: 23, width: 1920, height: 1057},
accelerometerSupport: "unknown",
monochrome: false,
colorDepth: 24,
colorSpace:
"{primaries_d50_referred: [[0.6825, 0.3155], [0.3001, 0.6589], [0.1589, 0.0529]], transfer:BT709_APPLE, matrix:RGB, range:FULL}",
depthPerComponent: 8,
size: {width: 1920, height: 1080},
workAreaSize: {width: 1920, height: 1057},
scaleFactor: 2,
rotation: 0,
internal: false,
touchSupport: "unknown",
}

export const screen = {
getDisplayNearestPoint() {
return display
},
getAllDisplays() {
return [
{
id: 459098087,
bounds: {x: 0, y: 0, width: 1920, height: 1080},
workArea: {x: 0, y: 23, width: 1920, height: 1057},
accelerometerSupport: "unknown",
monochrome: false,
colorDepth: 24,
colorSpace:
"{primaries_d50_referred: [[0.6825, 0.3155], [0.3001, 0.6589], [0.1589, 0.0529]], transfer:BT709_APPLE, matrix:RGB, range:FULL}",
depthPerComponent: 8,
size: {width: 1920, height: 1080},
workAreaSize: {width: 1920, height: 1057},
scaleFactor: 2,
rotation: 0,
internal: false,
touchSupport: "unknown",
},
]
return [display]
},
}

Expand Down

0 comments on commit a922703

Please sign in to comment.