 		RocketChat.settings.add "Assets_#{key}", {defaultUrl: value.defaultUrl}, { type: 'asset', group: 'Assets', fileConstraints: value.constraints, i18nLabel: value.label, asset: key, public: true }
 
 
-forEachAsset = (key, value) ->
-	RocketChat.settings.get "Assets_#{key}", (settingKey, settingValue) ->
-		if not settingValue?.url?
-			value.cache = undefined
-			return
-
-		file = RocketChatAssetsInstance.getFileWithReadStream key
-		if not file
-			value.cache = undefined
-			return
-
-		data = []
-		file.readStream.on 'data', Meteor.bindEnvironment (chunk) ->
-			data.push chunk
-
-		file.readStream.on 'end', Meteor.bindEnvironment ->
-			data = Buffer.concat(data)
-			hash = crypto.createHash('sha1').update(data).digest('hex')
-			extension = settingValue.url.split('.').pop()
-			value.cache =
-				path: "assets/#{key}.#{extension}"
-				cacheable: false
-				sourceMapUrl: undefined
-				where: 'client'
-				type: 'asset'
-				content: data
-				extension: extension
-				url: "/assets/#{key}.#{extension}?#{hash}"
-				size: file.length
-				uploadDate: file.uploadDate
-				contentType: file.contentType
-				hash: hash
-
-
-forEachAsset(key, value) for key, value of assets
+RocketChat.models.Settings.find().observe
+	added: (record) ->
+		RocketChat.Assets.processAsset record._id, record.value
+	changed: (record) ->
+		RocketChat.Assets.processAsset record._id, record.value
+	removed: (record) ->
+		RocketChat.Assets.processAsset record._id, undefined
+
+Meteor.startup ->
+	Meteor.setTimeout ->
+		process.emit('message', {refresh: 'client'})
+	, 200
 
 calculateClientHash = WebAppHashing.calculateClientHash
 WebAppHashing.calculateClientHash = (manifest, includeFilter, runtimeConfigOverride) ->
 	for key, value of assets
 		if not value.cache? && not value.defaultUrl?
 			continue
-
-		manifestItem = _.find manifest, (item) ->
-			return item.path is key
 
 		cache = {}
 		if value.cache

			WebAppInternals.staticFiles["/__cordova/assets/#{key}"] = WebAppInternals.staticFiles["/__cordova/#{value.defaultUrl}"]
			WebAppInternals.staticFiles["/__cordova/assets/#{key}.#{extension}"] = WebAppInternals.staticFiles["/__cordova/#{value.defaultUrl}"]


		if manifestItem?
			index = manifest.indexOf(manifestItem)

		ws = RocketChatAssetsInstance.createWriteStream asset, contentType
		ws.on 'end', Meteor.bindEnvironment ->
			Meteor.setTimeout ->
				key = "Assets_#{asset}"
				value = {
					url: "assets/#{asset}.#{extension}"
					defaultUrl: assets[asset].defaultUrl
				}
				RocketChat.settings.updateById key, value
				RocketChat.Assets.processAsset key, value
			, 200

		rs.pipe ws
