atome 0.5.7.3.2 → 0.5.7.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/atome/extensions/atome.rb +9 -4
- data/lib/atome/genesis/particles/event.rb +1 -1
- data/lib/atome/version.rb +1 -1
- data/vendor/assets/application/examples/repeat.rb +12 -5
- data/vendor/assets/application/examples/scheduler.rb +159 -0
- data/vendor/assets/application/examples/wait.rb +12 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f111d86401c9293ac46fa899d202bf0ab2a1c905d5d17186f0b87ba0560f65d
|
4
|
+
data.tar.gz: ae3208f9349448b93a93864308445ce9108c450366ce8ee2ac1b7026724b40c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3139df2c2320097e707d095e2aa577104669823e61c77fa9b7a4e43553537068926cea7701bd0cd9c8e21bd41087f9d1e04f101883adcd0ea3b5cc84ba1d665e
|
7
|
+
data.tar.gz: c151bca3643df87d2388087cf534eb44e22e3ca8bf4281de8a9311bc7a20717164dd8be7c4a65dced3365e23e110af18648d732374706aaa9aab1fabcfc98bee
|
@@ -216,9 +216,9 @@ class Object
|
|
216
216
|
id
|
217
217
|
end
|
218
218
|
|
219
|
-
def repeater(counter, proc)
|
220
|
-
|
221
|
-
end
|
219
|
+
# def repeater(counter, proc)
|
220
|
+
# instance_exec(counter, &proc) if proc.is_a?(Proc)
|
221
|
+
# end
|
222
222
|
|
223
223
|
def repeat_callback(params, counter)
|
224
224
|
@repeat[params].call(counter)
|
@@ -255,7 +255,7 @@ class Object
|
|
255
255
|
|
256
256
|
return intervalId;
|
257
257
|
JS
|
258
|
-
|
258
|
+
repeat_id+1
|
259
259
|
end
|
260
260
|
|
261
261
|
def stop(params)
|
@@ -266,6 +266,11 @@ class Object
|
|
266
266
|
JS.eval(<<~JS)
|
267
267
|
clearInterval(#{repeater_to_stop});
|
268
268
|
JS
|
269
|
+
elsif params.key?(:wait)
|
270
|
+
waiter_to_stop = params[:wait]
|
271
|
+
JS.eval(<<~JS)
|
272
|
+
clearTimeout(window.timeoutIds['#{waiter_to_stop}'])
|
273
|
+
JS
|
269
274
|
else
|
270
275
|
puts "La clé :repeat n'existe pas dans params"
|
271
276
|
end
|
@@ -261,7 +261,7 @@ new({ particle: :mass, category: :event, type: :int })
|
|
261
261
|
new({ particle: :damping, category: :event, type: :int })
|
262
262
|
new({ particle: :stiffness, category: :event, type: :int })
|
263
263
|
new({ particle: :velocity, category: :event, type: :int })
|
264
|
-
new({ particle: :repeat, category: :event, type: :boolean })
|
264
|
+
# new({ particle: :repeat, category: :event, type: :boolean })
|
265
265
|
new({ particle: :ease, category: :event, type: :boolean })
|
266
266
|
new(particle: :keyboard, category: :event, type: :hash, store: false)
|
267
267
|
new({ sanitizer: :keyboard }) do |params, user_bloc|
|
data/lib/atome/version.rb
CHANGED
@@ -3,21 +3,28 @@
|
|
3
3
|
|
4
4
|
c=circle({width: 66, height: 66})
|
5
5
|
t1=c.text({id: :first, data: 0, left: 28})
|
6
|
-
|
7
|
-
t2=cc.text({id: :second, data: 0, left: 28})
|
6
|
+
|
8
7
|
first_repeater=repeat(1, repeat = 99) do |counter|
|
9
8
|
t1.data(counter)
|
10
9
|
end
|
11
10
|
|
12
|
-
my_repeater=repeat(1, repeat = 9) do |counter|
|
13
|
-
t2.data(counter)
|
14
|
-
end
|
15
11
|
|
16
12
|
c.touch(true) do
|
17
13
|
stop({ repeat: first_repeater })
|
18
14
|
t1.data(:stopped)
|
19
15
|
end
|
20
16
|
|
17
|
+
|
18
|
+
cc=circle({width: 66, height: 66, left: 90 })
|
19
|
+
t2=cc.text({id: :second, data: 0, left: 28})
|
20
|
+
|
21
|
+
# # alert first_repeater
|
22
|
+
my_repeater=repeat(1, repeat = 9) do |counter|
|
23
|
+
t2.data(counter)
|
24
|
+
end
|
25
|
+
#
|
26
|
+
|
27
|
+
#
|
21
28
|
cc.touch(true) do
|
22
29
|
stop({ repeat: my_repeater })
|
23
30
|
t2.data(:stopped)
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
# Helper method to store task configuration in localStorage
|
5
|
+
def store_task(name, config)
|
6
|
+
JS.global[:localStorage].setItem(name, config.to_json)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Helper method to retrieve task configuration from localStorage
|
10
|
+
def retrieve_task(name)
|
11
|
+
config = JS.global[:localStorage].getItem(name)
|
12
|
+
config.nil? ? nil : JSON.parse(config)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Helper method to retrieve all tasks from localStorage
|
16
|
+
def retrieve_all_tasks
|
17
|
+
tasks = []
|
18
|
+
local_storage = JS.global[:localStorage]
|
19
|
+
if Atome::host == "web-opal"
|
20
|
+
local_storage.each do |key|
|
21
|
+
value = local_storage.getItem(key)
|
22
|
+
if value
|
23
|
+
value= JSON.parse(value)
|
24
|
+
tasks << { name: key, config:value }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
length = local_storage[:length].to_i
|
29
|
+
length.times do |i|
|
30
|
+
key = local_storage.call(:key, i)
|
31
|
+
value = local_storage.call(:getItem, key)
|
32
|
+
tasks << { name: key, config: JSON.parse(value.to_s) } if value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
tasks
|
36
|
+
end
|
37
|
+
|
38
|
+
# Helper method to schedule a task
|
39
|
+
def schedule_task(name, years, month, day, hours, minutes, seconds, recurrence: nil, &block)
|
40
|
+
target_time = Time.new(years, month, day, hours, minutes, seconds)
|
41
|
+
now = Time.now
|
42
|
+
|
43
|
+
if target_time < now
|
44
|
+
schedule_recurrence(name, target_time, recurrence, &block)
|
45
|
+
else
|
46
|
+
seconds_until_target = target_time - now
|
47
|
+
wait_task = wait(seconds_until_target) do
|
48
|
+
block.call
|
49
|
+
schedule_recurrence(name, target_time, recurrence, &block) if recurrence
|
50
|
+
end
|
51
|
+
store_task(name, { wait: wait_task, target_time: target_time, recurrence: recurrence })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def schedule_recurrence(name, target_time, recurrence, &block)
|
56
|
+
now = Time.now
|
57
|
+
next_time = target_time
|
58
|
+
|
59
|
+
case recurrence
|
60
|
+
when :yearly
|
61
|
+
next_time += 365 * 24 * 60 * 60 while next_time <= now
|
62
|
+
when :monthly
|
63
|
+
next_time = next_time >> 1 while next_time <= now
|
64
|
+
when :weekly
|
65
|
+
next_time += 7 * 24 * 60 * 60 while next_time <= now
|
66
|
+
when :daily
|
67
|
+
next_time += 24 * 60 * 60 while next_time <= now
|
68
|
+
when :hourly
|
69
|
+
next_time += 60 * 60 while next_time <= now
|
70
|
+
when :minutely
|
71
|
+
next_time += 60 while next_time <= now
|
72
|
+
when :secondly
|
73
|
+
next_time += 1 while next_time <= now
|
74
|
+
when Hash
|
75
|
+
if recurrence[:weekly]
|
76
|
+
wday = recurrence[:weekly]
|
77
|
+
next_time += 7 * 24 * 60 * 60 while next_time <= now
|
78
|
+
next_time += 24 * 60 * 60 until next_time.wday == wday
|
79
|
+
elsif recurrence[:monthly]
|
80
|
+
week_of_month = recurrence[:monthly][:week]
|
81
|
+
wday = recurrence[:monthly][:wday]
|
82
|
+
while next_time <= now
|
83
|
+
next_month = next_time >> 1
|
84
|
+
next_time = Time.new(next_month.year, next_month.month, 1, target_time.hour, target_time.min, target_time.sec)
|
85
|
+
next_time += 24 * 60 * 60 while next_time.wday != wday
|
86
|
+
next_time += (week_of_month - 1) * 7 * 24 * 60 * 60
|
87
|
+
end
|
88
|
+
end
|
89
|
+
else
|
90
|
+
puts "Invalid recurrence option"
|
91
|
+
return
|
92
|
+
end
|
93
|
+
|
94
|
+
seconds_until_next = next_time - Time.now
|
95
|
+
wait_task = wait(seconds_until_next) do
|
96
|
+
block.call
|
97
|
+
schedule_recurrence(name, next_time, recurrence, &block)
|
98
|
+
end
|
99
|
+
store_task(name, { wait: wait_task, target_time: next_time, recurrence: recurrence })
|
100
|
+
end
|
101
|
+
|
102
|
+
# Helper method to stop a scheduled task
|
103
|
+
def stop_task(name)
|
104
|
+
task_config = retrieve_task(name)
|
105
|
+
return unless task_config
|
106
|
+
|
107
|
+
stop({ wait: task_config['wait'] })
|
108
|
+
JS.global[:localStorage].removeItem(name)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Method to relaunch all tasks from localStorage
|
112
|
+
def relaunch_all_tasks
|
113
|
+
tasks = retrieve_all_tasks
|
114
|
+
|
115
|
+
tasks.each do |task|
|
116
|
+
name = task[:name]
|
117
|
+
config = task[:config]
|
118
|
+
target_time_found = config['target_time']
|
119
|
+
target_time = Time.parse(target_time_found)
|
120
|
+
recurrence_found = config['recurrence']
|
121
|
+
next unless recurrence_found
|
122
|
+
recurrence = config['recurrence'].is_a?(Hash) ? config['recurrence'].transform_keys(&:to_sym) : config['recurrence'].to_sym
|
123
|
+
puts "found : #{name}, #{target_time.year}, #{target_time.month}, #{target_time.day}, #{target_time.hour}, #{target_time.min}, #{target_time.sec}, recurrence: #{recurrence}"
|
124
|
+
schedule_task(name, target_time.year, target_time.month, target_time.day, target_time.hour, target_time.min, target_time.sec, recurrence: recurrence) do
|
125
|
+
puts "Relaunched task #{name}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
######## check
|
131
|
+
|
132
|
+
# Relaunch all tasks
|
133
|
+
relaunch_all_tasks
|
134
|
+
|
135
|
+
# Example: Schedule a task to run at a specific date and time
|
136
|
+
schedule_task('specific_time_task', 2024, 11, 12, 15, 12, 30) do
|
137
|
+
puts "Task running at the specific date and time"
|
138
|
+
end
|
139
|
+
|
140
|
+
# Example: Schedule a task to run every minute
|
141
|
+
schedule_task('every_minute_task', 2024, 05, 12, 15, 12, 3, recurrence: :minutely) do
|
142
|
+
puts "Task running every minute"
|
143
|
+
end
|
144
|
+
|
145
|
+
# Example: Schedule a task to run every Tuesday at the same time
|
146
|
+
schedule_task('weekly_tuesday_task', 2024, 11, 12, 15, 12, 30, recurrence: { weekly: 2 }) do
|
147
|
+
puts "Task running every Tuesday at the same time"
|
148
|
+
end
|
149
|
+
|
150
|
+
# Example: Schedule a task to run every second Wednesday of the month at the same time
|
151
|
+
schedule_task('second_wednesday_task', 2024, 11, 12, 15, 12, 30, recurrence: { monthly: { week: 2, wday: 3 } }) do
|
152
|
+
puts "Task running every second Wednesday of the month at the same time"
|
153
|
+
end
|
154
|
+
|
155
|
+
# Stop a task
|
156
|
+
# wait 133 do
|
157
|
+
# puts 'stop'
|
158
|
+
# stop_task('every_minute_task')
|
159
|
+
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.7.3.
|
4
|
+
version: 0.5.7.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean-Eric Godard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -629,6 +629,7 @@ files:
|
|
629
629
|
- vendor/assets/application/examples/resize.rb
|
630
630
|
- vendor/assets/application/examples/rotate.rb
|
631
631
|
- vendor/assets/application/examples/run.rb
|
632
|
+
- vendor/assets/application/examples/scheduler.rb
|
632
633
|
- vendor/assets/application/examples/security.rb
|
633
634
|
- vendor/assets/application/examples/select_text.rb
|
634
635
|
- vendor/assets/application/examples/selected.rb
|