saving and using windows positions. see #685
This commit is contained in:
parent
af6927c012
commit
a90b20052a
1 changed files with 35 additions and 10 deletions
|
|
@ -238,14 +238,24 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
// openChatGPT(message.prompt,message.action,message.tabId);
|
// openChatGPT(message.prompt,message.action,message.tabId);
|
||||||
// return true;
|
// return true;
|
||||||
case 'chatgpt_close':
|
case 'chatgpt_close':
|
||||||
browser.windows.remove(message.window_id).then(() => {
|
async function _closeChatGptWindow(window_id) {
|
||||||
taLog.log("ChatGPT window closed successfully.");
|
let prefs_close = await browser.storage.sync.get({chatgpt_win_save_position: prefs_default.chatgpt_win_save_position});
|
||||||
return true;
|
if(prefs_close.chatgpt_win_save_position){
|
||||||
}).catch((error) => {
|
try {
|
||||||
taLog.error("Error closing ChatGPT window:", error);
|
let winInfo = await browser.windows.get(window_id);
|
||||||
return false;
|
await browser.storage.sync.set({chatgpt_win_top: winInfo.top, chatgpt_win_left: winInfo.left});
|
||||||
});
|
taLog.log("Window position saved: top=" + winInfo.top + ", left=" + winInfo.left);
|
||||||
break;
|
} catch(e) {
|
||||||
|
taLog.error("Error saving window position: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return browser.windows.remove(window_id).then(() => {
|
||||||
|
taLog.log("ChatGPT window closed successfully.");
|
||||||
|
}).catch((error) => {
|
||||||
|
taLog.error("Error closing ChatGPT window:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return _closeChatGptWindow(message.window_id);
|
||||||
case 'chatgpt_replaceSelectedText':
|
case 'chatgpt_replaceSelectedText':
|
||||||
async function _replaceSelectedText(tabId, text) {
|
async function _replaceSelectedText(tabId, text) {
|
||||||
//console.log('chatgpt_replaceSelectedText: [' + tabId +'] ' + text)
|
//console.log('chatgpt_replaceSelectedText: [' + tabId +'] ' + text)
|
||||||
|
|
@ -477,6 +487,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options.width = prefs.chatgpt_win_width,
|
win_options.width = prefs.chatgpt_win_width,
|
||||||
win_options.height = prefs.chatgpt_win_height
|
win_options.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options, prefs);
|
||||||
|
|
||||||
const listener = (message, sender, sendResponse) => {
|
const listener = (message, sender, sendResponse) => {
|
||||||
async function handleChatGptWeb(createdTab) {
|
async function handleChatGptWeb(createdTab) {
|
||||||
|
|
@ -580,6 +591,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options2.width = prefs.chatgpt_win_width,
|
win_options2.width = prefs.chatgpt_win_width,
|
||||||
win_options2.height = prefs.chatgpt_win_height
|
win_options2.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options2, prefs);
|
||||||
|
|
||||||
await browser.windows.create(win_options2);
|
await browser.windows.create(win_options2);
|
||||||
}
|
}
|
||||||
|
|
@ -631,6 +643,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options5.width = prefs.chatgpt_win_width,
|
win_options5.width = prefs.chatgpt_win_width,
|
||||||
win_options5.height = prefs.chatgpt_win_height
|
win_options5.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options5, prefs);
|
||||||
|
|
||||||
await browser.windows.create(win_options5);
|
await browser.windows.create(win_options5);
|
||||||
}
|
}
|
||||||
|
|
@ -689,6 +702,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options3.width = prefs.chatgpt_win_width,
|
win_options3.width = prefs.chatgpt_win_width,
|
||||||
win_options3.height = prefs.chatgpt_win_height
|
win_options3.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options3, prefs);
|
||||||
|
|
||||||
await browser.windows.create(win_options3);
|
await browser.windows.create(win_options3);
|
||||||
|
|
||||||
|
|
@ -742,6 +756,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options4.width = prefs.chatgpt_win_width,
|
win_options4.width = prefs.chatgpt_win_width,
|
||||||
win_options4.height = prefs.chatgpt_win_height
|
win_options4.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options4, prefs);
|
||||||
|
|
||||||
await browser.windows.create(win_options4);
|
await browser.windows.create(win_options4);
|
||||||
}
|
}
|
||||||
|
|
@ -797,6 +812,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
||||||
win_options5.width = prefs.chatgpt_win_width,
|
win_options5.width = prefs.chatgpt_win_width,
|
||||||
win_options5.height = prefs.chatgpt_win_height
|
win_options5.height = prefs.chatgpt_win_height
|
||||||
}
|
}
|
||||||
|
applyWindowPosition(win_options5, prefs);
|
||||||
|
|
||||||
await browser.windows.create(win_options5);
|
await browser.windows.create(win_options5);
|
||||||
}
|
}
|
||||||
|
|
@ -818,6 +834,15 @@ function checkScreenDimensions(prefs){
|
||||||
return prefs;
|
return prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyWindowPosition(win_options, prefs){
|
||||||
|
if(prefs.chatgpt_win_save_position && (prefs.chatgpt_win_top != 0) && (prefs.chatgpt_win_left != 0)){
|
||||||
|
win_options.top = prefs.chatgpt_win_top;
|
||||||
|
win_options.left = prefs.chatgpt_win_left;
|
||||||
|
taLog.log("Applying saved window position: top=" + prefs.chatgpt_win_top + ", left=" + prefs.chatgpt_win_left);
|
||||||
|
}
|
||||||
|
return win_options;
|
||||||
|
}
|
||||||
|
|
||||||
function doGetSparkFeature(spark_feature_active) {
|
function doGetSparkFeature(spark_feature_active) {
|
||||||
if(spark_feature_active) {
|
if(spark_feature_active) {
|
||||||
return (_sparks_presence == 1);
|
return (_sparks_presence == 1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue