Skip to content

Commit 8bdd3bd

Browse files
authored
Merge pull request #57 from aicore/fs
Default Theme loading fixed
2 parents 917a23f + ff0e8de commit 8bdd3bd

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/extensions/default/DefaultExtensions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@
2727
"RecentProjects",
2828
"RemoteFileAdapter",
2929
"SVGCodeHints",
30-
"UrlCodeHints"
30+
"UrlCodeHints",
31+
"DarkTheme",
32+
"LightTheme"
3133
]

src/view/ThemeManager.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,64 @@ define(function (require, exports, module) {
270270
});
271271
}
272272

273+
/**
274+
*
275+
* @param file FileSystem.getFileForPath object
276+
* @param options
277+
* @private
278+
*/
279+
function _loadThemeFromFile(file, options) {
280+
var currentThemeName = prefs.get("theme");
281+
var theme = new Theme(file, options);
282+
loadedThemes[theme.name] = theme;
283+
ThemeSettings._setThemes(loadedThemes);
284+
285+
// For themes that are loaded after ThemeManager has been loaded,
286+
// we should check if it's the current theme. If it is, then we just
287+
// load it.
288+
if (currentThemeName === theme.name) {
289+
refresh(true);
290+
}
291+
}
292+
293+
/**
294+
* Loads a theme from a url.
295+
*
296+
* @param {string} url is the full hhtp/https url of the theme file
297+
* @param {Object} options is an optional parameter to specify metadata
298+
* for the theme.
299+
* @return {$.Promise} promise object resolved with the theme to be loaded from fileName
300+
*/
301+
function _loadFileFromURL(url, options) {
302+
var deferred = new $.Deferred();
303+
304+
var themeName = options.name || options.theme.title;
305+
var fileName = options.theme.file;
306+
var themePath = path.normalize(brackets.app.getApplicationSupportDirectory() + "/extensions/user/" +
307+
themeName + '_' + fileName);
308+
var file = FileSystem.getFileForPath(themePath);
309+
310+
file.exists(function (err, exists) {
311+
var theme;
312+
313+
if (exists) {
314+
_loadThemeFromFile(file, options);
315+
deferred.resolve(theme);
316+
return;
317+
}
318+
$.get(url).done(function (themeContent) {
319+
// Write theme to file
320+
FileUtils.writeText(file, themeContent).then(function () {
321+
_loadThemeFromFile(file, options);
322+
deferred.resolve(theme);
323+
}, deferred.reject);
324+
}).fail(function (err) {
325+
deferred.reject(err);
326+
});
327+
});
328+
329+
return deferred.promise();
330+
}
273331

274332
/**
275333
* Loads a theme from a file.
@@ -280,6 +338,10 @@ define(function (require, exports, module) {
280338
* @return {$.Promise} promise object resolved with the theme to be loaded from fileName
281339
*/
282340
function loadFile(fileName, options) {
341+
if(fileName.startsWith("http://") || fileName.startsWith("https://")) {
342+
return _loadFileFromURL(fileName, options);
343+
}
344+
283345
var deferred = new $.Deferred(),
284346
file = FileSystem.getFileForPath(fileName),
285347
currentThemeName = prefs.get("theme");

0 commit comments

Comments
 (0)