windows-shutdown-timer 1.0.3 → 1.0.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/windows-shutdown-timer.rb +18 -21
  3. metadata +6 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6bb12218d76cf41b3a10d5d1e29b7a872850976
4
- data.tar.gz: 805aa77ee11cd70235c99dd9e1450bb1da726fe3
3
+ metadata.gz: d2bbab4a47efab295daec7503f914f181ca4e9db
4
+ data.tar.gz: 33e69351d18e713fec57faeb4449d53b3453a10d
5
5
  SHA512:
6
- metadata.gz: a767438c139758e832e1d251f984dc6f208da89e5b657cc1933c90be69644ccf6d7901f94eb293cdd7efd9ccbc52b48edd4dbc0c950866fc925bce761d56f4dc
7
- data.tar.gz: 855cc1a5a51388e437befe9c36a1cd0a8d7e13f2f7f2e62f4d72fb1b6f051e76dacadefaaa5ec2ca24acdba98450f0d7babb543df684f604d6c6044e4b1dbf94
6
+ metadata.gz: 7a2e79b59b7f80d8993c46556a527e33968b1ec7ffdaf88c9bc357c734aa1fca7bcf95b3e2f0e8994d833dc0718703a24715f8f1238decbb1e66fb9a777b40a2
7
+ data.tar.gz: 4b56f2e381cdcd4ff42cd4099afc0d8ef557254a19b4fa4d1eab2736af96c061609a09a7874e7cfb391d74b251edf283995a50f2d248a2753e3f416f0096b7c7
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'open-uri'
2
3
  require 'net/http'
3
4
  require 'fileutils'
4
5
  require 'zip'
@@ -6,17 +7,15 @@ require 'zip'
6
7
  module WindowsShutdownTimer
7
8
  # Shutdown!
8
9
  class ShutdownStarter
9
-
10
- INSOMNIA = 'Insomnia.exe'
11
- PATH_TO_TEMP = Dir.tmpdir + '/windows-shutdown-timer'
12
- PATH_TO_INSOMNIA = PATH_TO_TEMP + '/' + INSOMNIA
13
- PATH = 'insomnia/64-bit'
14
- COMMAND_SHUTDOWN = 'shutdown /s /t '
15
- COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'
16
- COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}"
10
+ INSOMNIA = 'Insomnia.exe'.freeze
11
+ PATH_TO_TEMP = (Dir.tmpdir + '/windows-shutdown-timer').freeze
12
+ PATH_TO_INSOMNIA = (PATH_TO_TEMP + '/' + INSOMNIA).freeze
13
+ PATH = 'insomnia/64-bit'.freeze
14
+ COMMAND_SHUTDOWN = 'shutdown /s /t '.freeze
15
+ COMMAND_CANCEL_SHUTDOWN = 'shutdown /a'.freeze
16
+ COMMAND_INSOMNIA = "start #{PATH_TO_INSOMNIA}".freeze
17
17
 
18
18
  def initialize(arguments)
19
-
20
19
  # Get the first arg as the time
21
20
  @time = %w(-h --help -c).include?(arguments.first) ? nil : arguments.shift
22
21
 
@@ -45,7 +44,7 @@ module WindowsShutdownTimer
45
44
  def start_timer
46
45
  unless File.file?(PATH_TO_INSOMNIA)
47
46
  puts 'Downloading Insomnia.exe'
48
- download('dlaa.me', '/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
47
+ download('http://dlaa.me/Samples/Insomnia/Insomnia.zip', 'Insomnia.zip')
49
48
  unzip('Insomnia.zip', 'insomnia')
50
49
  FileUtils.mkdir(PATH_TO_TEMP)
51
50
  FileUtils.mv('insomnia/64-bit/Insomnia.exe', PATH_TO_INSOMNIA)
@@ -53,26 +52,25 @@ module WindowsShutdownTimer
53
52
  FileUtils.rm_rf('insomnia')
54
53
  FileUtils.rm('Insomnia.zip')
55
54
  end
56
- if @time == nil
55
+ if @time.nil?
57
56
  puts 'Please enter the number of minutes until shutdown (0 to cancel):'
58
- @time = gets
57
+ @time = gets.to_i
59
58
  end
60
- if @time.to_i == 0
59
+ if @time.zero?
61
60
  `#{COMMAND_CANCEL_SHUTDOWN}`
62
- elsif @time.to_i == -1
61
+ elsif @time == -1
63
62
  `#{COMMAND_INSOMNIA}`
64
63
  else
65
- time_in_seconds = @time.to_i * 60
64
+ time_in_seconds = @time * 60
66
65
  `#{COMMAND_SHUTDOWN} #{time_in_seconds}`
67
66
  `#{COMMAND_INSOMNIA}`
68
67
  end
69
68
  end
70
69
 
71
- def download(base_url, path, file_name)
72
- Net::HTTP.start(base_url) do |http|
73
- resp = http.get(path)
74
- open(file_name, 'wb') do |file|
75
- file.write(resp.body)
70
+ def download(url, file_name)
71
+ File.open(file_name, 'wb') do |saved_file|
72
+ open(url, 'rb') do |read_file|
73
+ saved_file.write(read_file.read)
76
74
  end
77
75
  end
78
76
  end
@@ -86,6 +84,5 @@ module WindowsShutdownTimer
86
84
  end
87
85
  end
88
86
  end
89
-
90
87
  end
91
88
  end
metadata CHANGED
@@ -1,38 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windows-shutdown-timer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Carlson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-30 00:00:00.000000000 Z
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.0.0
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 1.0.0
19
+ version: 1.2.1
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 1.0.0
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 1.0.0
26
+ version: 1.2.1
33
27
  description: Shut down Windows machine after keeping it awake
34
- email:
35
- - jawnnypoo@gmail.com
28
+ email: jawnnypoo at Google's popular web mail service
36
29
  executables:
37
30
  - windows-shutdown-timer
38
31
  extensions: []
@@ -61,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
54
  version: '0'
62
55
  requirements: []
63
56
  rubyforge_project:
64
- rubygems_version: 2.4.5.2
57
+ rubygems_version: 2.6.14.1
65
58
  signing_key:
66
59
  specification_version: 4
67
60
  summary: Starts a timer, keeping the Windows machine awake and shutting it down when