From c44d9fcaeb3e365a2cef62bbecfbc3f3806ddbb2 Mon Sep 17 00:00:00 2001 From: DotJoshJohnson Date: Tue, 8 Mar 2016 11:21:25 -0500 Subject: [PATCH] Dynamic Font Color #48 - Checks the storage.json file to set the XML Tree font color based on the theme type. DEfaults to #AAAAAA otherwise. --- src/services/XmlTreeService.ts | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/services/XmlTreeService.ts b/src/services/XmlTreeService.ts index 0b4e86f..f18c97b 100644 --- a/src/services/XmlTreeService.ts +++ b/src/services/XmlTreeService.ts @@ -1,10 +1,12 @@ 'use strict'; let DOMParser = require('xmldom').DOMParser; +let fs = require('fs'); export class XmlTreeService { static getXmlTreeHtml(xml: string): string { let xdoc: Document = new DOMParser().parseFromString(xml, 'text/xml'); + let fontColor: string = XmlTreeService._getRecommendedTextColor(); let html: string = ` @@ -22,7 +24,7 @@ export class XmlTreeService { } body { - color: #ffffff; + color: ${fontColor}; margin: 0; } @@ -74,7 +76,7 @@ export class XmlTreeService { li.xml a { background: url(document.png) 0 0 no-repeat; - color: #000; + color: ${fontColor}; padding-left: 21px; text-decoration: none; display: block; @@ -114,6 +116,7 @@ export class XmlTreeService { } li label { + color: ${fontColor}; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAYJJREFUOBFjYBjygJGQD1SmfNb+w8Sw8g8js/uTTK6n6OqZ0AXs/HfKIov9ZWKIANoi+OQl53Mb7y2CDqH7eZDlUQywD9qSxcj056ZT6GZpJEXhQANWMTQw/mNiY1j9/8+3dcZpZ1hh8nADHAO2BjP8Z5zMwPi/ZN9qX7BT5ad/NQQqVP3H8G8lSMP/f0x5QMqY9/WL+UAe2PtgAxwDt9n/Y2RYChRsPLjOZxpIMQgwM/yPYGBgfPAgi/8EiH94o9c1BoZ/Pv8ZGAMdArZ2g8TgLgBx0MH//wxhjIxA5+MBYAP2r/c6yPSfIRpoWz0oHEDqFaZ9tAC6SOEvA+MKmH5b/21aQDu3MDL8X39gg3cpSBzugv0bvNcC/Z8L9FoPKBCZGJjCgfK3H2Zyn4cZwMj0bxKQffazqEQi0LL/IHG4ASAOyP///7Go79P2eQ6UDQMKgQMPJAcC/34xhDKycAWdnWXyGyICNAbGQKZlpn+TZvn/dyfLP4bwOzm8V5HlhiEbAAAVeUhVveSUAAAAAElFTkSuQmCC) 15px 1px no-repeat; cursor: pointer; display: block; @@ -184,4 +187,36 @@ export class XmlTreeService { return html; } + + private static _getRecommendedTextColor(): string { + let color = '#AAAAAA'; + let path = ''; + + switch (process.platform) { + case 'darwin': + path = `${process.env.HOME}/Library/Application Support/Code/storage.json`; + break; + + case 'win32': + path = `${process.env.APPDATA}\\Code\\storage.json`; + break; + + default: + path = `${process.env.HOME}/.config/Code/storage.json` + break; + } + + try { + fs.accessSync(path); + + let json = fs.readFileSync(path, 'utf8'); + let storage = JSON.parse(json); + + color = (storage.theme.indexOf('vs-dark') > -1) ? '#FFFFFF' : '#000000'; + } + + catch (error) { } + + return color; + } } \ No newline at end of file