Skip to content

Commit

Permalink
v0.0.7.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Helmssyss committed Dec 24, 2023
1 parent 7563d59 commit 0d14f74
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 14 deletions.
22 changes: 13 additions & 9 deletions GUI/src/funcs/sync_dll_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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
else:
return False

def ManageDllStarted(self):
""" Server'i Başlat """
""" Start to server"""
try:
self.__magnetDll = ctypes.CDLL(name=self._dllPath)
except FileNotFoundError:
Expand All @@ -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()):
Expand All @@ -56,26 +57,25 @@ 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:
""" dosya indirme bittiyse True, bitmediyse False """
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):
Expand All @@ -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"
Expand Down
22 changes: 19 additions & 3 deletions GUI/src/funcs/sync_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ 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

finally:
# print("SyncClientInfoWorker START")
sleep(0.6)
sleep(0.6)
# ##### ===> SyncClientInfoWorker

# ##### ===> SyncFileSenderWorker
Expand Down Expand Up @@ -189,4 +187,22 @@ def checkStart(self):
self.checkNet.emit(False)
finally:
sleep(0.1)
# #### ====> SyncCheckNetWorker
# #### ====> 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
17 changes: 17 additions & 0 deletions GUI/src/pages/sync_server_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion GUI/src/service/src/sync_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ __SYNCPRIVATE void GetClientDevice(char* buffer) {
}
}catch(const std::exception& e){
std::cerr << "GetClientDevice -> " << e.what() << '\n';
onDisconnect = true;

}
}

Expand Down Expand Up @@ -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();
Expand All @@ -385,3 +393,4 @@ __SYNCPUBLIC void CloseServer() {
onDisconnect = true;
exit(0);
}

3 changes: 2 additions & 1 deletion GUI/src/service/src/sync_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <vector>
#include <iostream>

#define __SYNCPUBLIC extern "C" __declspec(dllexport)
#define __SYNCPUBLIC extern "C" __declspec(dllexport)
#define __SYNCPRIVATE
#define SINGLE "SINGLE"
#define DECLINE "DECLINE"
Expand Down Expand Up @@ -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
Binary file modified GUI/sync_service.dll
Binary file not shown.

0 comments on commit 0d14f74

Please sign in to comment.