mirror of
https://gitlab.com/RemixDev/deemix-gui-pyweb.git
synced 2024-12-28 02:16:16 +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
|
||||
*.sw?
|
||||
|
||||
# Private configs
|
||||
# Development stuff
|
||||
/config.py
|
||||
deemix
|
||||
config
|
||||
|
|
22
app.py
22
app.py
|
@ -12,24 +12,31 @@ from os import remove
|
|||
settings = {}
|
||||
spotifyHelper = None
|
||||
chartsList = []
|
||||
configFolder = ""
|
||||
|
||||
|
||||
def initialize():
|
||||
def initialize(portable):
|
||||
global settings
|
||||
global spotifyHelper
|
||||
global defaultSettings
|
||||
settings = initSettings()
|
||||
global configFolder
|
||||
if portable:
|
||||
configFolder = portable
|
||||
else:
|
||||
configFolder = getConfigFolder()
|
||||
settings = initSettings(configFolder=configFolder)
|
||||
defaultSettings = getDefaultSettings()
|
||||
spotifyHelper = SpotifyHelper()
|
||||
spotifyHelper = SpotifyHelper(configFolder=configFolder)
|
||||
|
||||
|
||||
def shutdown(interface=None):
|
||||
global configFolder
|
||||
if settings['saveDownloadQueue']:
|
||||
(queue, queueComplete, queueList, currentItem) = getQueue()
|
||||
if len(queueList) > 0:
|
||||
if 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({
|
||||
'queue': queue,
|
||||
'queueComplete': queueComplete,
|
||||
|
@ -40,11 +47,12 @@ def shutdown(interface=None):
|
|||
interface.send("toast", {'msg': "Server is closed."})
|
||||
|
||||
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:
|
||||
interface.send('toast', {'msg': "Restoring download queue", 'icon': 'loading', 'dismiss': False,
|
||||
'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)
|
||||
if interface:
|
||||
interface.send('init_downloadQueue',
|
||||
|
@ -52,7 +60,7 @@ def loadDownloadQueue(dz, interface=None):
|
|||
if interface:
|
||||
interface.send('toast', {'msg': "Download queue restored!", 'icon': 'done', 'dismiss': True,
|
||||
'id': 'restoring_queue'})
|
||||
remove(path.join(getConfigFolder(), 'queue.json'))
|
||||
remove(path.join(configFolder, 'queue.json'))
|
||||
restoreQueue(qd['queue'], qd['queueComplete'], qd['queueList'], dz, interface)
|
||||
|
||||
def getDownloadFolder():
|
||||
|
|
|
@ -32,17 +32,26 @@ def save_position():
|
|||
|
||||
if __name__ == '__main__':
|
||||
url = "127.0.0.1"
|
||||
port = 9666
|
||||
if len(sys.argv) >= 2:
|
||||
port = int(sys.argv[1])
|
||||
try:
|
||||
port = int(sys.argv[1])
|
||||
except ValueError:
|
||||
pass
|
||||
if '--portable' in sys.argv:
|
||||
portable = path.join(path.dirname(path.realpath(__file__)), 'config')
|
||||
else:
|
||||
port = 9666
|
||||
t = Thread(target=run_server, args=(port, ))
|
||||
portable = None
|
||||
t = Thread(target=run_server, args=(port, portable))
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
while not url_ok(url, port):
|
||||
sleep(1)
|
||||
configFolder = getConfigFolder()
|
||||
if portable:
|
||||
configFolder = portable
|
||||
else:
|
||||
configFolder = getConfigFolder()
|
||||
|
||||
if path.isfile(path.join(configFolder, '.UIposition')):
|
||||
try:
|
||||
|
|
14
server.py
14
server.py
|
@ -10,7 +10,6 @@ from flask_socketio import SocketIO, emit
|
|||
import app
|
||||
from deemix.api.deezer import Deezer
|
||||
from deemix.app.MessageInterface import MessageInterface
|
||||
from deemix.utils import localpaths
|
||||
|
||||
# Workaround for MIME type error in certain Windows installs
|
||||
# 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)
|
||||
#server.logger.disabled = True
|
||||
|
||||
app.initialize()
|
||||
firstConnection = True
|
||||
|
||||
|
||||
@server.route('/')
|
||||
def landing():
|
||||
return render_template('index.html')
|
||||
|
@ -93,7 +90,7 @@ def on_connect():
|
|||
emit('init_settings', (settings, spotifyCredentials, defaultSettings))
|
||||
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):
|
||||
with open(arl_file_path, 'r') as file:
|
||||
arl = file.readline().rstrip("\n")
|
||||
|
@ -260,7 +257,8 @@ def openDownloadsFolder():
|
|||
elif sys.platform == 'win32':
|
||||
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))
|
||||
socketio.run(server, host='0.0.0.0', port=port)
|
||||
|
||||
|
@ -272,4 +270,8 @@ if __name__ == '__main__':
|
|||
port = int(sys.argv[1])
|
||||
except ValueError:
|
||||
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