Last active
December 3, 2019 09:09
-
-
Save josser/06ae93c75dc132127c9205a75a94b6a0 to your computer and use it in GitHub Desktop.
Phoenix config
This file contains hidden or 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
'use strict'; | |
var keys = []; | |
var controlAlt = [ 'ctrl', 'alt' ]; | |
var margin = 0; | |
var increment = 0.1 | |
function log() { | |
Phoenix.log(JSON.stringify(arguments[0], true, 2)); | |
} | |
var Displays = { | |
Internal: 1, | |
External: 0 | |
} | |
Window.prototype.midCenter = function () { | |
var currScreenFrame = this.screen().flippedVisibleFrame(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * 0.75, | |
height: currScreenFrame.height * 0.75, | |
x: currScreenFrame.x + currScreenFrame.width * 0.125, | |
y: currScreenFrame.y + currScreenFrame.height * 0.125 | |
} | |
this.setFrame(newWindowFrame); | |
} | |
Window.prototype.sideLeft = function (proportion) { | |
var coefficient = proportion || 0.5; | |
var currScreenFrame = this.screen().flippedVisibleFrame(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * coefficient, | |
height: currScreenFrame.height, | |
x: currScreenFrame.x, | |
y: currScreenFrame.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
Window.prototype.sideRight = function (proportion) { | |
var coefficient = proportion || 0.5; | |
var currScreenFrame = this.screen().flippedVisibleFrame(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * coefficient, | |
height: currScreenFrame.height, | |
x: currScreenFrame.x + currScreenFrame.width * (1 - coefficient), | |
y: currScreenFrame.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
Window.prototype.throwTo = function (screen) { | |
var currScreenFrame = this.screen().flippedVisibleFrame(); | |
var currWindowFrame = this.frame(); | |
var aspectRatios = { | |
width: currWindowFrame.width / currScreenFrame.width, | |
height: currWindowFrame.height / currScreenFrame.height, | |
x: Math.abs((currScreenFrame.x - currWindowFrame.x) / currScreenFrame.width), | |
y: Math.abs((currScreenFrame.y - currWindowFrame.y) / currScreenFrame.height) | |
} | |
var screens = Screen.all(); | |
var targetScreenFrame = screens[screen].flippedVisibleFrame(); | |
var newWindowFrame = { | |
width: targetScreenFrame.width * aspectRatios.width, | |
height: targetScreenFrame.height * aspectRatios.height, | |
x: targetScreenFrame.x + targetScreenFrame.width * aspectRatios.x, | |
y: targetScreenFrame.y + targetScreenFrame.height * aspectRatios.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
keys.push(Key.on('up', controlAlt, function () { | |
Window.focused() && Window.focused().maximize(); | |
})); | |
// | |
keys.push(Key.on('down', controlAlt, function () { | |
Window.focused() && Window.focused().midCenter(); | |
})); | |
// | |
keys.push(Key.on('left', controlAlt, function () { | |
Window.focused() && Window.focused().sideLeft() | |
})); | |
// | |
keys.push(Key.on('right', controlAlt, function () { | |
Window.focused() && Window.focused().sideRight() | |
})); | |
keys.push(Key.on('[', controlAlt, function () { | |
Window.focused() && Window.focused().throwTo(Displays.Internal); | |
})); | |
keys.push(Key.on(']', controlAlt, function () { | |
Window.focused() && Window.focused().throwTo(Displays.External); | |
})); | |
var AppsConfig = { | |
get: function () { | |
return AppsConfig.test[AppsConfig.selector()]; | |
}, | |
selector: function () { | |
return Screen.all().length; | |
}, | |
test: { | |
1: { | |
'Skype': function (window){ | |
window.throwTo(Displays.External).sideLeft(0.5); | |
}, | |
'Telegram': function (window) { | |
window.throwTo(Displays.External).sideRight(); | |
}, | |
'Slack': function (window) { | |
window.throwTo(Displays.Internal).sideRight(0.5); | |
} | |
}, | |
2: { | |
'Skype': function (window){ | |
window.throwTo(Displays.Internal).sideLeft(0.5); | |
}, | |
'Telegram': function (window) { | |
window.throwTo(Displays.Internal).sideRight(); | |
}, | |
'Slack': function (window) { | |
window.throwTo(Displays.Internal).sideRight(0.5); | |
} | |
} | |
} | |
}; | |
keys.push(Key.on('delete', ['ctrl', 'alt', 'cmd'], function () { | |
var apps = App.all(); | |
var appsConfig = AppsConfig.get(); | |
_.each(apps, function (app) { | |
appsConfig[app.name()] && appsConfig[app.name()](app.mainWindow()); | |
}) | |
})); | |
Phoenix.set({ | |
daemon: false, | |
openAtLogin: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment