Added support for portable apps

This commit is contained in:
RemixDev 2020-05-26 12:16:07 +02:00
parent 68039365e8
commit c7a504f479
2 changed files with 19 additions and 15 deletions

View File

@ -13,13 +13,16 @@ import deemix.utils.localpaths as localpaths
settings = {} settings = {}
defaultSettings = {} defaultSettings = {}
configDir = ""
def initSettings(localFolder = False, configFolder = None):
def initSettings(localFolder = False):
global settings global settings
global defaultSettings global defaultSettings
global configDir
currentFolder = path.abspath(path.dirname(__file__)) currentFolder = path.abspath(path.dirname(__file__))
configFolder = localpaths.getConfigFolder() if not configFolder:
configFolder = localpaths.getConfigFolder()
configDir = configFolder
makedirs(configFolder, exist_ok=True) makedirs(configFolder, exist_ok=True)
with open(path.join(currentFolder, 'default.json'), 'r') as d: with open(path.join(currentFolder, 'default.json'), 'r') as d:
defaultSettings = json.load(d) defaultSettings = json.load(d)
@ -54,7 +57,7 @@ def getDefaultSettings():
def saveSettings(newSettings): def saveSettings(newSettings):
global settings global settings
settings = newSettings settings = newSettings
with open(path.join(localpaths.getConfigFolder(), 'config.json'), 'w') as configFile: with open(path.join(configDir, 'config.json'), 'w') as configFile:
json.dump(settings, configFile, indent=2) json.dump(settings, configFile, indent=2)
return True return True

View File

@ -5,15 +5,18 @@ from os import mkdir
import spotipy import spotipy
from spotipy.oauth2 import SpotifyClientCredentials from spotipy.oauth2 import SpotifyClientCredentials
from deemix.utils.localpaths import getConfigFolder
import deemix.utils.localpaths as localpaths
class SpotifyHelper: class SpotifyHelper:
def __init__(self): def __init__(self, configFolder=None):
self.credentials = {} self.credentials = {}
self.spotifyEnabled = False self.spotifyEnabled = False
self.sp = None self.sp = None
if not configFolder:
self.configFolder = getConfigFolder()
else:
self.configFolder = configFolder
self.emptyPlaylist = { self.emptyPlaylist = {
'collaborative': False, 'collaborative': False,
'description': "", 'description': "",
@ -34,13 +37,12 @@ class SpotifyHelper:
self.initCredentials() self.initCredentials()
def initCredentials(self): def initCredentials(self):
configFolder = localpaths.getConfigFolder() if not path.isdir(self.configFolder):
if not path.isdir(configFolder): mkdir(self.configFolder)
mkdir(configFolder) if not path.isfile(path.join(self.configFolder, 'authCredentials.json')):
if not path.isfile(path.join(configFolder, 'authCredentials.json')): with open(path.join(self.configFolder, 'authCredentials.json'), 'w') as f:
with open(path.join(configFolder, 'authCredentials.json'), 'w') as f:
json.dump({'clientId': "", 'clientSecret': ""}, f, indent=2) json.dump({'clientId': "", 'clientSecret': ""}, f, indent=2)
with open(path.join(configFolder, 'authCredentials.json'), 'r') as credentialsFile: with open(path.join(self.configFolder, 'authCredentials.json'), 'r') as credentialsFile:
self.credentials = json.load(credentialsFile) self.credentials = json.load(credentialsFile)
self.checkCredentials() self.checkCredentials()
@ -60,8 +62,7 @@ class SpotifyHelper:
return self.credentials return self.credentials
def setCredentials(self, spotifyCredentials): def setCredentials(self, spotifyCredentials):
configFolder = localpaths.getConfigFolder() with open(path.join(self.configFolder, 'authCredentials.json'), 'w') as f:
with open(path.join(configFolder, 'authCredentials.json'), 'w') as f:
json.dump(spotifyCredentials, f, indent=2) json.dump(spotifyCredentials, f, indent=2)
self.credentials = spotifyCredentials self.credentials = spotifyCredentials
self.checkCredentials() self.checkCredentials()