Skip to content

Commit

Permalink
Get your IP from menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Bytezz committed Oct 31, 2023
1 parent 3660089 commit 89427c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ipapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import json
import sys
from urllib.request import urlopen
from urllib.request import urlopen, Request
import socket

def internet_available():
Expand All @@ -41,3 +41,6 @@ def get_ip_info(ip):
result = json.loads(urlopen("http://ip-api.com/json/{}".format(ip)).read())

return result

def get_your_ip():
return urlopen(Request("https://ifconfig.io", headers={"User-Agent":"curl"})).read().decode("utf-8").strip()
7 changes: 7 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
flags=Gio.ApplicationFlags.FLAGS_NONE)
self.create_action('quit', self.on_quit_action, ['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('get-your-ip', self.on_get_your_ip_action)

def do_activate(self):
"""Called when the application is activated.
Expand Down Expand Up @@ -68,6 +69,12 @@ def on_about_action(self, widget, _):
copyright='Copyright© 2023 Bytez')
about.present()

def on_get_your_ip_action(self, widget, _):
self.win.ip_entry.set_text(ipapi.get_your_ip())
self.win.ip_entry.grab_focus()
self.win.ip_entry.set_position(-1)
self.on_search(self)

def on_search(self, widget):
# TODO: Call deferred
# TODO: Show an osd GtkProgressBar
Expand Down
6 changes: 6 additions & 0 deletions src/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
</child>
</template>
<menu id="primary_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Get Your IP</attribute>
<attribute name="action">app.get-your-ip</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
Expand Down

0 comments on commit 89427c1

Please sign in to comment.