Skip to content

Commit

Permalink
Automatically check for updates and minor enhancements
Browse files Browse the repository at this point in the history
- web app checks an api to see if there is a new version of Scanbot available. if there is, notify the user on the home screen
- remove unused whitelist so warnings about it stop showing up
  • Loading branch information
ceds92 committed Jun 28, 2024
1 parent 2e245fa commit 3599148
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scanbot"
version = "4.4.2"
version = "4.5.0"
description = "Collection of automated STM and nc-AFM commands compatible with Nanonis V5 SPM Controller"
authors = ["Julian Ceddia <jdceddia@gmail.com>"]
readme = "README.md"
Expand Down
8 changes: 8 additions & 0 deletions scanbot/App/src/Scanbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./styles/Scanbot.css";
function Scanbot() {
const [configFound, setConfigFound] = useState(true)
const [isConnected, setIsConnected] = useState(true)
const [is2Update, setIsUp2date] = useState(true)

const CardRow = () => (
<div className="card-row">
Expand All @@ -24,10 +25,16 @@ function Scanbot() {
const hasConnection = await getResponse('/test_connection')
setIsConnected(hasConnection)
}

const checkUpdates = async () => {
const isUpdated = await getResponse('/check_updates')
setIsUp2date(isUpdated)
}

useEffect(() => {
checkConfig()
testConnection()
checkUpdates()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand All @@ -39,6 +46,7 @@ function Scanbot() {
</header>
{isConnected ? <div/> : <p className='config-warning'><strong>Warning:</strong> Could not connect to Nanonis. Please check configured IP and ports and make sure Nanonis V5 is running.</p>}
{configFound ? <div/> : <p className='config-warning'><strong>Warning:</strong> A configuration file has not been found - using default parameters. Accept configuration to remove this warning.</p>}
{is2Update ? <div/> : <p className='config-warning'>A newer version of Scanbot is available.</p>}
<div className="scanbot-body">
<CardRow />
</div>
Expand Down
37 changes: 1 addition & 36 deletions scanbot/server/scanbot_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ def loadConfig(self):
from hk_commands import hk_commands
self.hk_commands = hk_commands(self)

self.loadWhitelist()

def firebaseInit(self):
try:
import firebase_admin
Expand All @@ -192,16 +190,6 @@ def firebaseInit(self):
print("Firebase not initialised...")
print(e)

def loadWhitelist(self):
self.whitelist = []
try:
print("Loading whitelist.txt...")
with open('whitelist.txt', 'r') as f:
d = f.read()
self.whitelist = d.split('\n')[:-1]
except:
print('No whitelist found... create one with add_user')

def initGlobals(self):
global_.tasks = []
global_.running = threading.Event() # event to stop threads
Expand All @@ -217,8 +205,6 @@ def initCommandDict(self):
'get_portlist' : lambda args: self.portList, # Return the list of ports scanbot is configured to use
'set_upload_method': self.setUploadMethod, # Set which upload method to use when uploading pngs
'get_upload_method': lambda args: self.uploadMethod, # View the upload method
'add_user' : self.addUser, # Add a user to the whitelist (by email - zulip only)
'get_users' : lambda args: str(self.whitelist), # Get the list of users allowed to talk to scanbot (zulip only)
'set_path' : self.setPath, # Changes the directory pngs are saved in. Creates the directory if it doesn't exist.
'get_path' : lambda args: self.path, # Path to save scan pngs (saves the channel of focus which can be set using plot_channel)
'plot_channel' : self.plotChannel, # Read/select the current channel of focus
Expand Down Expand Up @@ -627,22 +613,6 @@ def setUploadMethod(self,uploadMethod,_help=False):
self.uploadMethod = uploadMethod
self.reactToMessage('all_good')

def addUser(self,user,_help=False):
arg_dict = {'' : ['', 0, "(string) Add user email to whitelist (one at a time)"]}

if(_help): return arg_dict

if(len(user) != 1): self.reactToMessage("cross_mark"); return
if(' ' in user[0]): self.reactToMessage("cross_mark"); return # Replace this with proper email validation
try:
self.whitelist.append(user[0])
with open('whitelist.txt', 'w') as f:
for w in self.whitelist:
f.write(w+'\n')
self.reactToMessage('all_good')
except Exception as e:
return str(e)

def setPath(self,path,_help=False):
arg_dict = {'' : ['', 0, "(string) Sets upload path. Creates the directory if path does not exist"]}

Expand Down Expand Up @@ -729,12 +699,7 @@ def handle_message(self, message, bot_handler=None):
messageContent = message
self.bot_message = []
self.bot_handler = bot_handler
if(bot_handler): # If there's a bot_handler, we're communicating via zulip
if message['sender_email'] not in self.whitelist and self.whitelist:
self.sendReply(message['sender_email'])
self.sendReply('access denied')
return

if(bot_handler): # If there's a bot_handler, we're communicating via zulip
self.bot_message = message
messageContent = message['content']

Expand Down
28 changes: 26 additions & 2 deletions scanbot/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
import pickle
import webbrowser
from threading import Timer
import urllib.request
import json

run_mode = 'react'

# To create the .exe follow these steps:
# pip install pyinstaller
# Comment out the below ARGS section
# Run the following command from /scanbot/server:
# pyinstaller --onefile --icon=..\App\public\favicon.ico --add-data "..\App\build;static" --name scanbot_v4.4.3 server.py
# pyinstaller --onefile --icon=..\App\public\favicon.ico --add-data "..\App\build;static" --name scanbot_v4.5.0 server.py

################# ARGS ##################
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--version', action='version', version='scanbot 4.4.3', help='show the version number and exit')
parser.add_argument('--version', action='version', version='scanbot 4.5.0', help='show the version number and exit')
parser.add_argument('-c', '--terminal', action='store_true', help='run scanbot in terminal')
parser.add_argument('-z', '--zulip', action='store_true', help='run scanbot in terminal')
args = parser.parse_args()
Expand Down Expand Up @@ -342,6 +344,28 @@ def getDir(path):
def open_browser():
webbrowser.open_new('http://127.0.0.1:5000/')

def getLatestVersion(url):
try:
with urllib.request.urlopen(url) as response:
data = json.loads(response.read().decode())
version = data.get('version')
return version
except:
return '0.0.0'

@app.route('/check_updates')
def check_updates():
currentVersion = '4.5.0'
latestVersion = getLatestVersion('https://us-central1-scanbot-46390.cloudfunctions.net/getVersion')

update = False
for n,v in enumerate(currentVersion.split('.')):
if(int(latestVersion.split('.')[n]) > int(v)):
update = True
break

return {"status": not update}, 200

# Running app
if __name__ == '__main__':
Timer(1, open_browser).start()
Expand Down

0 comments on commit 3599148

Please sign in to comment.