1

Google 크롬의 약속 알림 확장 프로그램과 비슷한 것을 개발하려고합니다. 확장 프로그램은 클릭 할 때 사용자가 약속 세부 정보를 입력하는 HTML 페이지를 표시하는 브라우저 작업으로 구성됩니다. 약속 시작시 경고에 약속 이름이 표시되어야합니다.크롬 확장 스크립트는 팝업이 표시 될 때만 실행됩니다.

이 확장 프로그램은 작동하지만 브라우저 동작이 활성화 된 경우에만 작동합니다. 브라우저 조치가 해제되어 있으면 지정된 시간에 경보가 표시되지 않습니다. 이 문제의 원인을 이해하지 못합니다.

manifest.json을

{ 
    "manifest_version": 2, 
    "name": "Appointment", 
    "description": "", 
    "version": "1.0", 
    "background": { 
     "scripts": [ 
      "js/jquery.js", 
      "js/Utils.js", 
      "js/Controller.js" 
     ] 
    }, 
    "permissions": [ 
     "storage", 
     "alarms", 
    ], 
    "browser_action": { 
     "default_icon": "icon-appointment.png", 
     "default_popup": "popup.html" 
    } 
} 

Controller.js는

function loadAppointments(allAppointmentsLoadedCallback){ 


    chrome.storage.sync.get("test_appointments",function(items){ 
     allAppointments = []; 
     if("test_appointments" in items){ 
      sAllAppointments = items["test_appointments"]; 
      allAppointments = JSON.parse(sAllAppointments); 
     } 

     allAppointmentsLoadedCallback(allAppointments); 
    }); 
} 



function getAppointmentScheduledAt(aUnixTime,appointmentFoundCallback){ 
    console.log('Finding Appointment for ',new Date(aUnixTime)); 
    loadAppointments(function(allAppointments){ 
     for(var i=0;i<allAppointments.length;i++){ 
      var anAppointment = allAppointments[i]; 
      var startTime = new Date(anAppointment.startTime).getTime(); 
      console.log('Start time is ',startTime,' and alarm time is',aUnixTime); 
      if(startTime == aUnixTime){ 
       appointmentFoundCallback(anAppointment); 
       return; 
      } 
     } 
     appointmentFoundCallback(null); 
    }); 
} 

chrome.alarms.onAlarm.addListener(function(anAlarm){ 

    getAppointmentScheduledAt(anAlarm.scheduledTime,function(appointment){ 
     if(appointment){ 
      console.log('Found one'); 
      alert(appointment.title); 
     }else{ 
      console.log('No appointment found.'); 
     } 
    }); 
}); 
+0

당신이 전체 코드를 게시 할 수 있습니까? – FuzzyAmi

+0

나는 그렇게하지 않는 편이 좋을 것이다. 하지만 관련 부분은 거기에 있다고 생각합니다 –

답변

3

난 당신이 팝업 페이지에서 chrome.alarms.create를 호출한다고 가정합니다. 이렇게하면 팝업의 defaultView (window)에 알람이 등록됩니다. 팝업이 닫히면 파기됩니다.

당신은 배경 페이지의보기로 알람 등록해야

:

chrome.runtime.getBackgroundPage(function(bg) { 
    bg.chrome.alarms.create(...); 
}); 
+0

정말 고마워요! 그게 :) –

관련 문제