Skip to content

Instantly share code, notes, and snippets.

@slagyr
Last active January 9, 2019 23:44
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 slagyr/9cebd13524c419738f9d59d6e1aaede5 to your computer and use it in GitHub Desktop.
Save slagyr/9cebd13524c419738f9d59d6e1aaede5 to your computer and use it in GitHub Desktop.
Autumn code
/**
* Micah's Autumn setup
*/
alert('Running Autumn!');
/**
* Window management
*/
const { Command, Control, Option, Shift } = Hotkey.Mods;
const grid = new GridWM();
grid.rows = localStorage.getItem('rows') as number || 2;
grid.cols = localStorage.getItem('cols') as number || 6;
Hotkey.activate(Command | Control | Option, 'h', () => grid.moveLeft());
Hotkey.activate(Command | Control | Option, 'l', () => grid.moveRight());
Hotkey.activate(Command | Control | Option, 'k', () => { grid.shrinkFromBelow(); grid.moveUp() });
Hotkey.activate(Command | Control | Option, 'j', () => { grid.shrinkFromAbove(); grid.moveDown() });
Hotkey.activate(Command | Shift | Option, 'h', () => Window.focusedWindow().focusNext(Window.Dir.Left));
Hotkey.activate(Command | Shift | Option, 'l', () => Window.focusedWindow().focusNext(Window.Dir.Right));
Hotkey.activate(Command | Shift | Option, 'k', () => Window.focusedWindow().focusNext(Window.Dir.Up));
Hotkey.activate(Command | Shift | Option, 'j', () => Window.focusedWindow().focusNext(Window.Dir.Down));
Hotkey.activate(Command | Control | Option, 'o', () => grid.growRight());
Hotkey.activate(Command | Control | Option, 'i', () => grid.shrinkFromRight());
Hotkey.activate(Command | Control | Option, 'u', () => grid.fillCurrentColumn());
Hotkey.activate(Command | Control | Option, 'm', () => grid.moveToCellGroup(grid.fullScreenCellGroup()));
Hotkey.activate(Command | Control | Option, 'c', () => Window.focusedWindow().centerOnScreen());
Hotkey.activate(Command | Control | Option, ';', () => grid.align());
Hotkey.activate(Command | Control | Option, "'", () => grid.alignAll());
Hotkey.activate(Command | Control | Option, 'n', () => grid.moveToNextScreen());
Hotkey.activate(Command | Control | Option, 'p', () => grid.moveToPreviousScreen());
Hotkey.activate(Command | Control | Option, '-', () => changeWidthBy(-1));
Hotkey.activate(Command | Control | Option, '=', () => changeWidthBy(+1));
function changeWidthBy(n) {
grid.cols = Math.max(1, grid.cols + n);
localStorage.setItem('cols', grid.cols);
alert(`Grid width is now ${grid.cols}`);
grid.alignAll();
}
alert(`Running GridWM example, rows = ${grid.rows}, cols = ${grid.cols}`);
/**
* Show welcome message when computer wakes from sleep
*/
let sleepTime: number;
Power.onSleep = () => {
const now = new Date();
sleepTime = now.getTime();
console.log(`Good night! Sleeping at ${now.toLocaleString()}.`);
};
Power.onWake = () => {
const now = new Date();
let time = Math.floor((now.getTime() - sleepTime) / 1000);
const delay = 7; // seconds
alert("Good morning!", delay);
alert(`It's ${now.toLocaleString()}.`, delay);
alert(`Computer slept for ${hhmmss(time)}.`, delay);
}
function hhmmss(time) {
const s = time % 60;
time = Math.floor(time / 60);
const m = time % 60;
time = Math.floor(time / 60);
const h = time;
return [h, m, s].map(padWithZeroes).join(':');
}
function padWithZeroes(n: number) {
return n.toString().padStart(2, '0');
}
alert("Wakeup stretch enabled");
// Caffeine replacement
let sleepAllower = null;
let timeout = null;
resetMenu();
function endSleep() {
if (timeout !== null) clearTimeout(timeout);
sleepAllower();
sleepAllower = null;
alert("Power Save: That'll do pig, that'll do.");
resetMenu();
}
function resetMenu() {
const menuItems = [];
if (sleepAllower === null) {
menuItems.push({
title: 'Power Save: Prevent sleep',
onClick: () => {
sleepAllower = Power.preventSleep();
alert('Power Save: Staying awake indefinitely!');
resetMenu();
}
});
menuItems.push({
title: 'Power Save: Prevent sleep for 30 minutes',
onClick: () => {
sleepAllower = Power.preventSleep();
alert('Power Save: Staying awake for 30 minutes!');
resetMenu();
timeout = setTimeout(endSleep, 1000 * 60 * 30);
}
});
}
else {
menuItems.push({
title: 'Power Save: Allow sleep again',
onClick: endSleep,
});
}
Autumn.setStatusMenuItems(menuItems);
}
alert("Caffeine replacement installed");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment