<commit_before>from . import application
from . import browser
from . import settings
from . import event
from PyQt4 import QtCore, QtGui

TOAST_WIDTH = 330
# Used for toast and chat window positioning
_margin = 10

def init():
    base_url = "https://www.facebook.com"
    base_url_override = settings.get_setting("BaseUrl")
    if (base_url_override):
        print("BaseUrl:", base_url_override)
        base_url = base_url_override

    global main_window
    closable_main = not settings.get_setting("SystemTray", default=True)
    main_window = browser.BrowserWindow(base_url + "/desktop/client/", closable_main)
    main_window.set_size(212, 640)
    main_window.set_title("Messenger")
    def main_window_moved_or_resized():
        settings.set_setting(
            "MainWindowRectangle", main_window.get_rectangle())
    event.subscribe(main_window.MOVE_EVENT, main_window_moved_or_resized)
    event.subscribe(main_window.RESIZE_EVENT, main_window_moved_or_resized)
    event.subscribe(main_window.HIDE_EVENT, show_or_hide_main_window)
    event.subscribe(main_window.CLOSE_EVENT, application.quit)
    init_main_window()

    global chat_window
    chat_window = browser.BrowserWindow(base_url + "/desktop/client/chat.php", False)
    chat_window.set_size(420, 340)
    def chat_window_moved_or_resized():
        settings.set_setting(
            "ChatWindowRectangle", chat_window.get_rectangle())
    event.subscribe(chat_window.MOVE_EVENT, chat_window_moved_or_resized)
    event.subscribe(chat_window.RESIZE_EVENT, chat_window_moved_or_resized)
    event.subscribe(chat_window.HIDE_EVENT, show_or_hide_chat_window)

    global toast_window
    toast_window = browser.BrowserWindow(
        base_url + "/desktop/client/toast.php", True)
    toast_window.style_toast()
    # height of one toast -- this will be overridden but just in case
    toast_window.set_size(TOAST_WIDTH, 72)
    event.subscribe(settings.AUTH_CHANGED_EVENT, toast_window.hide)

    # check if system tray should be enabled
    if settings.get_setting("SystemTray", default=True):
        create_sys_tray()

def create_sys_tray():
    global sysTray
    sysIcon = QtGui.QIcon(application.resource_path("fbmessenger.png"))
    sysTray = QtGui.QSystemTrayIcon(sysIcon, application.get_qt_application())
    sysTray.activated.connect(on_sys_tray_activated)

    sysTrayMenu = QtGui.QMenu()

    global showHide
    showHide = sysTrayMenu.addAction("Hide")
    showHide.triggered.connect(on_sys_show_hide_activated)
    quit = sysTrayMenu.addAction("Quit")
    quit.triggered.connect(application.quit)
    sysTray.setContextMenu(sysTrayMenu)
    sysTray.setVisible(True)

def on_sys_tray_activated(reason):
    if reason == QtGui.QSystemTrayIcon.Trigger or reason == QtGui.QSystemTrayIcon.DoubleClick:
        show_or_hide_main_window()

def on_sys_show_hide_activated():
    show_or_hide_main_window()

def show_or_hide_chat_window():
    if chat_window.is_visible():
        chat_window.hide()
    else:
        chat_window.show()

def show_or_hide_main_window():
    if main_window.is_visible():
        main_window.hide()
        showHide.setText("Show")
        settings.set_setting("Minimized", True)
    else:
        main_window.show()
        showHide.setText("Hide")
        settings.set_setting("Minimized", False)

# The main window's position is saved whenever it is moved or resized, so we
# restore it when the window is created.
def init_main_window():
    saved_rectangle = settings.get_setting("MainWindowRectangle")
    if saved_rectangle:
        main_window.set_rectangle(*saved_rectangle)<commit_msg>Fix a bug regarding chat window still popping up when application is launched, even if the chat window was closed before closing the application.<commit_after>from . import application
