더 이상 귀하의 정보가 없으면 귀하의 문제/문제점에 대해 확신 할 수 없습니다.
그러나 sdk/notifications
documentation과 소스 코드에 대한 간략한 설명은 존재하지 않는 방법 인 notifications.close()
을 사용하려고 시도했음을 나타냅니다. sdk/notifications
에는 그러한 방법이 없습니다.
이 방법을 사용하려는 한 가지 이유는 Web Notification API, more detail을 추가 기능 SDK sdk/notifications
과 겹치게하는 것입니다.
추가 기능 SDK sdk/notifications
은 프로그래밍 방식으로 코드에서 알림을 닫을 수있는 방법이 없습니다. 따라서이 인터페이스를 사용하여 알림 시간 제한을 설정하는 방법은 없습니다. 그러나 일부 운영 체제/윈도우 시스템에서는 이미 이러한 알림에 대한 기본 시간 제한이 있습니다.
직접 패널을 표시하거나 에 설명 된 크롬 인터페이스를 사용해야합니다.
또한 setTimeout()
으로 전화를 걸 수있는 경우는 드뭅니다. 그것은 대부분의 상황에서 정의되지 않을 것입니다. 당신은 일반적으로 sdk/timers
를 사용해야합니다 : 어떤 상황에서
var { setTimeout } = require("sdk/timers");
, 당신은 window
이 적절하게 정의되어 window.setTimeout()
를, (당신은 아마 자신을 설정해야 할) 사용할 수 있습니다.
코드를 수정하면 Prevent XUL notificationBox from closing when button is hit (버튼을 원할 경우 답변이 표시됨) 및 기타 답변 : 내 생각에 당신이 원하는 바를 따라 무엇인가 타임 아웃은) 하단에 :
function showNotificationBox(text) {
//Create some common variables if they do not exist.
if (window === null || typeof window !== "object") {
// Add/remove a "/" to comment/un-comment the code appropriate for your add-on:
//* Add-on SDK:
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
//*/
/* Overlay and bootstrap (from almost any context/scope):
var window=Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
//*/
}
if (typeof gBrowser === "undefined") {
var gBrowser = window.gBrowser;
}
let notifyBox = gBrowser.getNotificationBox();
//appendNotification(label , value , image (URL) , priority , buttons, eventCallback)
let theNotification = notifyBox.appendNotification(text, "Test notification unique ID",
"chrome://browser/content/aboutRobots-icon.png",
notifyBox.PRIORITY_INFO_HIGH, [], null);
//* Add-on SDK:
var { setTimeout } = require("sdk/timers");
setTimeout(theNotification.close(), 10000);
//*/
/* Overlay and bootstrap:
let timerCallback = {
notify:function notify() {theNotification.close(); }
}
let closeNotificationTimer = Components.classes["@mozilla.org/timer;1"]
.createInstance(Components.interfaces.nsITimer);
closeNotificationTimer.initWithCallback(timerCallback,10000,
Components.interfaces.nsITimer.TYPE_ONE_SHOT);
//*/
}
참고 : 나는 당신의 질문의 코드에있는 1 초에서 10 초로 제한 시간이 변경되었습니다. 1 초는 실제로 사용자가보고 이해하고자하는 것을 보여줄 것으로 예상하는 데 비합리적인 시간입니다.
위의 내용은 사용자 알림을 notificationBox에 구현 한 것입니다. 따라서 그것은 파이어 폭스 창에서 나타 : 무엇 sdk/notifications
사용되는 nsIAlertsService을 사용하는 것도 가능하다
. 이렇게하면 일반적으로 화면 오른쪽 하단에 잠재적으로 Firefox 창 외부에 경고 상자가 표시됩니다 (예 : nsIAlertsService의 이미지 참조). 알림은 윈도우 시스템 설정 방법 (OS에 따라 다름)에 따라 다른 위치에 나타날 수 있습니다. 그러나 the documentation에는 알림을 지우거나 시간 제한을 설정하는 방법이 없습니다. 그러나 the interface definition은 closeAlert()
메서드가 있음을 보여줍니다. sdk/notifications
의 소스 코드는이를 Add-on SDK에 공개하지 않습니다. 따라서 크롬 인터페이스를 사용해야합니다. 설명서를 업데이트하여 closeAlert()
으로 표시했습니다.
는
은 (nsIAlertsService에서 가져온 수정 일부 코드)로 :
//* Add-on SDK:
var {Cc, Ci} = require("chrome");
//*/
/* Overlay and bootstrap:
const Cc = Components.classes;
const Ci = Components.interfaces;
//*/
function showNotifcation(title, text) {
var alertsService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
try {
//The second use of title is the alert name.
alertsService.showAlertNotification(icon, title, text, false, "", null, title);
} catch (e) {
// This can fail on Mac OS X
}
//* Add-on SDK:
var { setTimeout } = require("sdk/timers");
setTimeout(alertsService.closeAlert(title), 10000);
//*/
/* Overlay and bootstrap:
let alertTimerCallback = {
notify:function notify() {alertsService.closeAlert(title); }
}
let closeAlertTimer = Cc["@mozilla.org/timer;1"].createInstance(Components.interfaces
.nsITimer);
closeAlertTimer.initWithCallback(alertTimerCallback,10000,Ci.nsITimer.TYPE_ONE_SHOT);
//*/
}
는 난 단지 파이어 폭스 부가 기능은 부트 스트랩 /은 재시작으로 위의 코드를 테스트했습니다. 따라서 Add-on SDK 코드가 약간 벗어날 수 있습니다.
"작동하지 않습니다." 문제에 대한 설명이 충분하지 않습니다. – theblindprophet
작동하지 않는 경우 어떤 오류가 발생합니까? 우리가 문제를 해결할 수 있도록 문제를 설명해주십시오. – Pilatus
질문을 on-topic : 디버깅 도움을 구하는 질문 ("**이 코드가 작동하지 않는 이유는 무엇입니까? **")는 다음을 포함해야합니다 : • 원하는 동작 • 특정 문제 또는 오류 * 및 * • 질문 자체에서 ** 그것을 재현하는 데 필요한 가장 짧은 코드 **. 분명한 문제 성명이없는 질문은 다른 독자에게 유용하지 않습니다. 다음을 참조하십시오 : [최소한의 완전하고 검증 가능한 예제를 만드는 방법] (http://stackoverflow.com/help/mcve), [여기에 대해 나는 무엇에 관해서 물을 수 있습니까?] (http://stackoverflow.com/help/) on-topic), [어떻게 좋은 질문을합니까?] (http://stackoverflow.com/help/how-to-ask). – Makyen