sunaku / wmiirc

Ruby configuration for WMII window manager
ISC License
82 stars 26 forks source link

Compatibility changes for ['script']['before'] section ? #26

Closed ghost closed 12 years ago

ghost commented 13 years ago

Hi,

I did updated wmiirc scripts to git version but my initialization code in ['script']['before'] key of config.yaml fails to:

My initialization code of 'script/before' and 'script/after' did worked in wmiirc scripts distributed with wmii upto version 3.9.2 .

Are there some sandboxing techniques to prevent spread of global vars and threads ?!

sunaku commented 13 years ago

Global variables in Ruby should transcend all evaluation contexts. I think there is a discrepancy between the order in which your before & after keys are recognized and what you are assuming. Try dumping the fully-loaded configuration before it is applied (as shown in the diff below) and verify the order of your before & after keys.

diff --git a/lib/wmiirc/loader.rb b/lib/wmiirc/loader.rb
index 1b138d4..717eb11 100644
--- a/lib/wmiirc/loader.rb
+++ b/lib/wmiirc/loader.rb
@@ -108,6 +108,7 @@ module Wmiirc
       def load_user_config
         config = Config.new('config')
         Wmiirc.const_set :CONFIG, config
+        LOG.info config.to_yaml
         config.apply
       end
ghost commented 13 years ago

Hi,

I did added dump of the whole config as suggested but there is no problem in order of variables initialization. Assignment in script:before is done before it's use in display:status:clock .

Try please following steps to bring about the issue:

1) assign to a global variable in script:before section of config.yaml

script:

  • before: | $mymsg = 'HELLO'
2) use global variable defined in step 1 in display:status:clock:label section as the last expression (return value)
display:
status:
clock:
refresh: 60
label: |
$mymsg

3) reload wmii

Instead of displaying expected 'HELLO' string error message about nil value of $mymsg is displayed :(

ghost commented 13 years ago

So it was about barlets initialization ? I thought it has something to do with different scopes.

Thank You for the quick fix !

sunaku commented 13 years ago

Yes, the problem was that the status barlets were initialized too early.

sunaku commented 13 years ago

Hmm, my solution created another bug: the keyboard_action sections inside status barlets are not taking effect because it is assumed that the entire config is loaded & ready after the "script:before" sections.

sunaku commented 13 years ago

The proper way to fix this would be to exploit the order of config file loading / processing. To do this, just move your "script:before" section above the "import" section in your config.yaml file.

sunaku commented 13 years ago

@Monad did my suggestion work? Problem solved?

sunaku commented 13 years ago

Well it seems the user @Monad dissappeared from GitHub. It's unlikely that he will return here to confirm whether my suggested fix actually worked. So closing this issue.