from . import browser
from . import settings
from . import event
from PyQt4 import QtCore, QtGui

TOAST_WIDTH = 330
# Used for toast and chat window positioning
_margin = 10

def init():
    base_url = "https://www.facebook.com"
    base_url_override = settings.get_setting("BaseUrl")
    if (base_url_override):
        print("BaseUrl:", base_url_override)
        base_url = base_url_override

    global main_window
    closable_main = not settings.get_setting("SystemTray", default=True)
    main_window = browser.BrowserWindow(base_url + "/desktop/client/", closable_main)
    main_window.set_size(212, 640)
    main_window.set_title("Messenger")
    def main_window_moved_or_resized():
        settings.set_setting(
            "MainWindowRectangle", main_window.get_rectangle())
    event.subscribe(main_window.MOVE_EVENT, main_window_moved_or_resized)
    event.subscribe(main_window.RESIZE_EVENT, main_window_moved_or_resized)
    event.subscribe(main_window.HIDE_EVENT, show_or_hide_main_window)
    event.subscribe(main_window.CLOSE_EVENT, application.quit)
    init_main_window()

    global chat_window
    chat_window = browser.BrowserWindow(base_url + "/desktop/client/chat.php", False)
    chat_window.set_size(420, 340)
    def chat_window_moved_or_resized():
        settings.set_setting(
            "ChatWindowRectangle", chat_window.get_rectangle())
    event.subscribe(chat_window.MOVE_EVENT, chat_window_moved_or_resized)
    event.subscribe(chat_window.RESIZE_EVENT, chat_window_moved_or_resized)
    event.subscribe(chat_window.HIDE_EVENT, show_or_hide_chat_window)

    global toast_window
    toast_window = browser.BrowserWindow(
        base_url + "/desktop/client/toast.php", True)
    toast_window.style_toast()
    # height of one toast -- this will be overridden but just in case
    toast_window.set_size(TOAST_WIDTH, 72)
    event.subscribe(settings.AUTH_CHANGED_EVENT, toast_window.hide)

    # check if system tray should be enabled
    if settings.get_setting("SystemTray", default=True):
        create_sys_tray()

def create_sys_tray():
    global sysTray
    sysIcon = QtGui.QIcon(application.resource_path("fbmessenger.png"))
    sysTray = QtGui.QSystemTrayIcon(sysIcon, application.get_qt_application())
    sysTray.activated.connect(on_sys_tray_activated)

    sysTrayMenu = QtGui.QMenu()

    global showHide
    showHide = sysTrayMenu.addAction("Hide")
    showHide.triggered.connect(on_sys_show_hide_activated)
    quit = sysTrayMenu.addAction("Quit")
    quit.triggered.connect(application.quit)
    sysTray.setContextMenu(sysTrayMenu)
    sysTray.setVisible(True)

def on_sys_tray_activated(reason):
    if reason == QtGui.QSystemTrayIcon.Trigger or reason == QtGui.QSystemTrayIcon.DoubleClick:
        show_or_hide_main_window()

def on_sys_show_hide_activated():
    show_or_hide_main_window()

def show_or_hide_chat_window():
    if chat_window.is_visible():
        chat_window.hide()
        chat_window._on_close()
    else:
        chat_window.show()

def show_or_hide_main_window():
    if main_window.is_visible():
        main_window.hide()
        showHide.setText("Show")
        settings.set_setting("Minimized", True)
    else:
        main_window.show()
        showHide.setText("Hide")
        settings.set_setting("Minimized", False)

# The main window's position is saved whenever it is moved or resized, so we
# restore it when the window is created.
def init_main_window():
    saved_rectangle = settings.get_setting("MainWindowRectangle")
    if saved_rectangle:
        main_window.set_rectangle(*saved_rectangle)
{'fraction_non_alphanumeric': 0.08936804990507187, 'fraction_numerical': 0.005424464334147003, 'mean_word_length': 4.271622587562545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '622958', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2335, 'n_words': 429}