-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.ts
75 lines (60 loc) · 2.8 KB
/
utils.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { screen } from 'electron';
import log from 'electron-log'
import {homedir} from 'os'
import {join, resolve} from 'path'
import { execSync, execFile } from 'child_process'
import { Config } from './src/shared/config';
import { Logger } from './src/shared/logger';
const logger = new Logger('WINDOW MANAGER')
log.transports.file.resolvePath = () => join(homedir(), '.hyperlogs/main.log');
export function stringToHex(color: string){
return Number(color.replace("#", "0x")) || 0x000000
}
export function generateBounds() {
const configSizes = new Config("appearence.items.sizes.fields")
const configDock = new Config("general.items.position.fields")
const { width, height } = screen.getPrimaryDisplay().workAreaSize
logger.debug(`Detected Sreen Size: ${width}x${height}`)
const dockedTop = configDock.get('dock-pos.value') == "top"
const barHeight = Number(configSizes.get("height.value"))
const horizontalMargin = Number(configDock.get("horizontal-margin.value"))
const verticalMargin = Number(configDock.get("vertical-margin.value"))
const calculated = {
width: width - horizontalMargin * 2,
height: barHeight,
x: horizontalMargin,
y: dockedTop
? barHeight < 39
? barHeight - 39 + verticalMargin
: verticalMargin
// I don't know why 11, ask microsoft
: height - barHeight - verticalMargin
}
return calculated
}
export function removeAppBar(){
const exeLocation = resolve(__dirname, 'bin', 'Hyper Spacer.exe')
endAppBar()
execFile(`${exeLocation}`, ["0"]) // Change size or set to 0
}
export function endAppBar() {
try { execSync('taskkill /T /F /IM "Hyper Spacer.exe"') } catch {logger.info("Hyper Spacer is not running") }
}
export function makeAppBar() {
const promise = new Promise((resolvePromise, rejectPromise) => {
const config = new Config()
const shouldDock = config.getValue('general', 'behavior', 'reserve-space')
const reservedSpace = config.getValue('appearence', 'sizes', 'height') as number
const reservedMargin = config.getValue('general', 'position', 'vertical-margin') as number
const dockPos = config.getValue('general', 'position', 'dock-pos')
logger.info("Initializing space reservation")
endAppBar()
setTimeout(()=>{
const exeLocation = resolve(__dirname, 'bin', 'Hyper Spacer.exe')
execFile(`${exeLocation}`, [String(reservedSpace + reservedMargin * 2),`${shouldDock ? dockPos == "top" ? 'Top' : 'Bottom' : 0}`]) // Change size or set to 0
logger.success("Space reserved!", String(reservedSpace + reservedMargin * 2),`${shouldDock ? dockPos == "top" ? 'Top' : 'Bottom' : 0}`)
resolvePromise(true)
}, 100)
})
return promise
}