<commit_before>import application
import browser
import settings
import event
import external

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

# Chat position is not saved when the application closes
_chat_rectangle = None

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
  main_window = browser.BrowserWindow(base_url + "/desktop/client/")
  main_window.set_size(212, 640)
  main_window.set_title("Messenger")
  def main_window_moved():
    external.arbiter_inform_all("FbDesktop.mainWindowMoved", None)
  event.subscribe(main_window.MOVE_EVENT, main_window_moved)
  # js doesn't listen for a separate resize event, so we use move here
  event.subscribe(main_window.RESIZE_EVENT, main_window_moved)
  def main_window_activated():
    external.arbiter_inform_all("FbDesktop.mainWindowActivated", None)
  event.subscribe(main_window.ACTIVATE_EVENT, main_window_activated)
  def main_window_deactivated():
    external.arbiter_inform_all("FbDesktop.mainWindowDeactivated", None)
  event.subscribe(main_window.DEACTIVATE_EVENT, main_window_deactivated)
  def main_window_moved():
    settings.set_setting("MainWindowRectangle", main_window.get_rectangle())
  event.subscribe(main_window.MOVE_EVENT, main_window_moved)
  event.subscribe(main_window.CLOSE_EVENT, application.quit)
  show_main_window()

  global chat_window
  chat_window = browser.BrowserWindow(base_url + "/desktop/client/chat.php")
  chat_window.set_size(420, 340)
  def chat_window_activated():
    external.arbiter_inform_all("FbdChat.chatWindowActivated", None)
  event.subscribe(chat_window.ACTIVATE_EVENT, chat_window_activated)
  def chat_window_moved():
    global _chat_rectangle
    _chat_rectangle = chat_window.get_rectangle()
  event.subscribe(chat_window.MOVE_EVENT, chat_window_moved)

  global toast_window
  toast_window = browser.BrowserWindow(base_url + "/desktop/client/toast.php")
  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)

def show_main_window():
  saved_rectangle = settings.get_setting("MainWindowRectangle")
  if saved_rectangle:
    main_window.set_rectangle(*_fit_rectangle_to_desktop(*saved_rectangle))
  main_window.show()

def show_chat_window():
  if _chat_rectangle:
    rect = _chat_rectangle
  else:
    desk_x, desk_y, desk_width, desk_height = application.get_desktop_rectangle()
    main_x, main_y, main_width, main_height = main_window.get_rectangle()
    chat_x, chat_y, chat_width, chat_height = chat_window.get_rectangle()<commit_msg>save chat window position on resize as well as move<commit_after>import application
import browser
import settings
import event
import external

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

# Chat position is not saved when the application closes
_chat_rectangle = None

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
  main_window = browser.BrowserWindow(base_url + "/desktop/client/")
  main_window.set_size(212, 640)
  main_window.set_title("Messenger")
  def main_window_moved():
    external.arbiter_inform_all("FbDesktop.mainWindowMoved", None)
  event.subscribe(main_window.MOVE_EVENT, main_window_moved)
  # js doesn't listen for a separate resize event, so we use move here
  event.subscribe(main_window.RESIZE_EVENT, main_window_moved)
  def main_window_activated():
    external.arbiter_inform_all("FbDesktop.mainWindowActivated", None)
  event.subscribe(main_window.ACTIVATE_EVENT, main_window_activated)
  def main_window_deactivated():
    external.arbiter_inform_all("FbDesktop.mainWindowDeactivated", None)
  event.subscribe(main_window.DEACTIVATE_EVENT, main_window_deactivated)
  def main_window_moved():
    settings.set_setting("MainWindowRectangle", main_window.get_rectangle())
  event.subscribe(main_window.MOVE_EVENT, main_window_moved)
  event.subscribe(main_window.CLOSE_EVENT, application.quit)
  show_main_window()

  global chat_window
  chat_window = browser.BrowserWindow(base_url + "/desktop/client/chat.php")
  chat_window.set_size(420, 340)
  def chat_window_activated():
    external.arbiter_inform_all("FbdChat.chatWindowActivated", None)
  event.subscribe(chat_window.ACTIVATE_EVENT, chat_window_activated)
  def chat_window_moved():
    global _chat_rectangle
    _chat_rectangle = chat_window.get_rectangle()
  event.subscribe(chat_window.MOVE_EVENT, chat_window_moved)
  event.subscribe(chat_window.RESIZE_EVENT, chat_window_moved)

  global toast_window
  toast_window = browser.BrowserWindow(base_url + "/desktop/client/toast.php")
  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)

def show_main_window():
  saved_rectangle = settings.get_setting("MainWindowRectangle")
  if saved_rectangle:
    main_window.set_rectangle(*_fit_rectangle_to_desktop(*saved_rectangle))
  main_window.show()

def show_chat_window():
  if _chat_rectangle:
    rect = _chat_rectangle
  else:
    desk_x, desk_y, desk_width, desk_height = application.get_desktop_rectangle()
    main_x, main_y, main_width, main_height = main_window.get_rectangle()
    chat_x, chat_y, chat_width, chat_height = chat_window.get_rectangle()
{'fraction_non_alphanumeric': 0.08760272774960658, 'fraction_numerical': 0.006644518272425249, 'mean_word_length': 6.185929648241206, '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': '6216940', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1845, 'n_words': 344}