Created
March 1, 2017 20:22
-
-
Save itzexor/8f0c8e441903e4962ca155258b1e5b5b to your computer and use it in GitHub Desktop.
power-switcher@exor
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 Applet = imports.ui.applet; | |
const Lang = imports.lang; | |
const Util = imports.misc.util; | |
function MyApplet(orientation, panel_height, instance_id) { | |
this._init(orientation, panel_height, instance_id); | |
} | |
MyApplet.prototype = { | |
__proto__: Applet.IconApplet.prototype, | |
_init: function(orientation, panel_height, instance_id) { | |
Applet.IconApplet.prototype._init.call(this, orientation, panel_height, instance_id); | |
this.cur_attempts = 0; | |
this.enabled = false; | |
this.set_applet_icon_name("non-starred-symbolic"); | |
this.set_applet_tooltip("Click to enable performance mode"); | |
}, | |
on_click: function() { | |
if (this.cur_attempts > 1) { | |
this.cur_attempts = 0; | |
return; | |
} | |
else if (this.enabled) { | |
Util.spawnCommandLineAsync("gksudo \"sh -c 'echo 'auto' > /sys/class/drm/card0/device/power_dpm_force_performance_level; cpupower frequency-set -g powersave'\"", | |
Lang.bind(this, this.toggle_state_cb), | |
Lang.bind(this, this.on_click)); | |
} else { | |
Util.spawnCommandLineAsync("gksudo \"sh -c 'echo 'high' > /sys/class/drm/card0/device/power_dpm_force_performance_level; cpupower frequency-set -g performance'\"", | |
Lang.bind(this, this.toggle_state_cb), | |
Lang.bind(this, this.on_click)); | |
} | |
this.cur_attempts++; | |
}, | |
toggle_state_cb: function() { | |
this.enabled = !this.enabled; | |
this.cur_attempts = 0; | |
if (this.enabled) { | |
this.set_applet_icon_name("starred-symbolic"); | |
this.set_applet_tooltip("Click to enable powersave mode"); | |
} else { | |
this.set_applet_icon_name("non-starred-symbolic"); | |
this.set_applet_tooltip("Click to enable performance mode"); | |
} | |
}, | |
on_applet_clicked: function() { | |
this.on_click(); | |
}, | |
on_applet_removed_from_panel: function() { | |
if (this.enabled) this.on_click(); | |
} | |
}; | |
function main(metadata, orientation, panel_height, instance_id) { | |
return new MyApplet(orientation, panel_height, instance_id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment