forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDA-3990: Hide all windows and restore with previously focused window (…
- Loading branch information
1 parent
afc5d68
commit ba1ad1d
Showing
7 changed files
with
168 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { WindowStore } from './window-store'; | ||
|
||
const winStore = new WindowStore(); | ||
|
||
export { winStore }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { BrowserWindow } from 'electron'; | ||
import { getWindowByName } from '../window-utils'; | ||
|
||
export interface IWindowObject { | ||
windows: IWindowState[]; | ||
} | ||
|
||
export interface IWindowState { | ||
id: string; | ||
minimized?: boolean; | ||
focused?: boolean; | ||
} | ||
|
||
export class WindowStore { | ||
private windowVariable: IWindowObject = { | ||
windows: [], | ||
}; | ||
|
||
// Send signal | ||
public setWindowStore = (signalData: IWindowObject) => { | ||
this.windowVariable = { ...signalData }; | ||
}; | ||
|
||
// Destroy signal | ||
public destroyWindowStore = () => { | ||
this.windowVariable = { | ||
windows: [], | ||
} as IWindowObject; | ||
}; | ||
|
||
// Retrieve signal | ||
public getWindowStore = (): IWindowObject => { | ||
return { ...this.windowVariable } as IWindowObject; | ||
}; | ||
|
||
public hideWindowsOnCapturing = (hideOnCapture?: boolean) => { | ||
if (hideOnCapture) { | ||
const currentWindows = BrowserWindow.getAllWindows(); | ||
|
||
currentWindows.forEach((currentWindow) => { | ||
currentWindow?.hide(); | ||
}); | ||
} | ||
}; | ||
|
||
public focusWindowsSnippingFinished = (hideOnCapture?: boolean) => { | ||
if (hideOnCapture) { | ||
const currentWindows = this.getWindowStore(); | ||
const currentWindow = currentWindows.windows.find( | ||
(currentWindow) => currentWindow.focused, | ||
); | ||
|
||
if (currentWindow) { | ||
if (!currentWindow.minimized) { | ||
getWindowByName(currentWindow.id || '')?.show(); | ||
} | ||
|
||
if (currentWindow.focused) { | ||
getWindowByName(currentWindow.id || '')?.focus(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
public restoreWindowsOnCapturing = (hideOnCapture?: boolean) => { | ||
if (hideOnCapture) { | ||
const currentWindows = this.getWindowStore(); | ||
currentWindows.windows.forEach((currentWindow) => { | ||
if (!currentWindow.minimized) { | ||
getWindowByName(currentWindow.id || '')?.show(); | ||
} | ||
|
||
if (currentWindow.focused) { | ||
getWindowByName(currentWindow.id || '')?.focus(); | ||
} | ||
}); | ||
|
||
this.destroyWindowStore(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters