Not able to communicate with host page from outlook dialog box using messageParent - dialog

Not able to communicate from dialog box to the host page.
Am checking in both outlook desktop and outlook web
OS : windows 10
Outlook desktop version: 16.0.13901.20436 64-bit
Browser and version: Google Chrome Version 90.0.4430.93 (Official Build) (64-bit)
in the page opened in the dialog box, called Office. Initialize() and Office. onReady() functions,and on button click need to send information back to parent window.
In the dialog box console am able to see messageParent method but not receiving any call to the host page
parent window code snippet:
var dialog
Office.context.ui.displayDialogAsync(url, {height: 30, width: 20},
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function(arg){
var messageFromDialog = JSON.parse(arg.message);
if (messageFromDialog.messageType === "dialogClosed") {
dialog.close();
}
});
});
dialog box code snippet:
<script>
Office.initialize = function (reason) {
};
</script>
<script>
Office.onReady(function (_ref) {
var host = _ref.host;
console.log("In on ready function")
console.log(Office.context.ui)
});
</script>
function closeWindow1() {
var messageObject = {messageType: "dialogClosed"};
var jsonMessage = JSON.stringify(messageObject);
console.log(Office.context)
console.log(Office.context.ui)
Office.context.ui.messageParent(jsonMessage);
console.log(Office.context.ui.messageParent)
console.log("Called messageParent method")
}
logs in the console:
Cannot read property 'ui' of undefined
In on ready function
OSF.DDA.UI.ChildUIaddHandlerAsync: ƒ ()messageParent: ƒ ()removeHandlerAsync: ƒ ()__proto__: Object
Office.context
OSF.DDA.OutlookContext {contentLanguage: "", displayLanguage: "en-US", touchEnabled: false, commerceAllowed: true, host: "Outlook", …}
Office.context.ui
OSF.DDA.UI.ChildUI {messageParent: ƒ, addHandlerAsync: ƒ, removeHandlerAsync: ƒ}
ƒ (){var b=OSF._OfficeAppFactory.getHostFacade()[OSF.DDA.DispIdHost.Methods.MessageParent];return b(arguments,a)}
Called messageParent method

Please find displayDialogAsync documentation here.
There are also sample codes available, which can be found here.

Related

Not able to send message to hostpage using messageParent from outlook dialog box

Not able to communicate from dialog box to the host page.
in the page opened in the dialog box, called Office. Initialize() and Office. onReady() functions,
and on button click need to send information back to parent window.
tried sending using below.
Office.context.ui.messageParent(JSON.stringify({messageType: "dialogClosed"}));
But not able to receive any event in the host page.
Please help me in solving this.
Thank you.
Edit:
Am checking in both outlook desktop and outlook web
In the dialog box console am able to see messageParent method but not receiving any call to the host page
OS : windows 10
Outlook desktop version: 16.0.13901.20436 64-bit
Browser and version: Google Chrome Version 90.0.4430.93 (Official Build) (64-bit)
parent window code snippet:
var dialog
Office.context.ui.displayDialogAsync(url, {height: 30, width: 20},
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function(arg){
var messageFromDialog = JSON.parse(arg.message);
if (messageFromDialog.messageType === "dialogClosed") {
dialog.close();
}
});
});
dialog box code snippet:
<script>
Office.initialize = function (reason) {
};
</script>
<script>
Office.onReady(function (_ref) {
var host = _ref.host;
console.log("In on ready function")
console.log(Office.context.ui)
});
</script>
function closeWindow1() {
var messageObject = {messageType: "dialogClosed"};
var jsonMessage = JSON.stringify(messageObject);
console.log(Office.context)
console.log(Office.context.ui)
Office.context.ui.messageParent(jsonMessage);
console.log(Office.context.ui.messageParent)
console.log("Called messageParent method")
}
logs in the console:
Cannot read property 'ui' of undefined
In on ready function
OSF.DDA.UI.ChildUIaddHandlerAsync: ƒ ()messageParent: ƒ ()removeHandlerAsync: ƒ ()__proto__: Object
Office.context
OSF.DDA.OutlookContext {contentLanguage: "", displayLanguage: "en-US", touchEnabled: false, commerceAllowed: true, host: "Outlook", …}
Office.context.ui
OSF.DDA.UI.ChildUI {messageParent: ƒ, addHandlerAsync: ƒ, removeHandlerAsync: ƒ}
ƒ (){var b=OSF._OfficeAppFactory.getHostFacade()[OSF.DDA.DispIdHost.Methods.MessageParent];return b(arguments,a)}
Called messageParent method

