fix(update): wait for app exit before file replacement
This commit is contained in:
17
main.py
17
main.py
@@ -835,7 +835,7 @@ class VkChatManager(QMainWindow):
|
|||||||
return candidate
|
return candidate
|
||||||
return extracted_dir
|
return extracted_dir
|
||||||
|
|
||||||
def _build_update_script(self, app_dir, source_dir, exe_name):
|
def _build_update_script(self, app_dir, source_dir, exe_name, target_pid):
|
||||||
script_path = os.path.join(tempfile.gettempdir(), "anabasis_apply_update.cmd")
|
script_path = os.path.join(tempfile.gettempdir(), "anabasis_apply_update.cmd")
|
||||||
script_lines = [
|
script_lines = [
|
||||||
"@echo off",
|
"@echo off",
|
||||||
@@ -843,8 +843,15 @@ class VkChatManager(QMainWindow):
|
|||||||
f"set APP_DIR={app_dir}",
|
f"set APP_DIR={app_dir}",
|
||||||
f"set SRC_DIR={source_dir}",
|
f"set SRC_DIR={source_dir}",
|
||||||
f"set EXE_NAME={exe_name}",
|
f"set EXE_NAME={exe_name}",
|
||||||
"timeout /t 2 /nobreak >nul",
|
f"set TARGET_PID={target_pid}",
|
||||||
"robocopy \"%SRC_DIR%\" \"%APP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:3 /W:1 >nul",
|
":wait_for_exit",
|
||||||
|
"tasklist /FI \"PID eq %TARGET_PID%\" | find \"%TARGET_PID%\" >nul",
|
||||||
|
"if %ERRORLEVEL% EQU 0 (",
|
||||||
|
" timeout /t 1 /nobreak >nul",
|
||||||
|
" goto :wait_for_exit",
|
||||||
|
")",
|
||||||
|
"timeout /t 1 /nobreak >nul",
|
||||||
|
"robocopy \"%SRC_DIR%\" \"%APP_DIR%\" /E /NFL /NDL /NJH /NJS /NP /R:12 /W:2 >nul",
|
||||||
"set RC=%ERRORLEVEL%",
|
"set RC=%ERRORLEVEL%",
|
||||||
"if %RC% GEQ 8 goto :copy_error",
|
"if %RC% GEQ 8 goto :copy_error",
|
||||||
"start \"\" \"%APP_DIR%\\%EXE_NAME%\"",
|
"start \"\" \"%APP_DIR%\\%EXE_NAME%\"",
|
||||||
@@ -892,7 +899,7 @@ class VkChatManager(QMainWindow):
|
|||||||
app_exe = sys.executable
|
app_exe = sys.executable
|
||||||
app_dir = os.path.dirname(app_exe)
|
app_dir = os.path.dirname(app_exe)
|
||||||
exe_name = os.path.basename(app_exe)
|
exe_name = os.path.basename(app_exe)
|
||||||
script_path = self._build_update_script(app_dir, source_dir, exe_name)
|
script_path = self._build_update_script(app_dir, source_dir, exe_name, os.getpid())
|
||||||
|
|
||||||
creation_flags = 0
|
creation_flags = 0
|
||||||
if hasattr(subprocess, "CREATE_NEW_PROCESS_GROUP"):
|
if hasattr(subprocess, "CREATE_NEW_PROCESS_GROUP"):
|
||||||
@@ -911,7 +918,7 @@ class VkChatManager(QMainWindow):
|
|||||||
"Обновление запущено",
|
"Обновление запущено",
|
||||||
"Обновление скачано. Приложение будет перезапущено.",
|
"Обновление скачано. Приложение будет перезапущено.",
|
||||||
)
|
)
|
||||||
QTimer.singleShot(150, QApplication.instance().quit)
|
QApplication.instance().quit()
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log_event("auto_update_failed", str(e), level="ERROR")
|
self._log_event("auto_update_failed", str(e), level="ERROR")
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ class AuthReloginSmokeTests(unittest.TestCase):
|
|||||||
self.assertIn('message_box.addButton("Обновить сейчас", QMessageBox.AcceptRole)', self.source)
|
self.assertIn('message_box.addButton("Обновить сейчас", QMessageBox.AcceptRole)', self.source)
|
||||||
self.assertIn("def _start_auto_update(self, download_url, latest_version, checksum_url=\"\", download_name=\"\"):", self.source)
|
self.assertIn("def _start_auto_update(self, download_url, latest_version, checksum_url=\"\", download_name=\"\"):", self.source)
|
||||||
self.assertIn("def _verify_update_checksum(self, zip_path, checksum_url, download_name):", self.source)
|
self.assertIn("def _verify_update_checksum(self, zip_path, checksum_url, download_name):", self.source)
|
||||||
|
self.assertIn("def _build_update_script(self, app_dir, source_dir, exe_name, target_pid):", self.source)
|
||||||
|
self.assertIn("set TARGET_PID=", self.source)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user