Last active
April 19, 2020 12:16
-
-
Save azu/cef2684396d8199e1e852cc3cca673e5 to your computer and use it in GitHub Desktop.
SplitView on ~/.phoenix.js
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
const appNames = { | |
left: "Tweeten", | |
right: "MyDiscord" | |
} | |
const windowRatio = { | |
left: 0.75, | |
right: 0.25 | |
}; | |
/** | |
* SplitView | |
*/ | |
const splitView = ({ leftAppName, rightAppName, mainAppName }) => { | |
const leftApp = App.get(leftAppName); | |
const leftAppWindow = leftApp.mainWindow(); | |
const rightApp = App.get(rightAppName); | |
const rightAppWindow = rightApp.mainWindow(); | |
const frame = Screen.main().visibleFrame(); | |
const { width, height } = frame; | |
// Resize | |
leftAppWindow.setFrame({ x: 0, y: 0, width: width * windowRatio.left, height }); | |
rightAppWindow.setFrame({ x: width * windowRatio.left, y: 0, width: width * windowRatio.right, height }); | |
// raise up to front | |
if (leftAppName === mainAppName) { | |
rightAppWindow.raise(); | |
leftAppWindow.raise(); | |
} else { | |
leftAppWindow.raise(); | |
rightAppWindow.raise(); | |
} | |
} | |
// on active | |
Event.on('appDidActivate', app => { | |
const appName = app.name(); | |
if (appName === appNames.left || appName === appNames.right) { | |
splitView({ | |
leftAppName: appNames.left, | |
rightAppName: appNames.right, | |
mainAppName: appName | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment