Compare commits

...

10 Commits

Author SHA1 Message Date
Hamed
8463eb28df added melli internet install 2026-03-30 11:33:37 +03:30
Hamed
c23805320e run on startup silently 2026-01-06 23:04:07 +03:30
Hamed
66c0482ae3 update gitignore 2026-01-06 22:44:59 +03:30
Hamed
9647115ad6 update gitignore 2026-01-06 22:43:48 +03:30
Hamed
7fbd6ca080 gitignore update 2026-01-06 22:42:46 +03:30
Hamed
4163d1cf6e fixed the ensure one instanve only logic. 2025-12-15 20:26:07 +03:30
Hamed
fb12d5a216 correcting the one-instance only mechanism 2025-12-04 17:20:05 +03:30
Hamed
9aa2ff2bd0 gitignore update 2025-12-04 17:07:40 +03:30
Hamed
96a8092716 Remove merge conflict markers from requirements.txt 2025-12-04 17:02:09 +03:30
Hamed
ad7ca318a7 Delete app.lock 2025-12-04 16:59:24 +03:30
9 changed files with 81 additions and 19 deletions

11
.gitignore vendored
View File

@@ -1,6 +1,7 @@
.vscode/settings.json
src/__pycache__/config.cpython-314.pyc
src/__pycache__/startup.cpython-314.pyc
src/__pycache__/startup.cpython-314.pyc
src/__pycache__/config.cpython-314.pyc
__pycache__/
*.py[cod]
*$py.class
app.lock
src/__pycache__/
venv

View File

@@ -1 +0,0 @@
9512

19
install-melli.bat Normal file
View File

@@ -0,0 +1,19 @@
@echo off
REM install.bat
REM This script sets up a Python virtual environment and installs required libraries.
REM Make sure to run this script in the project directory.
REM Create Python virtual environment
python -m venv venv
REM Activate the virtual environment
call venv\Scripts\activate.bat
REM Upgrade pip
pip install --upgrade pip -i https://mirror-pypi.runflare.com/simple
REM Install required libraries from requirements.txt
pip install -r requirements.txt --no-cache-dir -i https://mirror-pypi.runflare.com/simple
echo Environment setup complete.
pause

View File

@@ -1,8 +1,5 @@
keyboard==0.13.5
pyperclip==1.9.0
pystray==0.19.5
<<<<<<< HEAD
Pillow==12.0.0
=======
Pillow==12.0.0
>>>>>>> 4143eb7dfbdcc5a646f23c1fc5369779d41c4f4a
psutil>=5.8.0

4
run_silent.bat Normal file
View File

@@ -0,0 +1,4 @@
@echo off
cd /d "%~dp0"
call venv\Scripts\activate.bat
start "" pythonw src\main.pyw

4
run_silent.vbs Normal file
View File

@@ -0,0 +1,4 @@
Set WshShell = CreateObject("WScript.Shell")
strPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
WshShell.Run chr(34) & strPath & "\run_silent.bat" & Chr(34), 0
Set WshShell = Nothing

View File

@@ -11,7 +11,6 @@ import re
from config import load_config, save_config, get_shortcut
from startup import add_to_startup, remove_from_startup, is_in_startup
import os
import signal
import atexit
def convert_en_characters(input_str):
@@ -178,22 +177,52 @@ def cleanup_lock():
except OSError:
pass
def is_process_running(pid):
"""Check if a process with the given PID is still running."""
try:
import psutil
return psutil.pid_exists(pid)
except:
# Fallback if psutil is not available
try:
os.kill(pid, 0) # Signal 0 doesn't kill, just checks if process exists
return True
except OSError:
return False
def ensure_single_instance():
"""Ensure only one instance of the app is running. Exit if another instance exists."""
if os.path.exists(LOCK_FILE):
try:
# Read the PID from the lock file
with open(LOCK_FILE, 'r') as f:
pid = int(f.read().strip())
old_pid = int(f.read().strip())
if pid != os.getpid():
# Check if the process with that PID is still running
if is_process_running(old_pid):
# Another instance is running, show message and exit
import ctypes
ctypes.windll.user32.MessageBoxW(
0,
"Another instance of OopsWrongLang is already running.\n\nPlease close the existing instance first (check your system tray).",
"OopsWrongLang - Already Running",
0x40 # MB_ICONINFORMATION
)
os._exit(1)
else:
# Process is not running, remove the stale lock file
try:
os.kill(pid, signal.SIGTERM)
print(f"Killed existing instance with PID {pid}")
time.sleep(0.5)
os.remove(LOCK_FILE)
except OSError:
pass
except (ValueError, OSError):
# Lock file exists but is invalid or unreadable, clean it up and continue
try:
os.remove(LOCK_FILE)
except OSError:
pass
# Create lock file with our PID
with open(LOCK_FILE, 'w') as f:
f.write(str(os.getpid()))
@@ -203,7 +232,12 @@ def main():
ensure_single_instance()
config = load_config()
# Sync startup state just in case it was changed externally
config["run_on_startup"] = is_in_startup()
if is_in_startup():
config["run_on_startup"] = True
# Update the registry key to point to the current location (in case the app was moved)
add_to_startup()
else:
config["run_on_startup"] = False
save_config(config)
# Start the tray icon in a separate thread

View File

@@ -2,7 +2,11 @@ import os
import winreg
APP_NAME = "OopsWrongLang"
RUN_BAT_PATH = os.path.abspath("run.bat")
# Get the directory of the current script (src)
current_dir = os.path.dirname(os.path.abspath(__file__))
# The project root is one level up
project_root = os.path.dirname(current_dir)
RUN_BAT_PATH = os.path.join(project_root, "run_silent.vbs")
def add_to_startup():
"""