Force footer-nav with cookie

Discourse renders that footer based on some conditions. The footer is added here.

discourse/application.hbs at a0bbc346cb5d5b89d1a3efdfa89869349a8b067f · discourse/discourse · GitHub

showFooterNav is defined here.

discourse/application.js at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub

If either of those is true, the nav will be displayed.

isiOSPWA() and isAppWebview() are defined here

discourse/utilities.js at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub

For example, isAppWebview() looks like this.

discourse/utilities.js at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub

You can create an additional condition in your theme - in your Discourse site - to check for the cookie, like so

const isWKWebView = () => {
  // check for the cookie and return true if it exists
  // or use any other method to detect if the user is using your application
}

For other Classes, you would normally then be able to modify the showFooterNav() like so

api.modifyClass("controller:application", {
  pluginId: "show-footer-nav",
  @discourseComputed
  showFooterNav() {
    // ...
  }
});

However, this is the application controller, which means that it will be cached before your code gets a chance to execute. In other words, you won’t be able to modify the Class.

That said, you can still change the showFooterNav value with something like this.

<script type="text/discourse-plugin" version="0.8">
  const isWKWebView = () => {
    // check and return your condition
  };

  if (isWKWebView()) {
    const applicationController = api.container.lookup("controller:application");
    applicationController.set("showFooterNav", true);
  }
</script>

in the header tab of your theme or in an initializer if you’re using a remote theme.

5 Likes