mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2024-12-29 10:56:06 +00:00
Implemented --portable option
This commit is contained in:
parent
38cd03ca29
commit
accabdf4dc
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -25,5 +25,7 @@ yarn-error.log*
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
# Private configs
|
# Development stuff
|
||||||
/config.py
|
/config.py
|
||||||
|
deemix
|
||||||
|
config
|
||||||
|
|
22
app.py
22
app.py
|
@ -12,24 +12,31 @@ from os import remove
|
||||||
settings = {}
|
settings = {}
|
||||||
spotifyHelper = None
|
spotifyHelper = None
|
||||||
chartsList = []
|
chartsList = []
|
||||||
|
configFolder = ""
|
||||||
|
|
||||||
|
|
||||||
def initialize():
|
def initialize(portable):
|
||||||
global settings
|
global settings
|
||||||
global spotifyHelper
|
global spotifyHelper
|
||||||
global defaultSettings
|
global defaultSettings
|
||||||
settings = initSettings()
|
global configFolder
|
||||||
|
if portable:
|
||||||
|
configFolder = portable
|
||||||
|
else:
|
||||||
|
configFolder = getConfigFolder()
|
||||||
|
settings = initSettings(configFolder=configFolder)
|
||||||
defaultSettings = getDefaultSettings()
|
defaultSettings = getDefaultSettings()
|
||||||
spotifyHelper = SpotifyHelper()
|
spotifyHelper = SpotifyHelper(configFolder=configFolder)
|
||||||
|
|
||||||
|
|
||||||
def shutdown(interface=None):
|
def shutdown(interface=None):
|
||||||
|
global configFolder
|
||||||
if settings['saveDownloadQueue']:
|
if settings['saveDownloadQueue']:
|
||||||
(queue, queueComplete, queueList, currentItem) = getQueue()
|
(queue, queueComplete, queueList, currentItem) = getQueue()
|
||||||
if len(queueList) > 0:
|
if len(queueList) > 0:
|
||||||
if currentItem != "":
|
if currentItem != "":
|
||||||
queue.insert(0, currentItem)
|
queue.insert(0, currentItem)
|
||||||
with open(path.join(getConfigFolder(), 'queue.json'), 'w') as f:
|
with open(path.join(configFolder, 'queue.json'), 'w') as f:
|
||||||
json.dump({
|
json.dump({
|
||||||
'queue': queue,
|
'queue': queue,
|
||||||
'queueComplete': queueComplete,
|
'queueComplete': queueComplete,
|
||||||
|
@ -40,11 +47,12 @@ def shutdown(interface=None):
|
||||||
interface.send("toast", {'msg': "Server is closed."})
|
interface.send("toast", {'msg': "Server is closed."})
|
||||||
|
|
||||||
def loadDownloadQueue(dz, interface=None):
|
def loadDownloadQueue(dz, interface=None):
|
||||||
if path.isfile(path.join(getConfigFolder(), 'queue.json')):
|
global configFolder
|
||||||
|
if path.isfile(path.join(configFolder, 'queue.json')):
|
||||||
if interface:
|
if interface:
|
||||||
interface.send('toast', {'msg': "Restoring download queue", 'icon': 'loading', 'dismiss': False,
|
interface.send('toast', {'msg': "Restoring download queue", 'icon': 'loading', 'dismiss': False,
|
||||||
'id': 'restoring_queue'})
|
'id': 'restoring_queue'})
|
||||||
with open(path.join(getConfigFolder(), 'queue.json'), 'r') as f:
|
with open(path.join(configFolder, 'queue.json'), 'r') as f:
|
||||||
qd = json.load(f)
|
qd = json.load(f)
|
||||||
if interface:
|
if interface:
|
||||||
interface.send('init_downloadQueue',
|
interface.send('init_downloadQueue',
|
||||||
|
@ -52,7 +60,7 @@ def loadDownloadQueue(dz, interface=None):
|
||||||
if interface:
|
if interface:
|
||||||
interface.send('toast', {'msg': "Download queue restored!", 'icon': 'done', 'dismiss': True,
|
interface.send('toast', {'msg': "Download queue restored!", 'icon': 'done', 'dismiss': True,
|
||||||
'id': 'restoring_queue'})
|
'id': 'restoring_queue'})
|
||||||
remove(path.join(getConfigFolder(), 'queue.json'))
|
remove(path.join(configFolder, 'queue.json'))
|
||||||
restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], dz, interface)
|
restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], dz, interface)
|
||||||
|
|
||||||
def getDownloadFolder():
|
def getDownloadFolder():
|
||||||
|
|
|
@ -32,16 +32,25 @@ def save_position():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
url = "127.0.0.1"
|
url = "127.0.0.1"
|
||||||
if len(sys.argv) >= 2:
|
|
||||||
port = int(sys.argv[1])
|
|
||||||
else:
|
|
||||||
port = 9666
|
port = 9666
|
||||||
t = Thread(target=run_server, args=(port, ))
|
if len(sys.argv) >= 2:
|
||||||
|
try:
|
||||||
|
port = int(sys.argv[1])
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
if '--portable' in sys.argv:
|
||||||
|
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
||||||
|
else:
|
||||||
|
portable = None
|
||||||
|
t = Thread(target=run_server, args=(port, portable))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
while not url_ok(url, port):
|
while not url_ok(url, port):
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
if portable:
|
||||||
|
configFolder = portable
|
||||||
|
else:
|
||||||
configFolder = getConfigFolder()
|
configFolder = getConfigFolder()
|
||||||
|
|
||||||
if path.isfile(path.join(configFolder, '.UIposition')):
|
if path.isfile(path.join(configFolder, '.UIposition')):
|
||||||
|
|
14
server.py
14
server.py
|
@ -10,7 +10,6 @@ from flask_socketio import SocketIO, emit
|
||||||
import app
|
import app
|
||||||
from deemix.api.deezer import Deezer
|
from deemix.api.deezer import Deezer
|
||||||
from deemix.app.MessageInterface import MessageInterface
|
from deemix.app.MessageInterface import MessageInterface
|
||||||
from deemix.utils import localpaths
|
|
||||||
|
|
||||||
# Workaround for MIME type error in certain Windows installs
|
# Workaround for MIME type error in certain Windows installs
|
||||||
# https://github.com/pallets/flask/issues/1045#issuecomment-42202749
|
# https://github.com/pallets/flask/issues/1045#issuecomment-42202749
|
||||||
|
@ -65,10 +64,8 @@ logging.getLogger('socketio').setLevel(logging.ERROR)
|
||||||
logging.getLogger('engineio').setLevel(logging.ERROR)
|
logging.getLogger('engineio').setLevel(logging.ERROR)
|
||||||
#server.logger.disabled = True
|
#server.logger.disabled = True
|
||||||
|
|
||||||
app.initialize()
|
|
||||||
firstConnection = True
|
firstConnection = True
|
||||||
|
|
||||||
|
|
||||||
@server.route('/')
|
@server.route('/')
|
||||||
def landing():
|
def landing():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
@ -93,7 +90,7 @@ def on_connect():
|
||||||
emit('init_settings', (settings, spotifyCredentials, defaultSettings))
|
emit('init_settings', (settings, spotifyCredentials, defaultSettings))
|
||||||
emit('init_autologin')
|
emit('init_autologin')
|
||||||
|
|
||||||
arl_file_path = path.join(localpaths.getConfigFolder(), '.arl')
|
arl_file_path = path.join(app.configFolder, '.arl')
|
||||||
if serverwide_arl and path.isfile(arl_file_path):
|
if serverwide_arl and path.isfile(arl_file_path):
|
||||||
with open(arl_file_path, 'r') as file:
|
with open(arl_file_path, 'r') as file:
|
||||||
arl = file.readline().rstrip("\n")
|
arl = file.readline().rstrip("\n")
|
||||||
|
@ -260,7 +257,8 @@ def openDownloadsFolder():
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
subprocess.check_call(['explorer', folder])
|
subprocess.check_call(['explorer', folder])
|
||||||
|
|
||||||
def run_server(port):
|
def run_server(port, portable=None):
|
||||||
|
app.initialize(portable)
|
||||||
print("Starting server at http://127.0.0.1:" + str(port))
|
print("Starting server at http://127.0.0.1:" + str(port))
|
||||||
socketio.run(server, host='0.0.0.0', port=port)
|
socketio.run(server, host='0.0.0.0', port=port)
|
||||||
|
|
||||||
|
@ -272,4 +270,8 @@ if __name__ == '__main__':
|
||||||
port = int(sys.argv[1])
|
port = int(sys.argv[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
run_server(port)
|
if '--portable' in sys.argv:
|
||||||
|
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
||||||
|
else:
|
||||||
|
portable = None
|
||||||
|
run_server(port, portable)
|
||||||
|
|
Loading…
Reference in a new issue