forked from svt/bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWindow.js
55 lines (46 loc) · 1.33 KB
/
SWindow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-FileCopyrightText: 2022 Sveriges Television AB
//
// SPDX-License-Identifier: MIT
/**
* @file Implements the window API
* @description This API is INTERNAL and may change anytime,
* it is not meant to be used by plugin developers
*/
const electron = require('electron')
const windowManagement = require('../electron/windowManagement.js')
const DIController = require('../../shared/DIController')
const DIBase = require('../../shared/DIBase')
class SWindow extends DIBase {
constructor (...args) {
super(...args)
this.#setup()
}
#setup () {
this.props.SCommands.registerAsyncCommand('window.openExternal', this.openExternal.bind(this))
this.props.SCommands.registerAsyncCommand('window.toggleMaximize', this.toggleMaximize.bind(this))
}
/**
* Toggle the maximized state of the window
* currently hosting the workspace
* @returns { Promise.<Boolean> }
*/
async toggleMaximize () {
const window = await windowManagement.getWindowFromWorkspace(this.props.Workspace.id)
if (!window) {
return false
}
if (window.isMaximized()) {
window.unmaximize()
} else {
window.maximize()
}
return true
}
openExternal (url) {
return electron.shell.openExternal(url)
}
}
DIController.main.register('SWindow', SWindow, [
'Workspace',
'SCommands'
])