I'm trying to launch a save dialog in my windows RT app when someone tries to close a file which has not been saved. However, I keep getting a 0x80070005 - JavaScript runtime error: Access is denied error
This is the code I'm using the launch the message dialog. When "Don't Save" is chosen (and BlankFile() is run) everything runs ok. However when you choose "Save File" it throws the access denied error when it tries to run .pickSaveFileAsync()
function createNewFile()
{
if (editedSinceSave)
{
// Create the message dialog and set its content
var msg = new Windows.UI.Popups.MessageDialog("Save this file?",
"Save Changes");
// Add commands
msg.commands.append(new Windows.UI.Popups.UICommand("Don't Save",
function (command) {
BlankFile();
}));
msg.commands.append(new Windows.UI.Popups.UICommand("Save File",
function (command) {
//saveFile(true, true);
testPop("test");
}));
// Set the command that will be invoked by default
msg.defaultCommandIndex = 2;
// Show the message dialog
msg.showAsync();
}
}
function testPop(text) {
var msg = new Windows.UI.Popups.MessageDialog(text, "");
msg.showAsync();
}
Your core problem is you are tying to show a message dialog ontop of another. I discuss the details, and the solution here:
What is the alternative to `alert` in metro apps?
However, you flow naturally needs this is to happen -- I suggest looking at building a different type of flow rather than stacking dialogs.
The way around this seems to be to set a command id and catch it in the done() function of showAsync(), like so
function createNewFile()
{
if (editedSinceSave)
{
// Add commands and set their CommandIds
msg.commands.append(new Windows.UI.Popups.UICommand("Dont Save", null, 1));
msg.commands.append(new Windows.UI.Popups.UICommand("Save File", null, 2));
// Set the command that will be invoked by default
msg.defaultCommandIndex = 1;
// Show the message dialog
msg.showAsync().done(function (command) {
if (command) {
if (command.id == 1){
BlankFile();
}
else {
saveFile(true, true);
}
}
});
}
}
This doesn't throw any errors. I don't know why doing it the other way throws errors as it doesn't seem to be any different!
Related
I am trying to send information to a dialog box in an Outlook web-add in.
var url = window.location.origin+'/dialog.html'
var dialog
Office.context.ui.displayDialogAsync(url2,
function (asyncResult) {
dialog = asyncResult.value;
dialog.messageChild('message')
});
Which opens a dialog box and tries to send information to the dialog which has this Javascript:
Office.onReady().then(()=> {
Office.context.ui.addHandlerAsync(
Office.EventType.DialogParentMessageReceived,
onMessageFromParent);
});
function onMessageFromParent(arg){
console.log(arg.message)
document.getElementById('ID').style.display = 'none';
}
However, that just gives me the error:
TypeError: Office.context.ui.addHandlerAsync is not a function
When I run console.log(Office.context.ui), I get:
OSF.DDA.UI.ParentUI
[[Prototype]]:Object
closeContainer:function(){ … }
displayDialogAsync:function(){ … }
openBrowserWindow:function(){ … }
__proto__:Object
As you can see, there is not a addHandlerAync function within Office.context.ui but the Microsoft documentation says to use it.
What is going wrong here? Thanks
I look at your add-in. Its taskpane.html is not completed yet and the JavaScript is not included. However, I manually load the dialog page in the debugger and I confirm that your code in dialogbox.html is working. I can see Office.context.ui.addHandlerAsync is available in the Office.onReady handler. Would you like to fix your add-in and double check it's working?
I am trying to write an extension for vscode, and I am trying to handle closing of the terminal, but whenever I click on the trash on the terminal to delete the terminal, the editor freezes. Here is how I am handling how the editor is closed. Am I doing something wrong?
I have multiple terminals, and I am opening one that is not named Server Terminal, it is called Add Package so it doesn't go into the if statement which is what I want in this case. So, what is causing the editor to freeze? I tried adding an else { t.dispose() } but the editor still freezes.
export function activate(context: ExtensionContext) {
window.onDidCloseTerminal(t => {
// Watch for when the server terminal closes.
if (t.name === 'Server Terminal') {
Serve.server = undefined
showMessage(`The server has been stopped on "http://${Serve.host}:${Serve.port}"`)
}
})
}
So, for me, it seems as if to solve this issue I need to first kill the process manually, then I can set Serve.server to undefined. This seems to solve the issue of the editor freezing:
window.onDidCloseTerminal(async t => {
// Watch for when the server terminal closes.
if (t.name === 'Server Terminal') {
const id = await t.processId
id && kill(id)
Serve.server = undefined
}
})
I want to call some JavaScript code using the osascript command. The code should stay running until it receives a chat message from Messages. Ultimately, I intend to execute this from node and receive back the chat message, sender, etc.
I am able to compile a 'stay-running' JavaScript app and run it via
osascript -l JavaScript JSiMessageReceiver.app
where JSiMessageReceiver.app is
function run() {
var Messages = Application('Messages');
Messages.includeStandardAdditions = true;
console.log('started');
}
function quit() { // should prevent app from quitting
return true; // according to Apple's developer release notes
}
function messageReceived(text) {
console.log('message received: ' + text);
}
Of course, the messageReceived handler is never called, because it is not yet associated with Messages. In AppleScript this is done via
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
processMessage("message received", theMessage, theBuddy, theChat)
end message received
end using terms from
How does this translate into JavaScript? I did not find any documentation on this.
Any ideas?
Try this on JavaScript:
function messageReceived(theMessage, eventDescription) {
processMessage("message received", theMessage,
eventDescription.from, eventDescription.for);
}
See event description of messageReceived function in AppleScript Editor - menu Window > Library - Messages Event Handler Suite.
The worked example from Jake Wolpert is there: Attach event listeners in OS X JavaScript for Automation (JXA)
I'm trying to extend some of the handling of messaging between my background process and content scripts. In the normal course of things my background process sends a message via postMessage() and the content script replies via another channel with a response. However I would like to now extend the background process to fall-back to something else if the content script can't find a valid thing on the page. It's when looking at this I discovered a problem when sending a message to blank or system pages. As the tabs don't have content scripts loaded there is nothing to receive the posted message. This generates warnings in the console logs but otherwise no ill effects. However:
// Called when the user clicks on the browser action.
//
// When clicked we send a message to the current active tab's
// content script. It will then use heuristics to decide which text
// area to spawn an edit request for.
chrome.browserAction.onClicked.addListener(function(tab) {
var find_msg = {
msg: "find_edit"
};
try {
// sometimes there is no tab to talk to
var tab_port = chrome.tabs.connect(tab.id);
tab_port.postMessage(find_msg);
updateUserFeedback("sent request to content script", "green");
} catch (err) {
if (settings.get("enable_foreground")) {
handleForegroundMessage(msg);
} else {
updateUserFeedback("no text area listener on this page", "red");
}
}
});
Doesn't work. I would expect the connect or the postMessage to throw an error I can trap, however the console log is filled with error messages including:
Port: Could not establish connection. Receiving end does not exist.
But I do not end up in the catch statement.
In the end I couldn't do it with connect, I had to use the one shot sendMessage() which has a call-back function when the response comes in. That can then be interrogated for success and the state of lastError. The code now looks like this:
// Called when the user clicks on the browser action.
//
// When clicked we send a message to the current active tab's
// content script. It will then use heuristics to decide which text
// area to spawn an edit request for.
chrome.browserAction.onClicked.addListener(function(tab) {
var find_msg = {
msg: "find_edit"
};
// sometimes there is no content script to talk to which we need to detect
console.log("sending find_edit message");
chrome.tabs.sendMessage(tab.id, find_msg, function(response) {
console.log("sendMessage: "+response);
if (chrome.runtime.lastError && settings.get("enable_foreground")) {
handleForegroundMessage();
} else {
updateUserFeedback("sent request to content script", "green");
}
});
});
This is a noob question.
What if I want to add logging to the java script application, which is running in a browser (IE, FF, etc.) ? As I understand I can not save log files in the client host. So, I have only two options: display my logging information in a new browser window (like "blackbird") or send the logging to the server.
Is it correct? What kind of logging do they usually use?
You can't "store" log files on client host. You can open a window and visualize it, but you (assuming you are running the Web Application) will never see it.
If you absolutely must get client side logs, you need to send them back to the server using AJAX. Here's a blog post I really liked about it.
Another possibility is the jsnlog library http://js.jsnlog.com/
It will let you send client side logs to the server.
Take a look at https://log4sure.com (disclosure: I created it) - but it is really useful, check it out and decide for yourself. It allows you to log errors/event and also lets you create your custom log table. It stores everything on its own server so you don't have to. It also allows you to monitor your logs real-time. And the best part, its free.
You can also use bower to install it, use bower install log4sure
The set up code is really easy too:
// setup
var _logServer;
(function() {
var ls = document.createElement('script');
ls.type = 'text/javascript';
ls.async = true;
ls.src = 'https://log4sure.com/ScriptsExt/log4sure.min.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ls, s);
ls.onload = function() {
// use your token here.
_logServer = new LogServer("use-your-token-here");
};
})();
// example for logging text
_logServer.logText("your log message goes here.")
//example for logging error
divide = function(numerator, divisor) {
try {
if (parseFloat(value) && parseFloat(divisor)) {
throw new TypeError("Invalid input", "myfile.js", 12, {
value: value,
divisor: divisor
});
} else {
if (divisor == 0) {
throw new RangeError("Divide by 0", "myfile.js", 15, {
value: value,
divisor: divisor
});
}
}
} catch (e) {
_logServer.logError(e.name, e.message, e.stack);
}
}
// another use of logError in window.onerror
// must be careful with window.onerror as you might be overwriting some one else's window.onerror functionality
// also someone else can overwrite window.onerror.
window.onerror = function(msg, url, line, column, err) {
// may want to check if url belongs to your javascript file
var data = {
url: url,
line: line,
column: column,
}
_logServer.logError(err.name, err.message, err.stack, data);
};
// example for custom logs
var foo = "some variable value";
var bar = "another variable value";
var flag = "false";
var temp = "yet another variable value";
_logServer.log(foo, bar, flag, temp);