MCPcopy Index your code
hub / github.com/ajatkj/scriptable / updateLayout

Function updateLayout

LSWeather.js:689–808  ·  view source on GitHub ↗
(isNight, weatherID)

Source from the content-addressed store, hash-verified

687FUNCTION updateLayout
688------------------------------------------------------------------*/
689async function updateLayout(isNight, weatherID){
690 const coloredSFSymbols = ['wind','sunset','sunrise','cloud','sun','snow','tornado'];
691 const validLayouts = ['custom','welcome','minimalWeather','feelMotivated','minimalCalendar','showMyWork','maximalWeather'];
692 layoutName = validLayouts.includes(LAYOUT) ? LAYOUT : 'custom';
693 layout = eval(layoutName);
694 writeLOG("Using layout " + layoutName);
695 try {
696 const imageSize=DEVICE_RESOLUTION;
697 let TEMPERATURE_UNIT;
698 let SPEED_UNIT;
699 // set constants based on UNITS
700 if (WEATHER_UNITS == 'imperial'){
701 TEMPERATURE_UNIT = "°";
702 SPEED_UNIT = "mph";
703 } else if (WEATHER_UNITS == 'metric') {
704 TEMPERATURE_UNIT = "°";
705 SPEED_UNIT = "m/s";
706 } else { // when WEATHER_UNITS is not applied or "standard"
707 TEMPERATURE_UNIT = "°";
708 SPEED_UNIT = "m/s";
709 }
710 // loop through the layout dictionary and update necessary dynamic data
711 for (let item in layout){
712 // Hide elements if set
713 if (!CALENDAR_SHOW_CALENDARS && layout[item].source == 'calendar') layout[item].hide = 1;
714 if (!QUOTE_SHOW_QUOTES && layout[item].source == 'quote') layout[item].hide = 1;
715 if (!WEATHER_SHOW_WEATHER && layout[item].source == 'weather') layout[item].hide = 1;
716
717 // Evaluate width & height
718 layout[item].w = parseWidthHeight("w",layout[item].w);
719 layout[item].h = parseWidthHeight("h",layout[item].h);
720
721 // Evaluate x & y co-ordinates
722 layout[item].x = parseCoordinates("x",layout[item].w,layout[item].x);
723 layout[item].y = parseCoordinates("y",layout[item].h,layout[item].y);
724
725 // Evaluate suffix for temperature and speed units
726 if (layout[item].suffix == "temperature") layout[item].suffix = TEMPERATURE_UNIT;
727 else if (layout[item].suffix == "speed") layout[item].suffix = SPEED_UNIT;
728
729 // Evaluate color
730 if (layout[item].color == "light") {
731 if (!useDarkColor) layout[item].color = LIGHT_COLOR;
732 else layout[item].color = DARK_COLOR;
733 } else if (layout[item].color == "dark") {
734 if (!useDarkColor) layout[item].color = LIGHT_COLOR;
735 else layout[item].color = DARK_COLOR;
736 }
737
738 // Evaluate font
739 if (layout[item].font === null) {
740 layout[item].font = allfonts.default.font;
741 layout[item].size = allfonts.default.size;
742 layout[item].fontName = "default";
743 layout[item].bold = false;
744 }
745 else {
746 const fontName = (layout[item].font).split(".")[0];

Callers 1

LSWeather.jsFile · 0.85

Calls 4

parseWidthHeightFunction · 0.85
parseCoordinatesFunction · 0.85
writeLOGFunction · 0.70
getWeatherSymbolFunction · 0.70

Tested by

no test coverage detected