leaguecloser 1.0.5
Mock package that auto-closes the League client

# Auto League Closer™

![The program moving the cursor to the X button, then the exit button](https://i.gyazo.com/acb406cece18d5138c53894cb9dae249.gif)

Tired of procrastinating on homework all day while still being hardstuck Bronze? Suffering from a bad case of League withdrawal?

Well, I've got a solution for you! Install the **Auto League Closer™**!

This handy program will **automatically close the League of Legends client whenever it's running**, so you can get back to binging YouTube videos - uh, I mean doing homework :)

## About

This is a **mock application** - complex enough to run into many common issues, but simple enough to quickly understand. The goal is to serve as a **reference for best practices** by using a clean project structure and handling packaging/distribution methods.

## Installation

Run the [installer](https://github.com/Giantpizzahead/auto-league-closer/releases/download/v1.0.4/LeagueCloserSetup.exe). (This app only works on Windows.)

## How It Works

1. Repeatedly checks if League is open using [psutil](https://pypi.org/project/psutil/).
2. Closes League in a \~fancy\~ way using [SikuliX](http://sikulix.com/).

## Using the Python Module

This module is just like any other Python module! See its [PyPi page](https://pypi.org/project/leaguecloser/), or just install it with:

```bash
$ pip install leaguecloser
```

Example usage (also what the installable app does):

```python
import leaguecloser
import time

print("Searching for League...")
while True:
    if leaguecloser.is_league_running():
        print("\nNO LEAGUE ALLOWED!")
        if leaguecloser.close_league():
            print("\nThat's right... now get back to work!")
    time.sleep(3)
```

## Best Practices

### Makefile

The [Makefile](https://github.com/Giantpizzahead/auto-league-closer/blob/main/Makefile) contains good practice methods for the common tasks below:

```bash
$ make run  # Runs the file
$ make test  # Runs all tests
$ make package_create  # Creates (or updates) the leaguecloser package
$ make package_upload  # Uploads the leaguecloser package to PyPi
$ make build_app  # Builds the app into a standalone folder with an executable ("freezes" the app)
```

The purpose of a Makefile is to simplify repetitive tasks. It's basically multiple shell scripts, but combined into one file with a simple command for each task.

### Building (EXEs) and Packaging (PyPi)

For building and packaging, these files must be configured per project (this repo serves as a good reference for how to do this!):

- [pyproject.toml](https://github.com/Giantpizzahead/auto-league-closer/blob/main/pyproject.toml) to create a PyPi package and specify required dependencies
- [MANIFEST.in](https://github.com/Giantpizzahead/auto-league-closer/blob/main/MANIFEST.in) to specify data files for setuptools to include in the package
- [src/app.py](https://github.com/Giantpizzahead/auto-league-closer/blob/main/src/app.py) as an entry point for the PyInstaller app
- [misc/InstallerSetupScript.iss](https://github.com/Giantpizzahead/auto-league-closer/blob/main/misc/InstallerSetupScript.iss), auto-generated by Inno Setup to create a Windows installer for the app.

### Handling Data Files

Since this app uses both **static and dynamic data files** (the SikuliX script folder, along with a large JAR file that is downloaded on the first run), the above files and some special code were required. Actually, the module, albeit small, follows best practices:

- [`__init__.py`](https://github.com/Giantpizzahead/auto-league-closer/blob/main/src/leaguecloser/__init__.py) only exposes things that are meant to be public and has a docstring describing the module with a copyright footer
- [`computer.py`](https://github.com/Giantpizzahead/auto-league-closer/blob/main/src/leaguecloser/computer.py) keeps large code organized through code reuse, clear sections using comments, and Google docstrings for variables and functions.
- [`league.py`](https://github.com/Giantpizzahead/auto-league-closer/blob/main/src/leaguecloser/league.py) exists to ensure each file serves a specific purpose (separation of concerns), rather than bunching this short piece of code into another file.
- [`sikuli.py`](https://github.com/Giantpizzahead/auto-league-closer/blob/main/src/leaguecloser/sikuli.py) treats frozen and non-frozen environments differently, and demonstrates how to handle program data files. (Data that's unique per computer user should be stored in `%APPDATA%` instead.)

## Development Setup

Run the development environment [setup script](https://github.com/Giantpizzahead/auto-league-closer/blob/main/misc/Dev%20Setup.ps1) to create a [virtual environment](https://kylefu.me/cheat_python/envanddeps.html) and install dependencies:

```powershell
> & '.\misc\Dev Setup.ps1'
```

### Publishing a New Version

Here are the steps:

- Change the project version in `pyproject.toml`.

- Delete the `dist/package` directory.

- Run `make package_create package_upload` and `make package_upload

```bash
$ make build_app
$ make package_create
$ make package_upload
```

- Compile the Inno Setup script.

- Create a new release on Github with the generated installer attached as a binary.