flashtoggle 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/flashtoggle +42 -0
- data/lib/flashtoggle.rb +7 -0
- data/lib/flashtoggle/toggler.rb +59 -0
- data/lib/flashtoggle/version.rb +4 -0
- metadata +85 -0
data/bin/flashtoggle
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'flashtoggle'
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
banner = "FlashToggle #{Flashtoggle::VERSION} (C) 2011 Brian P. Hogan\n"
|
7
|
+
banner << "-" * banner.length
|
8
|
+
puts banner
|
9
|
+
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: flashtoggle on | off | status"
|
12
|
+
end.parse!
|
13
|
+
|
14
|
+
command = ARGV[0]
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
plugins_dir = "/Library/Internet\ Plug-Ins"
|
19
|
+
backup_dir = "/Library/InternetPluginsDisabled"
|
20
|
+
|
21
|
+
toggler = Flashtoggle::Toggler.new(plugins_dir, backup_dir)
|
22
|
+
|
23
|
+
case command
|
24
|
+
when "on"
|
25
|
+
puts "Enabling Flash in Safari"
|
26
|
+
toggler.enable_flash!
|
27
|
+
puts "Done!"
|
28
|
+
when "off"
|
29
|
+
puts "Disabling Flash in Safari"
|
30
|
+
toggler.disable_flash!
|
31
|
+
puts "Done!"
|
32
|
+
when "status"
|
33
|
+
puts toggler.status
|
34
|
+
else
|
35
|
+
toggler.toggle!
|
36
|
+
puts toggler.status
|
37
|
+
end
|
38
|
+
|
39
|
+
if toggler.error
|
40
|
+
puts toggler.error
|
41
|
+
end
|
42
|
+
|
data/lib/flashtoggle.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Flashtoggle
|
2
|
+
class Toggler
|
3
|
+
|
4
|
+
attr_accessor :plugins_dir, :backup_dir, :error
|
5
|
+
|
6
|
+
def initialize(plugins_dir, backup_dir)
|
7
|
+
self.plugins_dir = plugins_dir
|
8
|
+
self.backup_dir = backup_dir
|
9
|
+
end
|
10
|
+
|
11
|
+
def toggle!
|
12
|
+
if self.flash_off?
|
13
|
+
self.enable_flash!
|
14
|
+
else
|
15
|
+
self.disable_flash!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def status
|
20
|
+
self.flash_on? ? "Flash is currently enabled" : "Flash is currently disabled"
|
21
|
+
end
|
22
|
+
|
23
|
+
def enable_flash!
|
24
|
+
return if flash_on?
|
25
|
+
begin
|
26
|
+
Flashtoggle::FLASH_PLUGIN_FILES.each do |file|
|
27
|
+
FileUtils.mv "#{self.backup_dir}/#{file}", "#{self.plugins_dir}/#{file}"
|
28
|
+
end
|
29
|
+
rescue Errno::EACCES => e
|
30
|
+
self.error = "You must run this script by using - sudo flashtoggle [options]"
|
31
|
+
rescue Errno::ENOENT => e
|
32
|
+
self.error = "That folder can't be found"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def disable_flash!
|
37
|
+
return if flash_off?
|
38
|
+
begin
|
39
|
+
FileUtils.mkdir_p self.backup_dir
|
40
|
+
Flashtoggle::FLASH_PLUGIN_FILES.each do |file|
|
41
|
+
FileUtils.mv "#{self.plugins_dir}/#{file}", "#{self.backup_dir}/#{file}"
|
42
|
+
end
|
43
|
+
rescue Errno::EACCES => e
|
44
|
+
self.error = "You must run this script by using - sudo flashtoggle [options]"
|
45
|
+
rescue Errno::ENOENT => e
|
46
|
+
self.error = "That folder can't be found"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def flash_on?
|
51
|
+
File.exists?("#{self.plugins_dir}/#{Flashtoggle::FLASH_PLUGIN_FILES[0]}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def flash_off?
|
55
|
+
File.exists?("#{self.backup_dir}/#{ Flashtoggle::FLASH_PLUGIN_FILES[0]}")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flashtoggle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian Hogan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-16 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mocha
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Commandline tool to enable and disable the Flash player in Safari and other applications that use Safari. This conserves battery life and, unlike Flash blocking solutions, this causes web sites to serve alternative content since Flash is truly not available.
|
36
|
+
email: info@napcs.com
|
37
|
+
executables:
|
38
|
+
- flashtoggle
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- bin/flashtoggle
|
45
|
+
- lib/flashtoggle/version.rb
|
46
|
+
- lib/flashtoggle.rb
|
47
|
+
- lib/flashtoggle/toggler.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/napcs/flashtoggle
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 23
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 3
|
75
|
+
- 6
|
76
|
+
version: 1.3.6
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Enable and disable Flash in OSX
|
84
|
+
test_files: []
|
85
|
+
|