11from geography .continents import OurWorld
2- from ui .interfaces import Tab , LatencyContent , TooltipMDIconButton
3- from typedef .win import WindowNames , ICANHAZURL , ICANHAZDNS
2+ from ui .interfaces import Tab , LatencyContent , TooltipMDIconButton , ConnectionDialog
3+ from typedef .win import WindowNames
44from cli .sentinel import NodeTreeData
55from typedef .konstants import NodeKeys , TextStrings , MeileColors , HTTParams , IBCTokens
66from cli .sentinel import disconnect as Disconnect
@@ -219,16 +219,16 @@ def runNodeThread(self):
219219 yield 0.6
220220 thread2 = Thread (target = lambda : self .progress_load ())
221221 thread2 .start ()
222- thread = Thread (target = lambda : self .NodeTree .get_nodes ("13s " ))
222+ thread = Thread (target = lambda : self .NodeTree .get_nodes ("23s " ))
223223 thread .start ()
224224
225225 Clock .schedule_interval (partial (self .update_status_text , thread ), 1.6 )
226226
227227 @delayable
228228 def progress_load (self ):
229- for k in range (1 ,1000 ):
229+ for k in range (1 ,2000 ):
230230 yield 0.0375
231- self .manager .get_screen (WindowNames .PRELOAD ).ids .pb .value += 0.001
231+ self .manager .get_screen (WindowNames .PRELOAD ).ids .pb .value += 0.0005
232232
233233
234234 def CopyBin (self ):
@@ -341,6 +341,7 @@ class MainWindow(Screen):
341341 ConnectedDict = {'v2ray_pid' : None , 'result' : False }
342342 NodeWidget = None
343343 Markers = []
344+ LatLong = []
344345
345346
346347 def __init__ (self , node_tree , ** kwargs ):
@@ -392,9 +393,9 @@ def build_meile_map(self):
392393
393394 if not self .MeileMapBuilt :
394395 self .MeileMap = MapView (lat = 50.6394 , lon = 3.057 , zoom = 2 )
395- source = MapSource (url = "https://server.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}.png" ,
396- cache_key = "meile-map-canvas-dark-grey-base" ,
397- tile_size = 512 ,
396+ source = MapSource (url = MeileColors . ARCGIS_MAP ,
397+ cache_key = "meile-map-canvas-dark-grey-base-2 " ,
398+ tile_size = 256 ,
398399 image_ext = "png" ,
399400 attribution = "@ Meile" ,
400401 size_hint = (.7 ,1 ))
@@ -415,7 +416,7 @@ def AddCountryNodePins(self, clear):
415416 try :
416417
417418 if clear :
418- for m in self .Makers :
419+ for m in self .Markers :
419420 self .MeileMap .remove_marker (m )
420421 self .Markers .clear ()
421422
@@ -570,16 +571,33 @@ def get_ip_address(self, dt):
570571
571572 self .old_ip = self .ip
572573 try :
573- resolver = DNSRequests .MakeDNSRequest (domain = ICANHAZDNS , timeout = 1 .5 , lifetime = 2 .5 )
574- icanhazip = resolver .DNSRequest ()
575- if icanhazip :
576- print ("%s:%s" % (ICANHAZDNS , icanhazip ))
574+ resolver = DNSRequests .MakeDNSRequest (domain = HTTParams . IFCONFIGDNS , timeout = 3 .5 , lifetime = 3 .5 )
575+ ifconfig = resolver .DNSRequest ()
576+ if ifconfig :
577+ print ("%s:%s" % (HTTParams . IFCONFIGDNS , ifconfig ))
577578 Request = HTTPRequests .MakeRequest ()
578579 http = Request .hadapter ()
579- req = http .get (ICANHAZURL )
580- self .ip = req .text
581-
582- self .manager .get_screen (WindowNames .MAIN_WINDOW ).ids .new_ip .text = self .ip
580+ req = http .get (HTTParams .IFCONFIGURL )
581+ ifJSON = req .json ()
582+ print (ifJSON )
583+ self .ip = str (ifJSON ['ip' ])
584+ self .ids .new_ip .text = self .ip
585+ self .LatLong .clear ()
586+ try :
587+ self .LatLong .append (ifJSON ['latitude' ])
588+ self .LatLong .append (ifJSON ['longitude' ])
589+ except :
590+ print ("No Lat/Long" )
591+ try :
592+ country = ifJSON ['country' ]
593+ loc = self .MeileLand .CountryLatLong [country ]
594+ self .LatLong .append (loc [0 ])
595+ self .LatLong .append (loc [1 ])
596+ except :
597+ print ("No Country...Defaulting to my dream." )
598+ loc = self .MeileLand .CountryLatLong ["Seychelles" ]
599+ self .LatLong .append (loc [0 ])
600+ self .LatLong .append (loc [1 ])
583601 return True
584602 #self.manager.get_screen(WindowNames.MAIN_WINDOW).ids.old_ip.text = "Old IP: " + self.old_ip
585603 else :
@@ -761,13 +779,21 @@ def Refresh(self, latency, *kwargs):
761779 self .remove_loading_widget (None )
762780 self .AddCountryNodePins (True )
763781 yield 0.314
764- self .add_loading_popup ("Reloading Nodes..." )
782+ cd = ConnectionDialog ()
783+ self .set_conn_dialog (cd , "Reloading Nodes..." )
765784 yield 0.314
766785 try :
767786 self .NodeTree .NodeTree = None
768- thread = ThreadWithResult (target = self .NodeTree .get_nodes , args = (latency .return_latency (),))
769- thread .start ()
770- thread .join ()
787+ t = Thread (target = lambda : self .NodeTree .get_nodes (latency .return_latency ()))
788+ t .start ()
789+ l = int (latency .return_latency ().split ('s' )[0 ])
790+ pool = l * 100
791+ inc = float (1 / pool )
792+ while t .is_alive ():
793+ yield 0.0365
794+ cd .ids .pb .value += inc
795+
796+ cd .ids .pb .value = 1
771797 except Exception as e :
772798 print (str (e ))
773799 pass
@@ -817,6 +843,7 @@ def on_tab_switch(self, instance_tabs, instance_tab, instance_tabs_label, tab_te
817843 pass
818844 def get_continent_coordinates (self , c ):
819845 loc = self .MeileLand .ContinentLatLong [c ]
846+ self .MeileMap .zoom = 4
820847 self .MeileMap .center_on (loc [0 ], loc [1 ])
821848
822849 def build_node_data (self , ncountry ):
@@ -872,6 +899,28 @@ def switch_to_sub_window(self):
872899 self .carousel .add_widget (self .NodeWidget )
873900 self .carousel .load_slide (self .NodeWidget )
874901
902+ def close_sub_window (self ):
903+ self .carousel .remove_widget (self .NodeWidget )
904+ self .carousel .load_previous ()
905+
906+ def zoom_country_map (self ):
907+ try :
908+ self .MeileMap .zoom = 7
909+ self .MeileMap .center_on (self .LatLong [0 ],self .LatLong [1 ])
910+ except Exception as e :
911+ print (str (e ))
912+ pass
913+
914+ def set_conn_dialog (self , cd , title ):
915+ self .dialog = None
916+ self .dialog = MDDialog (
917+ title = title ,
918+ type = "custom" ,
919+ content_cls = cd ,
920+ md_bg_color = get_color_from_hex (MeileColors .DIALOG_BG_COLOR ),
921+ )
922+ self .dialog .open ()
923+
875924 def load_country_nodes (self , country , * kwargs ):
876925 mw = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW )
877926 NodeTree = NodeTreeData (Meile .app .root .get_screen (WindowNames .MAIN_WINDOW ).NodeTree .NodeTree )
0 commit comments