<commit_before>import postRobot from "post-robot";
import { enterLoginDetails, submitLoginForm } from "./login.js";
import { hideInputDialog } from "./inputDialog.js";
import { hideSaveDialog } from "./saveDialog.js";
import { openGeneratorForCurrentInput, setPasswordForCurrentInput } from "./generator.js";

export function getLastLoginStatus() {
    return new Promise(resolve => {
        chrome.runtime.sendMessage({ type: "get-used-credentials" }, resp => {
            resolve(
                resp && !!resp.credentials
                    ? {
                          credentials: true,
                          title: resp.credentials.title
                      }
                    : {
                          credentials: false
                      }
            );
        });
    });
}

function handleMessage(request, sender, sendResponse) {
    switch (request.type) {
        case "enter-details": {
            const { signIn, entry } = request;
            enterLoginDetails(entry.properties.username, entry.properties.password, signIn);
            return false;
        }
        case "open-generator":
            openGeneratorForCurrentInput();
            break;
        case "set-generated-password":
            setPasswordForCurrentInput(request.password);
            break;
        default:
            throw new Error(`Unknown message received: ${request.type}`);
    }
}

export function startMessageListeners() {
    chrome.runtime.onMessage.addListener(handleMessage);
    startPostMessageListener();
}

function startPostMessageListener() {
    postRobot.on("bcup-close-dialog", () => {
        hideSearchDialog();
        hideSaveDialog();
    });
    postRobot.on("bcup-get-url", () => window.location.href);
    postRobot.on("bcup-open-url", event => {
        const { url } = event.data;
        chrome.runtime.sendMessage({ type: "open-tab", url });
    });
}

export function transferLoginCredentials(details) {
    chrome.runtime.sendMessage({ type: "save-used-credentials", credentials: details });
}
<commit_msg>Fix closing of save-new dialog - fixes #137<commit_after>import postRobot from "post-robot";
import { enterLoginDetails, submitLoginForm } from "./login.js";
import { hideInputDialog } from "./inputDialog.js";
import { hideSaveDialog } from "./saveDialog.js";
import { openGeneratorForCurrentInput, setPasswordForCurrentInput } from "./generator.js";

export function getLastLoginStatus() {
    return new Promise(resolve => {
        chrome.runtime.sendMessage({ type: "get-used-credentials" }, resp => {
            resolve(
                resp && !!resp.credentials
                    ? {
                          credentials: true,
                          title: resp.credentials.title
                      }
                    : {
                          credentials: false
                      }
            );
        });
    });
}

function handleMessage(request, sender, sendResponse) {
    switch (request.type) {
        case "enter-details": {
            const { signIn, entry } = request;
            enterLoginDetails(entry.properties.username, entry.properties.password, signIn);
            return false;
        }
        case "open-generator":
            openGeneratorForCurrentInput();
            break;
        case "set-generated-password":
            setPasswordForCurrentInput(request.password);
            break;
        default:
            throw new Error(`Unknown message received: ${request.type}`);
    }
}

export function startMessageListeners() {
    chrome.runtime.onMessage.addListener(handleMessage);
    startPostMessageListener();
}

function startPostMessageListener() {
    postRobot.on("bcup-close-dialog", () => {
        hideInputDialog();
        hideSaveDialog();
    });
    postRobot.on("bcup-get-url", () => window.location.href);
    postRobot.on("bcup-open-url", event => {
        const { url } = event.data;
        chrome.runtime.sendMessage({ type: "open-tab", url });
    });
}

export function transferLoginCredentials(details) {
    chrome.runtime.sendMessage({ type: "save-used-credentials", credentials: details });
}

{'fraction_non_alphanumeric': 0.12159884420900553, 'fraction_numerical': 0.0007223693715386468, 'mean_word_length': 2.1807044410413474, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7425720', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1060, 'n_words': 210}