Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package into single application #96

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ test.png
env
random_lexicon
logs
userdata
userdata
windrecorder.spec
build
dist
Binary file added __assets__/windrecorder-app.ico
Binary file not shown.
Binary file added __assets__/windrecorder-app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions buildtools/build_into_exe.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd ..
pyinstaller --onefile --windowed --icon="__assets__\windrecorder-app.ico" --name="windrecorder" "main.py"
pause
15 changes: 10 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
import requests
from PIL import Image

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
os.chdir(PROJECT_ROOT)
# 确定应用程序是脚本文件还是冻结的可执行文件
if getattr(sys, 'frozen', False):
project_root = os.path.dirname(sys.executable)
else:
project_root = os.path.abspath(os.path.dirname(__file__))
# PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
os.chdir(project_root)

from windrecorder import file_utils, utils # NOQA: E402
from windrecorder.config import config # NOQA: E402
Expand Down Expand Up @@ -43,7 +48,7 @@ def get_tray_icon(state="recording"):


def update(icon: pystray.Icon, item: pystray.MenuItem):
webbrowser.open(os.path.join(PROJECT_ROOT, "install_update.bat"))
webbrowser.open(os.path.join(project_root, "install_update.bat"))


file_utils.ensure_dir("cache")
Expand Down Expand Up @@ -79,7 +84,7 @@ def start_stop_webui(icon: pystray.Icon, item: pystray.MenuItem):
stdout=out,
stderr=err,
encoding="utf-8",
cwd=PROJECT_ROOT,
cwd=project_root,
)
time_spent = 0 # 记录启动服务以来已等待的时间
while time_spent < STREAMLIT_OPEN_TIMEOUT:
Expand Down Expand Up @@ -136,7 +141,7 @@ def start_stop_recording(icon: pystray.Icon | None = None, item: pystray.MenuIte
stdout=out,
stderr=err,
encoding="utf-8",
cwd=PROJECT_ROOT,
cwd=project_root,
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
)
if icon is not None:
Expand Down