Coder Social home page Coder Social logo

fidget's Introduction

Fidget

A cross platform tool to prevent your computer from sleeping.

Overview

Do you really dig caffeinate on OS X and wish that you could use it on Windows? Are you building something that supports multiple platforms and need the display to stay on without much fuss? Does the phrase "Yes. gnome-screensaver has a simple to use DBus API for this" make you irrationally angry?

If so, this might be the tool for you. Fidget provides both a commandline tool and a library to simply and easily inhibit sleep on all major platforms.

Usage

$ fidget [-o <options>] [command]

Options should be passed as a comma-separated list. Sleep options may very between platforms. Each platform will include at least the following core options:

  • display will prevent the display from sleeping.
  • sleep prevent the system from sleeping.
  • all to declare all known options.

Additional OS X options:

  • idle will prevent the system from idle sleeping.
  • disk will prevent the disk from sleeping.
  • 'user' will assert that the user is active. This keeps the display on and prevents idle sleep.

Additional Windows options:

  • away enables a low-power, but not sleeping, mode on Windows.
  • simulate will simulate a user keyboard action every few seconds.

Additional Linux options:

  • blanking disables terminal blanking on Linux.

Default options for each platform:

  • OS X: user
  • Linux: display
  • Windows: display,sleep

If you pass a command, then Fidget will execute that command and prevent the system from sleeping until that command terminates. If you do not provide a command, then Fidget will prevent sleeping until you press Ctrl-C to terminate.

Examples

Simply keep the computer from sleeping until you press Ctrl-C

$ fidget
System has been prevented from sleeping.
- Press Ctrl-C to resume normal power management.

Pass options and run a command

$ fidget -o sleep,idle make

Installation

$ gem install fidget

Library Usage

There are three methods you may use in your programs. The options parameter should be either an array or just a list of options and can be passed as strings or symbols.

  • Fidget.prevent_sleep(options)
    • Stops the computer from sleeping.
    • Can accept a block, in which case sleep will be inhibited during the execution of the block and resumed after.
  • Fidget.allow_sleep
    • Resume any previously inhibited sleep.
  • Fidget.current_process(options)
    • Shortcut method to inhibit sleep during the execution of the current process.

Examples

Default options, with a block:

#! /usr/bin/env ruby
require 'fidget'

Fidget.prevent_sleep do
  100.times do
    print '.'
    sleep 1
  end
end

Define sleep options to inhibit, with a block:

#! /usr/bin/env ruby
require 'fidget'

Fidget.prevent_sleep(:display, :sleep) do
  100.times do
    print '.'
    sleep 1
  end
end

No block, just calling methods:

#! /usr/bin/env ruby
require 'fidget'

Fidget.prevent_sleep(:display, :sleep)

100.times do
  print '.'
  sleep 1
end

Fidget.allow_sleep

Simply prevent the computer from sleeping while the current process is running:

#! /usr/bin/env ruby
require 'fidget'

Fidget.current_process

100.times do
  print '.'
  sleep 1
end

Limitations

This is super early in development and has not yet been battle tested. If you discover a platform it doesn't work on, or a use case that it should cover, please do file an issue

Disclaimer

I take no liability for the use of this tool.

Contact

[email protected]

fidget's People

Contributors

binford2k avatar marrero984 avatar smortex avatar

Watchers

 avatar

fidget's Issues

Should have another option for `:common` settings

Right now you either have to list all the sleep options you want, or set :all. This should have another :common option that would have most settings, but not things like :simulate or :blanking, etc.

craps out when Xorg isn't installed

/usr/local/share/gems/gems/fidget-0.0.3/lib/fidget/platform/linux.rb:43:in ``': No such file or directory - xwininfo (Errno::ENOENT)
	from /usr/local/share/gems/gems/fidget-0.0.3/lib/fidget/platform/linux.rb:43:in `root_win'
	from /usr/local/share/gems/gems/fidget-0.0.3/lib/fidget/platform/linux.rb:55:in `suspend'
	from /usr/local/share/gems/gems/fidget-0.0.3/lib/fidget/platform/linux.rb:15:in `prevent_sleep'
	from /usr/local/share/gems/gems/fidget-0.0.3/lib/fidget.rb:28:in `prevent_sleep'
	from /usr/local/share/gems/gems/fidget-0.0.3/bin/fidget:63:in `<top (required)>'
	from /usr/local/bin/fidget:23:in `load'
	from /usr/local/bin/fidget:23:in `<main>'

Platform support

I am fairly confident that this will work on pretty much any modern OS X or Windows machine. Linux is another story though! It's only feasible for me to test on a few distros, so it would be swell if you'd help me out and test it on your distro of choice.

Please post a comment with your distro, platform, any special configuration, etc. Use ๐Ÿ‘ to indicate it works and ๐Ÿšซ to indicate that it failed. Please include the backtrace or any error messages too!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.