/- browsermanager /+ *server, default-agent :: |% +$ versioned-state $% [%0 state-0] == +$ state-0 $: access-counts=@ seen-urls=(set @t) == +$ card card:agent:gall -- ^- agent:gall =| state-0 =* state - |^ :: Main gall core |_ bol=bowl:gall +* this . def ~(. (default-agent this %|) bol) :: ++ on-init ^- (quip card _this) =/ launcha [%launch-action !>([%add %browsermanager [[%basic 'Browser Manager' '/~browsermanager/img/tile.png' '/~browsermanager'] %.y]])] =/ filea [%file-server-action !>([%serve-dir /'~browsermanager' /app/browsermanager %.n %.n])] :_ this :~ [%pass /srv %agent [our.bol %file-server] %poke filea] [%pass /browsermanager %agent [our.bol %launch] %poke launcha] == :: ++ on-watch |= =path ^- (quip card _this) ?: ?=([%http-response *] path) `this ?. =(/ path) (on-watch:def path) [[%give %fact ~ %json !>(*json)]~ this] :: ++ on-agent on-agent:def :: ++ on-arvo |= [=wire =sign-arvo] ^- (quip card _this) ?. ?=(%bound +<.sign-arvo) (on-arvo:def wire sign-arvo) [~ this] :: :: ++ on-poke |= [=mark =vase] ^- (quip card _this) ?+ mark (on-poke:def mark vase) %noun ~& 'Browser Manager state' ~& state `this %browsermanager-action =/ action !<(action:browsermanager vase) =/ output (handle-action action state) =/ new-actions=(list card) +2:output =/ new-state=state-0 +3:output [new-actions this(state new-state)] == ++ on-save ~& 'on-save' on-save:def ++ on-load ~& 'on-load' on-load:def ++ on-leave on-leave:def ++ on-peek |= pax=path ^- (unit (unit cage)) ~ ++ on-fail on-fail:def -- :: Helper core ++ handle-action |= [action=action:browsermanager state=state-0] ^- [(list card) state-0] ~& 'Browser Manager action' ~& >> action =/ new-state ?- -.action %ping state %submit-url ~& 'got submit-url' state(seen-urls (~(put in seen-urls.state) url.action)) == =/ new-state new-state(access-counts (add 1 access-counts.state)) [~ new-state] --