2023-10-02 12:06:35 -04:00
|
|
|
import { App, Widget } from '../../imports.js';
|
|
|
|
const { Window, EventBox } = Widget;
|
|
|
|
const { closeWindow } = App;
|
2023-09-12 14:42:53 -04:00
|
|
|
|
2023-09-25 12:43:36 -04:00
|
|
|
const ALWAYS_OPEN = [
|
|
|
|
'closer',
|
|
|
|
'bar',
|
|
|
|
'notifications',
|
|
|
|
];
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-14 13:33:59 -04:00
|
|
|
// TODO: close on scroll event too?
|
2023-09-13 19:04:23 -04:00
|
|
|
export const closeAll = () => {
|
2023-10-02 12:06:35 -04:00
|
|
|
App.windows.forEach(w => {
|
2023-09-25 12:43:36 -04:00
|
|
|
if (!ALWAYS_OPEN.some(window => window === w.name))
|
2023-10-02 12:06:35 -04:00
|
|
|
closeWindow(w.name)
|
2023-09-13 19:04:23 -04:00
|
|
|
});
|
2023-09-25 12:43:36 -04:00
|
|
|
closeWindow('closer');
|
2023-09-13 19:04:23 -04:00
|
|
|
};
|
2023-09-12 09:37:48 -04:00
|
|
|
|
|
|
|
export const Closer = Window({
|
2023-09-11 19:57:21 -04:00
|
|
|
name: 'closer',
|
|
|
|
popup: true,
|
|
|
|
layer: 'top',
|
2023-10-07 21:02:23 -04:00
|
|
|
anchor: [ 'top', 'bottom', 'left', 'right' ],
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-09-12 09:37:48 -04:00
|
|
|
child: EventBox({
|
2023-09-12 14:42:53 -04:00
|
|
|
onPrimaryClickRelease: () => closeAll(),
|
2023-10-02 12:06:35 -04:00
|
|
|
connections: [[App, (_b, _w, _v) => {
|
|
|
|
if (!Array.from(App.windows).some(w => w[1].visible &&
|
2023-09-25 12:43:36 -04:00
|
|
|
!ALWAYS_OPEN.some(window => window === w[0]))) {
|
2023-09-18 17:39:10 -04:00
|
|
|
closeWindow('closer');
|
|
|
|
}
|
|
|
|
}]],
|
2023-09-11 19:57:21 -04:00
|
|
|
}),
|
|
|
|
});
|