Module: Gnome::Wallpaper::Changer::Updater::ClassMethods

Included in:
Gnome::Wallpaper::Changer::Updater
Defined in:
lib/gnome-wallpaper-changer/updater.rb

Constant Summary collapse

PICTURES =
[".jpg", ".png"]

Instance Method Summary collapse

Instance Method Details

#do_update_wallpaper(path) ⇒ Object



43
44
45
46
# File 'lib/gnome-wallpaper-changer/updater.rb', line 43

def do_update_wallpaper path
  puts "update: #{path || '-'}"
  `gsettings set org.gnome.desktop.background picture-uri "#{path ? 'file://' + path : ''}"`
end

#expand_folder_config(folder) ⇒ Object



68
69
70
# File 'lib/gnome-wallpaper-changer/updater.rb', line 68

def expand_folder_config folder
  { files: get_files_in_folder(folder[:path]) }.merge folder
end

#filesObject



23
24
25
# File 'lib/gnome-wallpaper-changer/updater.rb', line 23

def files
  @files || []
end

#force_update(path) ⇒ Object



38
39
40
41
# File 'lib/gnome-wallpaper-changer/updater.rb', line 38

def force_update path
  do_update_wallpaper path
  reschedule!
end

#get_active_filesObject



48
49
50
# File 'lib/gnome-wallpaper-changer/updater.rb', line 48

def get_active_files
  Configuration.folders.map { |folder| get_files_in_folder( folder[:path] ) - folder[:excluded] }.flatten + Configuration.files
end

#get_expanded_configuration(folder) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gnome-wallpaper-changer/updater.rb', line 52

def get_expanded_configuration folder
  if folder
    folder = Configuration.folders.find { |f| f[:path] == folder }
    if folder
      expand_folder_config folder
    else
      nil
    end
  else
    {
      folders: Configuration.folders.map { |folder| self.expand_folder_config folder },
      files: Configuration.files
    }
  end
end

#get_files_in_folder(path) ⇒ Object



72
73
74
# File 'lib/gnome-wallpaper-changer/updater.rb', line 72

def get_files_in_folder path
  Pathname.new(path).children.select(&:file?).select { |file| PICTURES.include? file.extname }.map(&:to_s)
end

#known_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/gnome-wallpaper-changer/updater.rb', line 76

def known_file? path
  dir = File.dirname path
  Configuration.files.include?( path ) || Configuration.folders.find { |folder| folder[:path] == dir }
end

#reschedule!Object



17
18
19
20
21
# File 'lib/gnome-wallpaper-changer/updater.rb', line 17

def reschedule!
  EM.cancel_timer @last_timer if @last_timer
  @last_timer = nil
  schedule! if Configuration.active?
end

#schedule!Object



10
11
12
13
14
15
# File 'lib/gnome-wallpaper-changer/updater.rb', line 10

def schedule!
  @last_timer = EM.add_timer Configuration.interval do
    @last_timer = nil
    self.update if Configuration.active?
  end
end

#updateObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/gnome-wallpaper-changer/updater.rb', line 27

def update
  @files = get_active_files
  #@files.each { |file| Resizer.resize file }
  do_update_wallpaper( if @files.empty?
    nil
  else
    @files[ rand(files.length) ]
  end )
  schedule!
end