|
@@ -287,14 +287,22 @@ export function checkPined() {
|
|
|
}
|
|
|
|
|
|
function sendActivetabMessage(message = {}) {
|
|
|
- chrome.tabs.query({
|
|
|
- active: true,
|
|
|
- currentWindow: true
|
|
|
- }, (tabs) => {
|
|
|
- chrome.tabs.sendMessage(tabs[0].id, message, res => {
|
|
|
- console.log(res)
|
|
|
+ try{
|
|
|
+ chrome.tabs.query({
|
|
|
+ active: true,
|
|
|
+ currentWindow: true
|
|
|
+ }, (tabs) => {
|
|
|
+ chrome.tabs.sendMessage(tabs[0].id, message, res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'sendActivetabMessage',
|
|
|
+ errMsg: error.message
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -441,19 +449,27 @@ export async function setMessageCount() {
|
|
|
}
|
|
|
|
|
|
function createAlarm() {
|
|
|
- let alarmInfo = {
|
|
|
- //1分鐘之後開始(該值不能小於1)
|
|
|
- delayInMinutes: 1,
|
|
|
- //與上方等同的寫法是
|
|
|
- // when : Date.now() + n,
|
|
|
- //開始後每一分鐘執行一次(該值不能小于1)
|
|
|
- periodInMinutes: 1
|
|
|
- };
|
|
|
-
|
|
|
- //每次加載就清空定時器
|
|
|
- chrome.alarms.clear('denetChromeAlarm');
|
|
|
- //創造定時器
|
|
|
- chrome.alarms.create('denetChromeAlarm', alarmInfo);
|
|
|
+ try {
|
|
|
+ let alarmInfo = {
|
|
|
+ //1分鐘之後開始(該值不能小於1)
|
|
|
+ delayInMinutes: 1,
|
|
|
+ //與上方等同的寫法是
|
|
|
+ // when : Date.now() + n,
|
|
|
+ //開始後每一分鐘執行一次(該值不能小于1)
|
|
|
+ periodInMinutes: 1
|
|
|
+ };
|
|
|
+
|
|
|
+ //每次加載就清空定時器
|
|
|
+ chrome.alarms.clear('denetChromeAlarm');
|
|
|
+ //創造定時器
|
|
|
+ chrome.alarms.create('denetChromeAlarm', alarmInfo);
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'createAlarm',
|
|
|
+ errMsg: error.message
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export function getMessageInfo() {
|
|
@@ -496,36 +512,32 @@ export const injectExtensionPopup = (tab) => {
|
|
|
}
|
|
|
|
|
|
export const setPopupConfig = (activeInfo) => {
|
|
|
- chrome.tabs.query({
|
|
|
- active: true,
|
|
|
- currentWindow: true
|
|
|
- }, (tabs) => {
|
|
|
- if (tabs.length) {
|
|
|
- let { pendingUrl = '', url = '' } = tabs[0];
|
|
|
- if (pendingUrl.startsWith('https://twitter.com') || url.startsWith('https://twitter.com')) {
|
|
|
- sendActivetabMessage({
|
|
|
- actionType: 'BG_SET_POPUP_CONFIG'
|
|
|
- });
|
|
|
- } else {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup: 'popup.html',
|
|
|
- }, function () {
|
|
|
- });
|
|
|
+ try{
|
|
|
+ chrome.tabs.query({
|
|
|
+ active: true,
|
|
|
+ currentWindow: true
|
|
|
+ }, (tabs) => {
|
|
|
+ if (tabs.length) {
|
|
|
+ let { pendingUrl = '', url = '' } = tabs[0];
|
|
|
+ if (pendingUrl.startsWith('https://twitter.com') || url.startsWith('https://twitter.com')) {
|
|
|
+ sendActivetabMessage({
|
|
|
+ actionType: 'BG_SET_POPUP_CONFIG'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup: 'popup.html',
|
|
|
+ }, function () {
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // if(pendingUrl.startsWith('chrome://') || url.startsWith('chrome://') || pendingUrl.startsWith('https://chrome.google.com') || url.startsWith('https://chrome.google.com')) {
|
|
|
- // chrome.action.setPopup({
|
|
|
- // popup: 'popup.html',
|
|
|
- // },function() {
|
|
|
- // });
|
|
|
- // } else {
|
|
|
- // chrome.action.setPopup({
|
|
|
- // popup: '',
|
|
|
- // },function() {
|
|
|
- // });
|
|
|
- // }
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'setPopupConfig',
|
|
|
+ errMsg: error.message
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export const getSysMessage = () => {
|
|
@@ -553,22 +565,30 @@ export const windwoLoadSetPopupPage = (data, sender) => {
|
|
|
}
|
|
|
|
|
|
export const setActionPopup = (data) => {
|
|
|
- let { popup } = data.data || {};
|
|
|
- if (popup) {
|
|
|
- chrome.action.getPopup(
|
|
|
- {},
|
|
|
- function (result) {
|
|
|
- if (!result) {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup,
|
|
|
- }, function () {
|
|
|
- });
|
|
|
- }
|
|
|
+ try {
|
|
|
+ let { popup } = data.data || {};
|
|
|
+ if (popup) {
|
|
|
+ chrome.action.getPopup(
|
|
|
+ {},
|
|
|
+ function (result) {
|
|
|
+ if (!result) {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup,
|
|
|
+ }, function () {
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ chrome.action.setPopup({
|
|
|
+ popup: '',
|
|
|
+ }, function () {
|
|
|
});
|
|
|
- } else {
|
|
|
- chrome.action.setPopup({
|
|
|
- popup: '',
|
|
|
- }, function () {
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ Report.reportLog({
|
|
|
+ objectType: Report.objectType.background_function_catch,
|
|
|
+ funcName: 'setActionPopup',
|
|
|
+ errMsg: error.message
|
|
|
});
|
|
|
}
|
|
|
}
|