notifier.on click event is not fired in Windows Action Center

I am using the node-notifier package for notification but I have one problem. notifier.on click event is not fired in Windows Action Center
notifier.notify(
{
appId: "com.electron.demo", // Absolute path (doesn't work on balloons),
title: "Alert Message",
message: "Click to view",
icon: path.join(__dirname, 'msicon.png'),
wait: true,
timeout: false,
id: "demo app"
},
function(err, response) {
// Response is response from notification
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
notifier.on("click", function(notifierObject, options, event) {
// Triggers if `wait: true` and user clicks notification
var request = new sql.Request();
let username = userName;
request.query("update alerts.dbo.groupmessages set isRead = 1\
where pk = '"+ recordset.recordset[i].pk + "'\
and userFK = (select pk from alerts.dbo.users where username = '"+ username + "')\
and groupFK = (select groupFK from alerts.dbo.users where username = '"+ username + "')", function (err, recordset) {
if (err) throw err
console.log(err, recordset, 'User shit');
});
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 400,
frame: false,
webPreferences: {
nodeIntegration: true
}
});
// and load the index.html of the app.
ejse.data('message', recordset.recordset[i].message);
win.loadFile('index.ejs')
}
createWindow();
});
});
});
notifier.on click event is not fired in only Windows Action Center. please let me know the reason and solution as well. Thanks.
Action Center requires separate implementation in native code, which node-notifier doesn't have.
You can try node-powertoast instead and use the onActivated callback:
npm i node-powertoast
const toast = require('powertoast');
toast({
title: "Hello",
message: "world",
callback: {
timeout: 5000, //keep-a-live in ms
onActivated: ()=>{ console.log("activated") },
onDismissed: (reason)=>{ console.log(reason) }
})
.then(()=> console.log("Notified")
.catch(err => console.error(err));
As for the reason:
You can see for other projects it's a significant undertaking and the following project, for example, seems to have Action Center support stuck in limbo for 2 years now: https://github.com/mohabouje/WinToast/issues/35 People trying to implement it themselves appear to have gotten stuck, and have had difficulty getting it implemented correctly.
It's just hard to do.
Notification doesn't get clicks because not all Action Center requirements are fulfilled.
In general Windows notifications have three types of activation: foreground, background and protocol.
In any case you will need to have the following:
Have a shortcut in Start Menu with AppUserModelId property. Please consult your installer on how to do it or use shell.readShortcutLink and shell.writeShortcutLink Electron API. Specifically WiX allows you to specify appUserModelId and toastActivatorClsid in options.
Specify AppUserModelId in the app.
app.setAppUserModelId('AppUserModelId');
Register a custom protocol and some reaction to it. For example like this:
app.setAsDefaultProtocolClient('example');
To use foreground or background you need to:
Have a shortcut in Start Menu with ToastActivatorCLSID property. See above on how to do it.
Use a project like electron-windows-interactive-notifications to register a COM server with the specified earlier ToastActivatorCLSID and a custom protocol of your choice and call:
registerComServer();
registerActivator();
I won't get deep into details on how to react to custom protocol but you will need to parse command line args in search for example: and also expect it in the second-instance hook if the app is already launched.
To use protocol type no extra actions needed.
After that even standard Electron notifications will get clicks from Action Center.
But how to use these protocols and get feature rich notifications?
Electron allows you to specify toastXml directly!
Let's say here's your notification. It will open https://google.com even if clicked from Action Center.
const notification = new Notification({
toastXml: `
<toast launch="https://google.com" activationType="protocol">
<visual>
<binding template="ToastGeneric">
<text>Wonderman meets Superwoman</text>
<text>In the eve of the new millennium, Wonderman challenges Superwoman to a bliniking contest.</text>
<text placement="attribution">Mars Press</text>
</binding>
</visual>
</toast>
`,
});
notification.show();
This notification simply opens Google. You can get more ideas at Notification Visualizer App

Safari does not reopen page after Facebook authentication on iPhone

I'm working on a responsive website that require the user to authenticate with Facebook.
I've set up the Facebook JS SDK, and the login and login-success callback. The setup I have works great on desktop, but on iPhone (seems to work on iPad!) I'm having an issue I am yet to resolve.
When tapping the Login button, the user is brought to a new tab that asks the user to log in. After the user has entered his/her credentials, the tab is closed, but Safari does not reopen my page. Instead, Safari sits in the "tab selection" screen with my page highlighted. The user has to explicitly re-open my page by tapping the tab. When tapping the tab, it doesn't seem to fire the authResponseChange consistently.
Please note that if I make sure that Safari on iPhone has no tabs open except my page, then I am automatically directed back to it (as expected by the Safari app's design) and the site functions correctly.
<div id="fb-root"></div>
<script>
$(document).ready(function() {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/all.js', function() {
FB.init({
appId : 'xxx',
xfbml : true,
status : true,
cookie : true
});
});
});
$("#login_button").bind("vclick", function() {
// Require explicit login
FB.Event.subscribe("auth.authResponseChange", function(response) {
if (response.status === "connected") {
// Perform API calls and display more of the page ...
// $.get("https://graph.facebook.com/me/friends?access_token=")
// FB.api("/me/friends", function(data) {});
}
});
FB.login(function(response) {}, {scope: 'email,friends_birthday,friends_hometown'});
});
</script>

Add Page Tab Dialog is autoredirecting but not showing the dialog to add pages

I am calling the Facebook Add Page Tab Dialog using the Javascript SDK as follows:
var obj = {
method: 'pagetab'
};
FB.ui(obj, function(response) {
console.log(response);
});
The dialog shows up on the page and then auto redirects to the same page which is presently open. It doesn't show the options to select the pages as described in the docs.
Got it working now. The 'display' parameter should be specified explicitly to 'popup'
var obj = {
method: 'pagetab',
display: 'popup'
};
FB.ui(obj, function(response) {
console.log(response);
});

Can you focus a popup window from a Chrome Extension

I have a Chrome Extension that does a window.open() when the extensions icon is clicked. (It can't use the traditional Chrome extension popup due to an unrelated bug in Chrome). I'm wondering if there's a way to focus a popup window if its already open. Chrome disables window.focus() but I thought there might be a way to do it in a Chrome Extension.
Update:
For anyone interested this is the code I ended up using in my background page:
var popupId;
// When the icon is clicked in Chrome
chrome.browserAction.onClicked.addListener(function(tab) {
// If popupId is undefined then there isn't a popup currently open.
if (typeof popupId === "undefined") {
// Open the popup
chrome.windows.create({
"url": "index.html",
"type": "popup",
"focused": true,
"width": 350,
"height": 520
}, function (popup) {
popupId = popup.id;
});
}
// There's currently a popup open
else {
// Bring it to the front so the user can see it
chrome.windows.update(popupId, { "focused": true });
}
});
// When a window is closed
chrome.windows.onRemoved.addListener(function(windowId) {
// If the window getting closed is the popup we created
if (windowId === popupId) {
// Set popupId to undefined so we know the popups not open
popupId = undefined;
}
});
Instead of using window.open() use the Chromes chrome.windows.create... http://code.google.com/chrome/extensions/windows.html#method-create
...then in the call back you can record its window.id and then any time you want to make it focused you can use chrome.windows.update.

Resources