Skip to content

Commit

Permalink
close ##116
Browse files Browse the repository at this point in the history
  • Loading branch information
rllola committed Sep 24, 2019
1 parent 3ea96a8 commit 5905020
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
35 changes: 35 additions & 0 deletions launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,34 @@
from PyQt5.QtCore import QLibraryInfo, QCoreApplication
from PyQt5.QtWidgets import QApplication
from src.MainWindow import MainWindow
from src.version import VERSION
from src.UpdateNotification import UpdateNotification
from multiprocessing import Process, freeze_support

import time
import imp

# version1 > version2 --> True (outdated)
# Else --> False
def compare_version(version1, version2):
version1 = version1.split('.')
version2 = version2.split('.')

if version1[0] > version2[0]:
return True
elif version2[0] > version1[0]:
return False
elif version1[1] > version2[1]:
return True
elif version2[1] > version1[1]:
return False
elif version1[2] > version2[2]:
return True
elif version2[2] > version1[2]:
return False
else:
return False

def osx_first_run():
zeronet_browser_path = os.path.join(os.path.expanduser("~"), "Library", "Application Support", "Zeronet Browser")

Expand Down Expand Up @@ -103,6 +126,7 @@ def openLocked(path, mode="wb"):
use_internal_zeronet = config.getboolean('global', 'use_internal_zeronet', fallback=True)
zeronet_base_url = config.get('global', 'zeronet_base_url', fallback="http://127.0.0.1:43110")
zeronet_base_url = zeronet_base_url.rstrip("/")
auto_update = config.get('browser', 'auto_update', fallback=True)

if use_internal_zeronet:
from ZeroNet import zeronet
Expand Down Expand Up @@ -137,6 +161,17 @@ def openLocked(path, mode="wb"):
# Start the PyQt application
app = QApplication(sys.argv)
mainWindow = MainWindow(**kwargs)

if auto_update and sys.platform.startswith('linux'):
import requests
r = requests.get('https://api.update.rocks/update/github.com/rllola/ZeronetBrowser/stable/linux/{}'.format(VERSION))
response = r.json()
latest_version = response['url'].split('/')[-2][1:]
outdated = compare_version(latest_version, VERSION)
if outdated:
update_dialog = UpdateNotification(response['url'])
update_dialog.open()

app.exec_()

if p:
Expand Down
22 changes: 22 additions & 0 deletions src/UpdateNotification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from PyQt5.QtWidgets import QDialog, QGridLayout, QLabel
from PyQt5.QtCore import Qt

class UpdateNotification(QDialog):

def __init__(self, url):
super(QDialog,self).__init__()

self.url = url
self.setWindowTitle("Update!")
self.layout = QGridLayout(self)
label = QLabel("New update available. You download it here : <br/> <a href='{}'>New Release!</a>".format(self.url))
label.setTextFormat(Qt.RichText)
label.linkActivated.connect(self.link_update_clicked)
self.layout.addWidget(label)



def link_update_clicked(self, link):
import webbrowser
webbrowser.open(link)
self.close()
1 change: 1 addition & 0 deletions src/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = '0.0.0'

0 comments on commit 5905020

Please sign in to comment.