~enso-os/coffee-news/trunk

« back to all changes in this revision

Viewing changes to src/CoffeeView.vala

  • Committer: Nick Wilkins
  • Date: 2017-10-05 16:07:48 UTC
  • Revision ID: nickawilkins@hotmail.com-20171005160748-ndtqudt0tfrv2max
add close button and open links to default browser

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
      //this.zoom_level = 1.6;
55
55
      app = GLib.Application.get_default () as CoffeeApp;
56
56
      coffee_settings = Settings.Settings.get_default ();
 
57
      //ResponsePolicyDecision navoption = new ResponsePolicyDecision() ;
 
58
 
 
59
      //polDecis.ignore();
57
60
      try {
58
61
          news_html = app.load_from_resource ("/com/github/nick92/Coffee/ui/News.html");
59
62
          style_css = load_css();
64
67
      } catch (Error e) {
65
68
          critical (e.message);
66
69
      }
 
70
 
 
71
      decide_policy.connect ((decision, type) => {
 
72
        switch (type) {
 
73
          case WebKit.PolicyDecisionType.NEW_WINDOW_ACTION:
 
74
              if (decision is WebKit.ResponsePolicyDecision) {
 
75
                  launch_browser ((decision as WebKit.ResponsePolicyDecision).request.get_uri ());
 
76
              }
 
77
          break;
 
78
          case WebKit.PolicyDecisionType.RESPONSE:
 
79
              if (decision is WebKit.ResponsePolicyDecision) {
 
80
                  var policy = (WebKit.ResponsePolicyDecision) decision;
 
81
                  launch_browser (policy.request.get_uri ());
 
82
                  return false;
 
83
              }
 
84
          break;
 
85
        }
 
86
        return true;
 
87
      });
 
88
    }
 
89
 
 
90
    private void launch_browser (string url) {
 
91
      if (!url.contains ("/embed/")) {
 
92
          try {
 
93
              AppInfo.launch_default_for_uri (url, null);
 
94
          } catch (Error e) {
 
95
              warning ("No app to handle urls: %s", e.message);
 
96
          }
 
97
          stop_loading ();
 
98
      }
67
99
    }
68
100
 
69
101
    public Post post {