Called when a snapshot is being applied and some windows in that snapshot would be fully or partially off-screen. Returns an array of windows with modified positions, such that any off-screen windows are positioned in the top left corner of the main monitor.
Example
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async positionOutOfBoundsWindows(
snapshot, // The snapshot currently being applied
outOfBoundsWindows // An array of options for all windows that would be fully or partially off-screen.
) {
// By default, this function cascades out-of-bounds windows from the top left of the main monitor.
// Perhaps we wish to instead position all such windows on the bottom right.
// First, find the coordinates of the bottom right of the primary monitor
const {
primaryMonitor: {
availableRect: { right, bottom }
}
} = await fin.System.getMonitorInfo();
// Update the coordinates of each out-of-bounds window to be bottom right
const newWindows = snapshot.windows.map((windowOptions) => {
if (outOfBoundsWindows.find(w => w.name === windowOptions.name)) {
// If the window is out of bounds, set a new initial top and left
const { defaultHeight, defaultWidth } = windowOptions;
return {
...windowOptions,
defaultTop: bottom - defaultHeight,
defaultLeft: right - defaultWidth
}
} else {
return windowOptions;
}
})
// Return all windows with desired bounds
return newWindows;
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });