Add support for checking ThunderAI Sparks version and update related UI messages. Fixes #315
This commit is contained in:
parent
ce58612269
commit
d73e4e5eb6
6 changed files with 27 additions and 8 deletions
|
|
@ -1043,6 +1043,10 @@
|
|||
"message": "To use the calendar event feature, please install the ThunderAI Sparks addon.",
|
||||
"description": ""
|
||||
},
|
||||
"prefs_OptionText_get_calendar_event_Sparks_wrong_version": {
|
||||
"message": "To use the calendar event feature, please install an updated version of ThunderAI Sparks addon.",
|
||||
"description": ""
|
||||
},
|
||||
"prefs_OptionText_download_now": {
|
||||
"message": "Download ThunderAI Sparks now!",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const sparks_min = '1.2.0'; // Minimum version of ThunderAI-Sparks required for the add-on to work
|
||||
|
||||
export const getMenuContextCompose = () => 'compose_action_menu';
|
||||
export const getMenuContextDisplay = () => 'message_display_action_menu';
|
||||
|
||||
|
|
@ -367,9 +369,17 @@ export function extractJsonObject(inputString) {
|
|||
|
||||
export async function checkSparksPresence() {
|
||||
try {
|
||||
return (await browser.runtime.sendMessage('thunderai-sparks@micz.it',{action: "checkPresence"}) === 'ok');
|
||||
let sparks_current = await browser.runtime.sendMessage('thunderai-sparks@micz.it',{action: "checkPresence"});
|
||||
if(sparks_current === undefined || sparks_current === null) {
|
||||
return -1;
|
||||
}
|
||||
if (compareThunderbirdVersions(sparks_current, sparks_min) < 0) {
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
} catch (error) {
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -618,7 +618,7 @@ function checkScreenDimensions(prefs){
|
|||
|
||||
async function doGetCalendarEvent(get_calendar_event) {
|
||||
if(get_calendar_event) {
|
||||
return await checkSparksPresence();
|
||||
return (await checkSparksPresence() == 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -376,7 +376,8 @@
|
|||
</tr>
|
||||
<tr class="get_calendar_event_tr" id="no_sparks">
|
||||
<td colspan="2">
|
||||
<span>__MSG_prefs_OptionText_get_calendar_event_Sparks_not_present__</span>
|
||||
<span id="no_sparks_text">__MSG_prefs_OptionText_get_calendar_event_Sparks_not_present__</span>
|
||||
<span id="wrong_sparks_text">__MSG_prefs_OptionText_get_calendar_event_Sparks_wrong_version__</span>
|
||||
<br><a href="https://addons.thunderbird.net/it/thunderbird/addon/thunderai-sparks">__MSG_prefs_OptionText_download_now__</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -299,14 +299,18 @@ function disable_SpamFilter(){
|
|||
async function disable_GetCalendarEvent(){
|
||||
let get_calendar_event = document.getElementById('get_calendar_event');
|
||||
let no_sparks_tr = document.getElementById('no_sparks');
|
||||
let is_spark_present = await checkSparksPresence()
|
||||
let no_sparks_text = document.getElementById('no_sparks_text');
|
||||
let wrong_sparks_text = document.getElementById('wrong_sparks_text');
|
||||
let is_spark_present = await checkSparksPresence();
|
||||
let conntype_select = document.getElementById("connection_type");
|
||||
get_calendar_event.disabled = (conntype_select.value === "chatgpt_web") || !is_spark_present;
|
||||
get_calendar_event.disabled = (conntype_select.value === "chatgpt_web") || !(is_spark_present == 1);
|
||||
let get_calendar_event_tr_elements = document.querySelectorAll('.get_calendar_event_tr');
|
||||
get_calendar_event_tr_elements.forEach(get_calendar_event_tr => {
|
||||
get_calendar_event_tr.style.display = get_calendar_event.disabled ? 'none' : 'table-row';
|
||||
});
|
||||
no_sparks_tr.style.display = (is_spark_present || (conntype_select.value === "chatgpt_web")) ? 'none' : 'table-row';
|
||||
no_sparks_tr.style.display = ((is_spark_present == 1) || (conntype_select.value === "chatgpt_web")) ? 'none' : 'table-row';
|
||||
no_sparks_text.style.display = (is_spark_present == -1) ? 'inline' : 'none';
|
||||
wrong_sparks_text.style.display = (is_spark_present == 0) ? 'inline' : 'none';
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ function checkDoAddTags(){
|
|||
}
|
||||
|
||||
function checkDoCalendarEvent(){
|
||||
return get_calendar_event && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && checkSparksPresence();
|
||||
return get_calendar_event && (connection_type !== "chatgpt_web" && tabType !== 'messageCompose') && (checkSparksPresence() == 1);
|
||||
}
|
||||
|
||||
function ensurePromptAddTagsFirst(arr) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue