diff --git a/GUI/src/funcs/sync_dll_service.py b/GUI/src/funcs/sync_dll_service.py index a4b51b3..6e2190d 100644 --- a/GUI/src/funcs/sync_dll_service.py +++ b/GUI/src/funcs/sync_dll_service.py @@ -12,7 +12,7 @@ def __init__(self) -> None: self.__magnetDll:ctypes.CDLL = None def LoadMagnetDll(self) -> bool: - """ Dll dosyasının varlığını kontrol et """ + """ Check for exist of dll file""" if os.path.exists(self._dllPath): return True @@ -20,7 +20,7 @@ def LoadMagnetDll(self) -> bool: return False def ManageDllStarted(self): - """ Server'i Başlat """ + """ Start to server""" try: self.__magnetDll = ctypes.CDLL(name=self._dllPath) except FileNotFoundError: @@ -30,10 +30,11 @@ def ManageDllStarted(self): self.__magnetDll.StartServer() def ManageDllFinished(self): + "Stop to server" self.__magnetDll.CloseServer() def SelectSendDllFilePath(self, sendListWidget: SyncListWidget): - """ DOSYALARI GÖNDER """ + """ Files send """ file_info_list = [] for i in range(sendListWidget.count()): @@ -56,18 +57,17 @@ def HandleFileTransfer(cls): return cls.__magnetDll.HandleFileTransfer() def GetCurrentDownloadFileSize(self) -> int: - """ şuan indirilen dosyanin boyutu (byte)""" + """ Size of the currently downloaded file (bytes)""" return self.__magnetDll.GetCurrentDownloadFileSize() def GetCurrentTotalDownloadFileSize(self) -> int: - """ şuan indirilecek dosyanin toplam boyutu (byte)""" + """ Total size the file to will download now (byte)""" return self.__magnetDll.GetCurrentTotalDownloadFileSize() def GetIsLoadFile(self): - """ şuan dosya indiriliyorsa True indirilmiyorsa False """ - + """ True if the file is downloading now, if not downloading file is False""" return self.__magnetDll.GetIsLoadFile() def GetIsDownloadCompletedFile(self) -> bool: @@ -75,7 +75,7 @@ def GetIsDownloadCompletedFile(self) -> bool: return self.__magnetDll.GetIsDownloadCompletedFile() def CanGetDeviceState(self) -> bool: - """dosya gönderiliyor mu gönderiliyorsa True gönderilmiyorsa False""" + """is the file sending,True if file sending if not send file is false.""" return self.__magnetDll.CanGetDeviceState() def GetDeviceBatteryStatus(self): @@ -86,9 +86,13 @@ def SetCanDeviceState(self,state: bool): def SetTransferMode(self,mode: bool): self.__magnetDll.SetTransferMode(mode) + + def GetonDisconnectDevice(self) -> bool: + "Is connection closed?" + return self.__magnetDll.GetonDisconnectDevice() def formatSize(self,byte) -> str: - """ Dosya boyutu birim dönüşümü """ + """ file size conversion""" if byte < 1024: return f"{byte} B" diff --git a/GUI/src/funcs/sync_workers.py b/GUI/src/funcs/sync_workers.py index 0f38417..fe2bfc0 100644 --- a/GUI/src/funcs/sync_workers.py +++ b/GUI/src/funcs/sync_workers.py @@ -45,7 +45,6 @@ def start(self) -> None: device_battery = int(device.attrib["device_battery"]) self.connectGetClientInfo.emit({"device_name":device_name,"device_battery":device_battery}) __DLL_SERVICE__.GetDeviceBatteryStatus() - except Exception as E: print("SyncClientInfoWorker ERROR: ",E) pass @@ -53,7 +52,6 @@ def start(self) -> None: finally: # print("SyncClientInfoWorker START") sleep(0.6) - sleep(0.6) # ##### ===> SyncClientInfoWorker # ##### ===> SyncFileSenderWorker @@ -189,4 +187,22 @@ def checkStart(self): self.checkNet.emit(False) finally: sleep(0.1) -# #### ====> SyncCheckNetWorker \ No newline at end of file +# #### ====> SyncCheckNetWorker + +# #### ====> SyncOnClientDisconnectWorker +class SyncOnClientDisconnectWorker(QObject): + onDisconnect = pyqtSignal(bool) + def __init__(self) -> None: + super().__init__() + self.__run = True + + def setRunState(self,newRunState: bool): + self.__run = newRunState + + def disconnectListen(self): + while self.__run: + state = __DLL_SERVICE__.GetonDisconnectDevice() + print("GetonDisconnectDevice -> ",state) + self.onDisconnect.emit(state) + sleep(0.6) +# #### ====> SyncOnClientDisconnectWorker \ No newline at end of file diff --git a/GUI/src/pages/sync_server_page.py b/GUI/src/pages/sync_server_page.py index 60bdeac..964f1a7 100644 --- a/GUI/src/pages/sync_server_page.py +++ b/GUI/src/pages/sync_server_page.py @@ -12,6 +12,7 @@ from src.funcs.sync_workers import SyncProcessRunWorker from src.funcs.sync_workers import SyncFileDownloadWorker from src.funcs.sync_workers import SyncLoadFileListener +from src.funcs.sync_workers import SyncOnClientDisconnectWorker from src.pages.sync_load_page import LoadWindow from src.widgets import SyncListWidget from src.widgets import SyncTableWidget @@ -936,6 +937,19 @@ def connectedButtons(self): self.getInfoWorker.connectGetClientInfo.connect(self.getClientInfo) self.frame_top_btns.mouseDoubleClickEvent = self.doubleClickMaximizeRestore + self.getOnClientDisconnectWorker = SyncOnClientDisconnectWorker() + self.getOnClientDisconnectThread = QThread(self) + self.getOnClientDisconnectWorker.moveToThread(self.getOnClientDisconnectThread) + self.getOnClientDisconnectThread.started.connect(self.getOnClientDisconnectWorker.disconnectListen) + self.getOnClientDisconnectThread.start() + self.getOnClientDisconnectWorker.onDisconnect.connect(self.onClientDisconnect) + + @pyqtSlot(bool) + def onClientDisconnect(self,state:bool): + if state: + print("closed to mobile") + self.closeApplication() + @pyqtSlot(bool) def onAppIsBackground(self, isBackground: bool): if isBackground: @@ -960,6 +974,9 @@ def closeApplication(self): self.getInfoWorker.setRunState(False) self.getInfoThread.quit() self.getInfoThread.wait() + self.getOnClientDisconnectWorker.setRunState(False) + self.getOnClientDisconnectThread.quit() + self.getOnClientDisconnectThread.wait() if getattr(self,"downloadFileWorker",None): self.downloadFileWorker.setRunState(False) self.downloadFileThread.quit() diff --git a/GUI/src/service/src/sync_service.cpp b/GUI/src/service/src/sync_service.cpp index b29f37c..919eb77 100644 --- a/GUI/src/service/src/sync_service.cpp +++ b/GUI/src/service/src/sync_service.cpp @@ -159,6 +159,8 @@ __SYNCPRIVATE void GetClientDevice(char* buffer) { } }catch(const std::exception& e){ std::cerr << "GetClientDevice -> " << e.what() << '\n'; + onDisconnect = true; + } } @@ -376,7 +378,13 @@ __SYNCPUBLIC void GetDeviceBatteryStatusPerSecond(){ __SYNCPUBLIC void CloseServer() { Sleep(100); - if(!mobileAppDisconnect) send(ClientSocket, DISCONNECT, strlen(DISCONNECT), 0); + if(!mobileAppDisconnect){ + send(ClientSocket, DISCONNECT, strlen(DISCONNECT), 0); + std::cout << "masaustunden kapandi" << std::endl; + }else{ + std::cout << "mobilden kapandi" << std::endl; + } + closesocket(ClientSocket); closesocket(ServerSocket); WSACleanup(); @@ -385,3 +393,4 @@ __SYNCPUBLIC void CloseServer() { onDisconnect = true; exit(0); } + diff --git a/GUI/src/service/src/sync_service.hpp b/GUI/src/service/src/sync_service.hpp index 230ccf4..6b5093d 100644 --- a/GUI/src/service/src/sync_service.hpp +++ b/GUI/src/service/src/sync_service.hpp @@ -10,7 +10,7 @@ #include #include -#define __SYNCPUBLIC extern "C" __declspec(dllexport) +#define __SYNCPUBLIC extern "C" __declspec(dllexport) #define __SYNCPRIVATE #define SINGLE "SINGLE" #define DECLINE "DECLINE" @@ -73,5 +73,6 @@ __SYNCPUBLIC inline bool GetSendFinishedState() { return sendFinished; } __SYNCPUBLIC inline bool GetIsLoadFile() { return isLoadFile; } __SYNCPUBLIC inline bool GetIsDownloadCompletedFile() { return isDownloadCompleted; } __SYNCPUBLIC inline bool CanGetDeviceState() { return isCanGetDeviceState; } +__SYNCPUBLIC inline bool GetonDisconnectDevice() { return onDisconnect; } #endif \ No newline at end of file diff --git a/GUI/sync_service.dll b/GUI/sync_service.dll index 4a7ef68..ae6e4fa 100644 Binary files a/GUI/sync_service.dll and b/GUI/sync_service.dll differ