def createApp(appdef, folder, forPreview, progress):
    # save to global __appdef to patch a PyPubSub limitation that does not allow
    # to register a lambda function as listener (weak reference is unregistered
    # as soon the lambda is out of scope)
    global __appdef
    __appdef = appdef

    viewer.shutdown()
    pub.subscribe(endWriteWebAppListener, utils.topics.endWriteWebApp)
    try:
        writeWebApp(appdef, folder, forPreview, progress)
    except Exception as ex:
        endWriteWebAppListener(False, traceback.format_exc())
def createApp(appdef, deployData, folder, forPreview, progress):
	viewer.shutdown()
	if deployData:
		usesGeoServer = False
		usesPostgis = False
		layers = appdef["Layers"]
		for layer in layers:
			if layer.method in [METHOD_WFS_POSTGIS, METHOD_WMS_POSTGIS]:
				usesPostgis = True
				usesGeoServer = True
			elif layer.method in [METHOD_WFS, METHOD_WMS]:
				usesGeoServer = True
		if usesPostgis:
			importPostgis(appdef, progress)
		if usesGeoServer:
			publishGeoserver(appdef, progress)
	writeWebApp(appdef, folder, deployData, forPreview, progress)

	projFile = QgsProject.instance().fileName()
	if projFile:
		appdefFile =  projFile + ".appdef"
		saveAppdef(appdef, appdefFile)