Skip to content

Commit

Permalink
Merge branch 'AdnanHodzic:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleWazard authored Mar 8, 2024
2 parents f3beb67 + 0354775 commit 6dbb8e2
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 54 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Linux Build

on:
push:
paths-ignore:
- "README.md"
- ".gitignore"
- "LICENSE"
pull_request:

jobs:
build_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]

- name: Install poetry
run: pipx install poetry

- name: "Setup Python"
uses: actions/[email protected]
with:
python-version: 3.12
cache: "poetry"

- name: "Install auto-cpufreq"
run: sudo ./auto-cpufreq-installer --install

26 changes: 26 additions & 0 deletions .github/workflows/build-nix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Nix Flake

on:
push:
paths-ignore:
- "README.md"
- ".gitignore"
- "LICENSE"
pull_request:

jobs:
build-nix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: "Install Nix ❄️"
uses: cachix/install-nix-action@v25

- name: "Nix Cache"
uses: DeterminateSystems/magic-nix-cache-action@v3

- name: "Build Nix Flake ❄️"
run: nix build


2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# auto-cpufreq
[![Linux Build](https://github.com/AdnanHodzic/auto-cpufreq/actions/workflows/build-linux.yml/badge.svg?event=push)](https://github.com/AdnanHodzic/auto-cpufreq/actions/workflows/build-linux.yml)
[![Nix Flake](https://github.com/AdnanHodzic/auto-cpufreq/actions/workflows/build-nix.yaml/badge.svg?event=push)](https://github.com/AdnanHodzic/auto-cpufreq/actions/workflows/build-nix.yaml)

Automatic CPU speed & power optimizer for Linux. Actively monitors laptop battery state, CPU usage, CPU temperature, and system load, ultimately allowing you to improve battery life without making any compromises.

Expand Down
56 changes: 36 additions & 20 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,32 +174,48 @@ def check_for_update():
# Fetch the latest release information from GitHub API
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
try:
latest_release = requests.get(latest_release_url).json()
response = requests.get(latest_release_url)
if response.status_code == 200:
latest_release = response.json()
else:
message = response.json().get("message")
print("Error fetching recent release!")
if message is not None and message.startswith("API rate limit exceeded"):
print("GitHub Rate limit exceeded. Please try again later within 1 hour or use different network/VPN.")
else:
print("Unexpected status code:", response.status_code)
return False
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout,
requests.exceptions.RequestException, requests.exceptions.HTTPError) as err:
print ("Error Connecting to server!")
print("Error Connecting to server!")
return False

latest_version = latest_release["tag_name"]
latest_version = latest_release.get("tag_name")

# Get the current version of auto-cpufreq
# Extract version number from the output string
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
try:
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
except AttributeError:
print("Error Retrieving Current Version!")
exit(1)
installed_version = "v" + version_line
#Check whether the same is installed or not
# Compare the latest version with the installed version and perform update if necessary
if latest_version == installed_version:
print("auto-cpufreq is up to date")
return False
if latest_version is not None:
# Get the current version of auto-cpufreq
# Extract version number from the output string
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
try:
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
except AttributeError:
print("Error Retrieving Current Version!")
exit(1)
installed_version = "v" + version_line
#Check whether the same is installed or not
# Compare the latest version with the installed version and perform update if necessary
if latest_version == installed_version:
print("auto-cpufreq is up to date")
return False
else:
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
print("Note that your previous custom settings might be erased with the following update")
return True
else:
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
print("Note that your previous custom settings might be erased with the following update")
return True
# Handle the case where "tag_name" key doesn't exist
print("Malformed Released data!\nReinstall manually or Open an issue on GitHub for help!")



def new_update(custom_dir):
os.chdir(custom_dir)
Expand Down
2 changes: 1 addition & 1 deletion auto_cpufreq/gui/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_stats():
def get_version():
# snap package
if os.getenv("PKG_MARKER") == "SNAP":
return getoutput("echo \(Snap\) $SNAP_VERSION")
return getoutput(r"echo \(Snap\) $SNAP_VERSION")
# aur package
elif dist_name in ["arch", "manjaro", "garuda"]:
aur_pkg_check = run("pacman -Qs auto-cpufreq > /dev/null", shell=True)
Expand Down
66 changes: 33 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6dbb8e2

Please sign in to comment.