Last active
August 29, 2015 14:02
-
-
Save ka2n/80502b43e761a75ca1e2 to your computer and use it in GitHub Desktop.
Sqwiggle minimum mode
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
/* | |
# Save this file to /Applications/Sqwiggle.app/Contents/Resources/app.nw/assets/js/toggle.js | |
# And Add | |
<script src="assets/js/toggle.js" type="text/javascript"></script> | |
to /Applications/Sqwiggle.app/Contents/Resources/app.nw/index.html | |
*/ | |
process.removeAllListeners('uncaughtException'); // Disable Sentry | |
var plugin = function() { | |
var nw_gui = require('nw.gui'); | |
var nw_win = nw_gui.Window.get(); | |
var initial = { | |
x: 0, | |
y: 0, | |
width: 0, | |
height: 0 | |
}, | |
conf = { | |
current: -1, | |
pos: [ | |
{ | |
// right | |
x: window.screen.availWidth - 360, | |
y: window.screen.availTop, | |
width: 360, | |
height: window.screen.availHeight | |
}, | |
{ | |
// bottom | |
x: window.screen.availLeft, | |
y: window.screen.availHeight - 250, | |
width: window.screen.availWidth, | |
height: 250 | |
} | |
] | |
}, | |
min = false; | |
var item = new nw_gui.MenuItem({label: "Toggle minimum mode", click: function(){ | |
if (min) { | |
// Restore | |
App.mainRegion.minWidth = 360; | |
App.mainRegion.$el.width(App.mainRegion.minWidth); | |
nw_win.resizeTo(initial.width, initial.height); | |
nw_win.moveTo(initial.x, initial.y); | |
min = false; | |
} else { | |
// Switch to minimum mode | |
initial.width = nw_win.width; | |
initial.height = nw_win.height; | |
initial.x = nw_win.x; | |
initial.y = nw_win.y; | |
App.mainRegion.minWidth = 0; | |
App.mainRegion.$el.width(0); | |
var idx; | |
if (conf.current === -1 || conf.current >= conf.pos.length-1) { | |
idx = 0; | |
} else { | |
idx = conf.current + 1; | |
} | |
var pos = conf.pos[idx]; | |
nw_win.resizeTo(pos.width, pos.height); | |
nw_win.moveTo(pos.x, pos.y); | |
min = true; | |
conf.current = idx; | |
} | |
}}); | |
nw_win.menu.items[0].submenu.append(item); | |
}; | |
var original = App.loadApplication; | |
App.loadApplication = function() { | |
original(); | |
plugin(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment