Skip to content

Commit

Permalink
Detect whether Service Worker of Nomad Web is running, based on that …
Browse files Browse the repository at this point in the history
…display to the user message

(reference #53)
  • Loading branch information
piotrzarzycki21 committed Apr 24, 2024
1 parent ff996d4 commit 7fd4675
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ package constants
public static const NOTE_OPEN_ADD_EDIT_BOOKMARK:String = NAME + SEPARATOR + "NoteOpenAddEditBookmark";
public static const NOTE_OPEN_SELECTED_BOOKMARK_GROUP:String = NAME + SEPARATOR + "NoteOpenSelectedBookmarkGroup";

public static const NOTE_FAILED_OPEN_NOMAD_LINK:String = NAME + SEPARATOR + "NoteFailedOpenNomadLink";

//----------------------------------
// Commands
//----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package controller
import model.proxy.login.ProxyLogin;
import org.apache.royale.net.navigateToURL;
import org.apache.royale.net.URLRequest;
import constants.ApplicationConstants;

public class CommandLaunchNomadLink extends SimpleCommand
{
Expand All @@ -17,23 +18,43 @@ package controller
var loginProxy:ProxyLogin = facade.retrieveProxy(ProxyLogin.NAME) as ProxyLogin;
var nomadHelperUrl:String = loginProxy.config.config.nomad_helper_url;
var link:String = note.getBody().link;
window["onmessage"] = null;

if (nomadHelperUrl)
{
var mainMediator:MediatorMainContentView = facade.retrieveMediator(MediatorMainContentView.NAME) as MediatorMainContentView;
var nomadHelper:Iframe = mainMediator.view.viewNomadHelper as Iframe;


window["onmessage"] = onWindowMessage;

var encodedLink:String = encodeURIComponent(link);
nomadHelper.src = nomadHelperUrl + "?link=" + encodedLink;

var appName:String = note.getBody().name;
Snackbar.show("Application " + appName + " has been opened in HCL Nomad web", 4000, null);
Snackbar.show("Opening application " + appName + " in HCL Nomad Web in progress...", 4000, null);
}
else
{
navigateToURL(new URLRequest(link));
}
}

private function onWindowMessage(event:Event):void
{
var loginProxy:ProxyLogin = facade.retrieveProxy(ProxyLogin.NAME) as ProxyLogin;
var nomadHelperUrl:String = loginProxy.config.config.nomad_helper_url;

window["onmessage"] = null;
var winMessage:String = event["data"];
var errorPrefix:String = "[Error]";
var hasErrorIndex:int = winMessage.indexOf(errorPrefix);
var hasOriginIndex:int = nomadHelperUrl.indexOf(event["origin"]);

if (hasErrorIndex > -1 && hasOriginIndex > -1)
{
winMessage = winMessage.substr(errorPrefix.length, winMessage.length);
sendNotification(ApplicationConstants.NOTE_FAILED_OPEN_NOMAD_LINK, winMessage);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ package mediator
import org.puremvc.as3.multicore.interfaces.IMediator;
import org.puremvc.as3.multicore.interfaces.INotification;
import org.puremvc.as3.multicore.patterns.mediator.Mediator;
import model.vo.PopupVO;
import constants.PopupType;

public class MediatorMainContentView extends Mediator implements IMediator
{
Expand Down Expand Up @@ -99,6 +101,7 @@ package mediator
interests.push(ApplicationConstants.NOTE_OPEN_ADD_EDIT_GENESIS_DIR);
interests.push(ApplicationConstants.NOTE_OPEN_ADD_EDIT_BOOKMARK);
interests.push(ApplicationConstants.NOTE_OPEN_SELECTED_BOOKMARK_GROUP);
interests.push(ApplicationConstants.NOTE_FAILED_OPEN_NOMAD_LINK);

return interests;
}
Expand Down Expand Up @@ -161,6 +164,9 @@ package mediator
case ApplicationConstants.NOTE_OPEN_SELECTED_BOOKMARK_GROUP:
selectBookmarkGroup(String(note.getBody()));
break;
case ApplicationConstants.NOTE_FAILED_OPEN_NOMAD_LINK:
sendNotification(ApplicationConstants.COMMAND_SHOW_POPUP, new PopupVO(PopupType.ERROR, this.getMediatorName(), "Nomad Web is not running. " + String(note.getBody())));
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Super.Human.Portal_Royale/src/resources/nomadhelper.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
});
} else {
console.error('No service worker registered');

window.top.postMessage('[Error] No service worker registered', '*');
}
}

Expand Down

0 comments on commit 7fd4675

Please sign in to comment.