Skip to content

Instantly share code, notes, and snippets.

@azu
Last active April 19, 2020 12:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/cef2684396d8199e1e852cc3cca673e5 to your computer and use it in GitHub Desktop.
Save azu/cef2684396d8199e1e852cc3cca673e5 to your computer and use it in GitHub Desktop.
SplitView on ~/.phoenix.js
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