- name: Ensure Ulauncher and dependencies are installed
  ansible.builtin.package:
    name:
      - ulauncher
      # - python3-pytz
      - python3-tornado
      - python3-docker
      - python3-requests
      - python3-pint
      - python3-simpleeval
      - python3-parsedatetime
      - python3-fuzzywuzzy
      # - python3-thefuzz
    state: present
  become: true

- name: Ensure Ulauncher config directory exists
  ansible.builtin.file:
    path: "~/.config/ulauncher"
    state: directory
    mode: '0755'

- name: Configure Ulauncher settings
  ansible.builtin.copy:
    content: "{{ ulauncher_settings | to_json }}"
    dest: "~/.config/ulauncher/settings.json"
    mode: '0644'
  vars:
    ulauncher_settings:
      blacklisted-desktop-dirs: >
        /usr/share/locale:/usr/share/app-install:/usr/share/kservices5:/usr/share/fk5:/usr/share/kservicetypes5:
        /usr/share/applications/screensavers:/usr/share/kde4:/usr/share/mimelnk
      clear-previous-query: true
      disable-desktop-filters: false
      grab-mouse-pointer: false
      hotkey-show-app: "<Control>Space"
      render-on-screen: "mouse-pointer-monitor"
      show-indicator-icon: true
      show-recent-apps: "4"
      terminal-command: "ptyxis"
      theme-name: "dark"

- name: Configure Ulauncher shortcuts
  ansible.builtin.copy:
    content: "{{ ulauncher_shortcuts | to_json }}"
    dest: "~/.config/ulauncher/shortcuts.json"
    mode: '0644'
  vars:
    ulauncher_shortcuts:
      "0bab9d26-5464-4501-bc95-9995d8fa1405":
        id: "0bab9d26-5464-4501-bc95-9995d8fa1405"
        name: "Google Search"
        keyword: "g"
        cmd: "https://google.com/search?q=%s"
        icon: "/usr/share/ulauncher/media/google-search-icon.png"
        is_default_search: true
        run_without_argument: false
        added: 0
      "d72834d1-5d81-4f5d-a9f6-386b12110f56":
        id: "d72834d1-5d81-4f5d-a9f6-386b12110f56"
        name: "Stack Overflow"
        keyword: "so"
        cmd: "https://stackoverflow.com/search?q=%s"
        icon: "/usr/share/ulauncher/media/stackoverflow-icon.svg"
        is_default_search: true
        run_without_argument: false
        added: 0
      "4dfcffeb-879c-49b2-83bb-c16254a7ce75":
        id: "4dfcffeb-879c-49b2-83bb-c16254a7ce75"
        name: "GoLink"
        keyword: "go"
        cmd: "http://go/%s"
        icon: null
        is_default_search: false
        run_without_argument: false
        added: 0
      "40d1ed32-8fd3-4bf8-92f5-cbaa7cd607a1":
        id: "40d1ed32-8fd3-4bf8-92f5-cbaa7cd607a1"
        name: "NixOS"
        keyword: "nix"
        cmd: "https://search.nixos.org/packages?query=%s"
        icon: null
        is_default_search: false
        run_without_argument: false
        added: 0
      "40d1ed32-8fd3-4ff4-92f6-fbaa7cd607a1":
        id: "42d1ed42-8dd3-2bf8-92f5-cbaa7cd607a1"
        name: "Flathub"
        keyword: "flat"
        cmd: "https://flathub.org/apps/search?q=%s"
        icon: null
        is_default_search: false
        run_without_argument: false
        added: 0
      "43d1ed32-8fd3-fbf8-94f5-cffa7cd607a1":
        id: "40d1ed32-8fd3-4bf8-92f5-cbaa7cd607a1"
        name: "GitHub"
        keyword: "gh"
        cmd: "https://github.com/search?q=%s"
        icon: null
        is_default_search: false
        run_without_argument: false
        added: 0
