File: update_ui.js

package info (click to toggle)
allow-html-temp 10.0.8-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 368 kB
  • sloc: javascript: 1,454; makefile: 25; sh: 7
file content (126 lines) | stat: -rw-r--r-- 5,384 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Enable if action buttons
// - if message is not Junk
// - if message is not News
// - if message has an HTML MIME part
async function updateActionButtonForNewMessages(tab, messages) {
  // messages is technically an array of objects, which in theory should only 
  // have one object at this point. Nevertheless we need to recursively handle this array.
  for (let i = 0; i < messages.length; i++){ 
    consoleDebug("AHT: updateActionButtonForNewMessages: messages Array i = " + i);

    let message = messages[i];

    consoleDebug("AHT: updateActionButtonForNewMessage: tab.id = " + tab.id + " message.id = " + message.id);

    // check for folder type and don't enable UI for junk folders
    consoleDebug("AHT: updateActionButtonForNewMessage: folder type = " + message.folder.type);
    if (message.folder.type == "junk") {
      messenger.messageDisplayAction.disable(tab.id);
      return;
    }
    // check for junk status and don't enable UI for junk messages
    consoleDebug("AHT: updateActionButtonForNewMessage: junk status = " + message.junk);
    if (message.junk) {
      messenger.messageDisplayAction.disable(tab.id);
      return;
    }
  
    // check for account type:
    // don't enable UI for News accounts,
    // but enable UI for RSS accounts
    let account = await messenger.accounts.get(message.folder.accountId);
    consoleDebug("AHT: updateActionButtonForNewMessage: account type = " + account.type);
    if (account.type == "news") {
      messenger.messageDisplayAction.disable(tab.id);
      return;
    }
    
    if (account.type == "rss") {
      consoleDebug("AHT: updateActionButtonForNewMessage: enable toolbar button");
      messenger.messageDisplayAction.enable(tab.id); // Unconditionally for all rss messages?
      return;
    }
  
    // for all other messages check, if they have a HTML MIME part
    consoleDebug("AHT: updateActionButtonForNewMessage: checkMailForHtmlpart");
    let hasHtmlMimePart = await messenger.allowHtmlTemp.checkMailForHtmlpart(message.id, options.debug);
    consoleDebug("AHT: updateActionButtonForNewMessage: checkMailForHtmlpart returns: " + hasHtmlMimePart);
  
    if (hasHtmlMimePart) {
      messenger.messageDisplayAction.enable(tab.id);
    } else {
      messenger.messageDisplayAction.disable(tab.id);
    }
  }
};

async function setButtonIconAndLabel() {
  buttonIcon = {};
  buttonLabel = {};

  await reloadOption("buttonHtmlMode");
  let appRemoteContent = !(await messenger.messageContentPolicy.getCurrent()).disableRemoteContent;
  await reloadOption("tempRemoteContent");
  consoleDebug("AHT: setButtonIcon: options.buttonHtmlMode: " + options.buttonHtmlMode);
  consoleDebug("AHT: setButtonIcon: pref appRemoteContent: " + appRemoteContent);
  consoleDebug("AHT: setButtonIcon: options.tempRemoteContent: " + options.tempRemoteContent);

  switch (options.buttonHtmlMode) {
    case "buttonMode_html":
      if ((appRemoteContent == true) || (options.tempRemoteContent == true)) {
        consoleDebug("AHT: setButtonIcon: html+");
        buttonIcon.path = "../icons/aht_button_supernova_color_plus.svg";
        buttonLabel.label = messenger.i18n.getMessage("button_label_html");
        break;
      } else {
        consoleDebug("AHT: setButtonIcon: html");
        buttonIcon.path = "../icons/aht_button_supernova_color.svg";
        buttonLabel.label = messenger.i18n.getMessage("button_label_html");
        break;
      }
    case "buttonMode_sanitized":
      consoleDebug("AHT: setButtonIcon: sanitized");
      buttonIcon.path = "../icons/aht_button_supernova_sanitized_lightdarkcss.svg";
      buttonLabel.label = messenger.i18n.getMessage("button_label_sanitized");
      break;
    case "buttonMode_plaintext":
      consoleDebug("AHT: setButtonIcon: plaintext");
      buttonIcon.path = "../icons/aht_button_supernova_plaintext_lightdarkcss.svg";
      buttonLabel.label = messenger.i18n.getMessage("button_label_plaintext");
      break;
    default:
      consoleDebug("AHT: setButtonIcon: default");
      buttonIcon.path = "../icons/aht_button_supernova_color.svg";
      buttonLabel.label = messenger.i18n.getMessage("button_label_html");
      break;
  }

  messenger.messageDisplayAction.setIcon(buttonIcon);
  messenger.messageDisplayAction.setLabel(buttonLabel);
}

async function setCommandKey() {
  await reloadOption("commandKey");
  consoleDebug("AHT: setCommandKey: options.commandKey: " + options.commandKey);

  let detail = {};
  detail.name = "_execute_message_display_action";
  detail.shortcut = options.commandKey;
  if (detail.shortcut === "") {
    consoleDebug("AHT: setCommandKey: Your chosen commandkey is empty. Therefore the default \"" + DefaultOptions.commandKey + "\" will be used.");
    detail.shortcut = DefaultOptions.commandKey;
  }
  try {
    await messenger.commands.update(detail);
  } catch (e) {
    consoleDebug("AHT: setCommandKey: Your chosen commandkey isn't valid. Therefore the default \"" + DefaultOptions.commandKey + "\" will be used.");
    detail.shortcut = DefaultOptions.commandKey;
    await messenger.commands.update(detail);
    // Reset option to default
    return messenger.storage.local.remove("commandKey").then(() => {
    });
  }
}

setButtonIconAndLabel();
setCommandKey();