omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Check if Pythonista is in background

    Pythonista
    5
    13
    8303
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • userista
      userista last edited by

      Is there a callback or some way to tell if the app is in the background/foreground?

      import webrowser
      webrowser.open('safari-http://')
      # I want the next line to execute only when returning back to Pythonista
      print "Back here"
      

      I tried this work around but it always returns false (I would've wrapped it in a setTimeout and checked every 30ms)

      ui.WebView().eval_js('document.hidden')

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        http://omz-software.com/pythonista/docs/ios/scene.html#scene.Scene.pause

        http://omz-forums.appspot.com/pythonista/post/5234385359994880

        http://omz-forums.appspot.com/pythonista/post/5988988296888320

        1 Reply Last reply Reply Quote 0
        • userista
          userista last edited by

          Ah perfect! thanks - would importing scene just to use scene.Scene().pause() be overkill?

          EDIT: Never mind - this only works if I have an instance of a scene - I don't think subclassing scene just for this pause is a good practice. So I can't really use scene.pause

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            It looks like if Scene is run in SceneView... it doesn't receive the pause/resume...

            import ui, scene
            
            class scTest(scene.Scene):
            	def pause(self):
            		print 'pause'
            		
            	def resume(self):
            		print 'resume'
            
            if False:
            	scene.run(scTest())
            else:
            	v = ui.View()
            	sv = scene.SceneView()
            	sv.scene = scTest()
            	#sv.hidden = True
            	v.add_subview(sv)
            	v.present('panel')
            
            1 Reply Last reply Reply Quote 0
            • ccc
              ccc last edited by

              Yes. That is documented at: http://omz-software.com/pythonista/docs/ios/scene.html#integration-with-the-ui-module

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                There is no guarantee that your script will continue to run once you launch safari. In fact, there is a guarantee that in a few minutes, the background timer will expire, and your script will be unceremoniously killed.

                If you just want to do something on a webpage, it is better to do it within a webview since you could make it modal for example, and continue only when the dialog is closed. Someone should really make a webview based clone of a full browser, with address bar, navigation, reload, stop, etc, in which case you'd never have to launch safari.

                1 Reply Last reply Reply Quote 0
                • userista
                  userista last edited by

                  I am trying to open Google Authenticator for 2FA - I want to send them there and then when they return I would fill a prompt with clipboard.get() - so in this case a webview doesn't really help me.

                  (To keep my script running I could use console.set_idle_timer_disabled(flag) like cclaus has shown.)

                  1 Reply Last reply Reply Quote 0
                  • ccc
                    ccc last edited by

                    The idea in NoDoze.py is that you setup a notification to wake yourself back up just before you shut yourself down. An interesting departure point. ;-)

                    1 Reply Last reply Reply Quote 0
                    • Sebastian
                      Sebastian last edited by

                      @JonB I started working on something like that a while ago. I got history and bookmarks working as well. I don't really know how to get tabs working though.

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by

                        @hyshai It looks like this might do it....

                        import ui, scene
                        
                        def AmIBack():
                        	global gbGone
                        	if gbGone and not sv.paused:
                        		gbGone = False
                        		print "Back here"
                        	else:
                        		if sv.paused:
                        			gbGone = True
                        		ui.delay(AmIBack, 1)
                        		
                        gbGone = False
                        v = ui.View()
                        sv = scene.SceneView()
                        sv.hidden = True
                        v.add_subview(sv)
                        v.present('panel')
                        AmIBack()
                        

                        Edit: no need to set the scene... just SceneView will do

                        1 Reply Last reply Reply Quote 0
                        • JonB
                          JonB last edited by

                          @sebastian. Post to github, others will contrib.

                          @hyshai. Ok, you originally said you wanted to open safari, not that you wanted to launch the authenticator app. Presumably you want to open a page which has an otpauth:// URI

                          See this.
                          Seems like you could create your own implementation in python, no external app required... After all, google authenticator is open source.
                          You could implement the custom uri handler for this in webview, and even autofill it, or have a little counter on the page showing the code in real time.

                          1 Reply Last reply Reply Quote 0
                          • userista
                            userista last edited by

                            @JonB ah sorry - just was trying to give a trivial example. But that's a great idea - though it's more work ;)

                            @tony hmm gonna try that - looks good

                            1 Reply Last reply Reply Quote 0
                            • userista
                              userista last edited by

                              @JonB - I just realized that you were giving me a solution for the opposite problem - I wasn't clear, my bad. I want for them to get the 2FA token so that they can login to their account. So implementing my own Google Authenticator app isn't a great solution because then I would have to store their secret in order to generate the token each time - and that's way too scary for me.

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              Powered by NodeBB Forums | Contributors