Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WEBUI: compress and optimize the default js/css files
- create Makefile.webui to kept all in one place
- fix various .js errors
- don't compress .jpg and .gif files
  • Loading branch information
perexg committed May 13, 2015
1 parent 6327e58 commit 4aca9be
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 132 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -2,6 +2,14 @@ build.*
.config.mk

src/version.c
src/webui/extjs-std.c
src/webui/extjs-debug.c
src/webui/extjs-tv-std.c
src/webui/extjs-tv-debug.c
src/webui/static/tvh.js.gz
src/webui/static/tvh-tv.css.gz
src/webui/static/tvh-tv.js.gz
src/webui/static/tvh.css.gz

data/dvb-scan

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Expand Up @@ -420,7 +420,7 @@ reconfigure:
$(ROOTDIR)/configure $(CONFIGURE_ARGS)

# Binary
${PROG}: check_config $(OBJS) $(ALLDEPS)
${PROG}: check_config make_webui $(OBJS) $(ALLDEPS)
$(CC) -o $@ $(OBJS) $(CFLAGS) $(LDFLAGS)

# Object
Expand All @@ -437,6 +437,7 @@ ${BUILDDIR}/%.so: ${SRCS_EXTRA}
clean:
rm -rf ${BUILDDIR}/src ${BUILDDIR}/bundle*
find . -name "*~" | xargs rm -f
$(MAKE) -f Makefile.webui clean

distclean: clean
rm -rf ${ROOTDIR}/libav_static
Expand All @@ -461,10 +462,14 @@ $(BUILDDIR)/bundle.o: $(BUILDDIR)/bundle.c
@mkdir -p $(dir $@)
$(CC) -I${ROOTDIR}/src -c -o $@ $<

$(BUILDDIR)/bundle.c: check_dvb_scan
$(BUILDDIR)/bundle.c: check_dvb_scan make_webui
@mkdir -p $(dir $@)
$(MKBUNDLE) -o $@ -d ${BUILDDIR}/bundle.d $(BUNDLE_FLAGS) $(BUNDLES:%=$(ROOTDIR)/%)

.PHONY: make_webui
make_webui:
$(MAKE) -f Makefile.webui all

# Static FFMPEG

ifeq ($(CONFIG_LIBFFMPEG_STATIC),yes)
Expand Down
221 changes: 221 additions & 0 deletions Makefile.webui
@@ -0,0 +1,221 @@
#
# Tvheadend WEBUI interface
# Copyright (C) 2015 Jaroslav Kysela
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

#
# Configuration
#

IAM=$(lastword $(MAKEFILE_LIST))
WEBDIR ?= src/webui
ROOTPATH = static

ifneq ($(WEBUI),)

TOPDIR=$(dir $(IAM))
include $(TOPDIR)/.config.mk
EXTJSPATH = $(ROOTPATH)/extjs
CSS_PY = support/css.py
RUN_JS = java -jar vendor/yui-compressor/yuicompressor-2.4.8.jar --type js
RUN_CSS = java -jar vendor/yui-compressor/yuicompressor-2.4.8.jar --type css
GZIP = gzip -n

ifeq ($(WEBUI),std)
DEBUG =
else
DEBUG = -debug
endif

JAVASCRIPT =
JAVASCRIPT2 =
JAVASCRIPT_TV =
CSS =
CSS_TV =

#
# base extjs files
#

JAVASCRIPT += $(EXTJSPATH)/adapter/ext/ext-base$(DEBUG).js
JAVASCRIPT += $(EXTJSPATH)/ext-all$(DEBUG).js

#
# CSS
#

CSS += $(EXTJSPATH)/resources/css/ext-all-notheme.css
CSS += $(EXTJSPATH)/resources/css/xtheme-blue.css
CSS += $(ROOTPATH)/livegrid/resources/css/ext-ux-livegrid.css
CSS += $(EXTJSPATH)/examples/ux/gridfilters/css/GridFilters.css
CSS += $(EXTJSPATH)/examples/ux/gridfilters/css/RangeMenu.css
CSS += static/xcheckbox/xcheckbox.css
CSS += static/app/ext.css

#
# extjs extensions
#

JAVASCRIPT += $(ROOTPATH)/app/extensions.js
JAVASCRIPT += $(ROOTPATH)/livegrid/livegrid-all.js
JAVASCRIPT += $(ROOTPATH)/lovcombo/lovcombo-all.js
JAVASCRIPT += $(ROOTPATH)/multiselect/multiselect.js
JAVASCRIPT += $(ROOTPATH)/multiselect/ddview.js
JAVASCRIPT += $(ROOTPATH)/xcheckbox/xcheckbox.js
JAVASCRIPT += $(ROOTPATH)/checkcolumn/CheckColumn.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/GridFilters.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/Filter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/BooleanFilter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/DateFilter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/ListFilter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/NumericFilter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/filter/StringFilter.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/menu/ListMenu.js
JAVASCRIPT += $(EXTJSPATH)/examples/ux/gridfilters/menu/RangeMenu.js

#
# app itself
#

JAVASCRIPT += $(ROOTPATH)/app/namespace.js
JAVASCRIPT += $(ROOTPATH)/smoothie.js
JAVASCRIPT += $(ROOTPATH)/app/comet.js
JAVASCRIPT += $(ROOTPATH)/app/tableeditor.js
JAVASCRIPT += $(ROOTPATH)/app/cteditor.js
JAVASCRIPT += $(ROOTPATH)/app/acleditor.js

CACLIENT-$(CONFIG_CWC) = yes
CACLIENT-$(CONFIG_CAPMT) = yes

ifeq ($(CACLIENT-yes), yes)
JAVASCRIPT += $(ROOTPATH)/app/caclient.js
endif

JAVASCRIPT += $(ROOTPATH)/app/tvadapters.js
JAVASCRIPT += $(ROOTPATH)/app/idnode.js
JAVASCRIPT += $(ROOTPATH)/app/esfilter.js
ifeq ($(CONFIG_MPEGTS), yes)
JAVASCRIPT += $(ROOTPATH)/app/mpegts.js
endif
ifeq ($(CONFIG_TIMESHIFT), yes)
JAVASCRIPT += $(ROOTPATH)/app/timeshift.js
endif
JAVASCRIPT += $(ROOTPATH)/app/chconf.js
JAVASCRIPT += $(ROOTPATH)/app/epg.js
JAVASCRIPT += $(ROOTPATH)/app/dvr.js
JAVASCRIPT += $(ROOTPATH)/app/epggrab.js
JAVASCRIPT += $(ROOTPATH)/app/config.js
JAVASCRIPT += $(ROOTPATH)/app/tvhlog.js
JAVASCRIPT += $(ROOTPATH)/app/status.js
JAVASCRIPT += $(ROOTPATH)/tv.js
JAVASCRIPT += $(ROOTPATH)/app/servicemapper.js

JAVASCRIPT += $(ROOTPATH)/app/tvheadend.js

#
# tv
#

CSS_TV += $(ROOTPATH)/tv.css
JAVASCRIPT_TV += $(EXTJSPATH)/adapter/ext/ext-base$(DEBUG).js
JAVASCRIPT_TV += $(EXTJSPATH)/ext-all$(DEBUG).js
JAVASCRIPT_TV += $(ROOTPATH)/tv.js

#
# real source paths
#

JAVASCRIPT_SRC = $(foreach f,$(JAVASCRIPT),$(WEBDIR)/$(f))
CSS_SRC = $(foreach f,$(CSS),$(WEBDIR)/$(f))
JAVASCRIPT_TV_SRC = $(foreach f,$(JAVASCRIPT_TV),$(WEBDIR)/$(f))
CSS_TV_SRC = $(foreach f,$(CSS_TV),$(WEBDIR)/$(f))

endif # WEBUI defined

ifndef V
VV = @
endif

define GO_JS
$(VV)cat $^ > $@.tmp
$(VV)$(RUN_JS) $@.tmp > $@.tmp2
@stat --printf="%-35n %7s\n" $@.tmp $@.tmp2
@$(GZIP) -c $@.tmp2 > $@.tmp
@rm $@.tmp2
@mv $@.tmp $@
@stat --printf="%-35n %7s\n" $@
endef

define GO_CSS
$(VV)$(CSS_PY) --in="$^" > $@.tmp
$(VV)$(RUN_CSS) $@.tmp > $@.tmp2
@stat --printf="%-35n %7s\n" $@.tmp $@.tmp2
@$(GZIP) -c $@.tmp2 > $@.tmp
@rm $@.tmp2
@mv $@.tmp $@
@stat --printf="%-35n %7s\n" $@
endef

all:
$(MAKE) -f $(IAM) WEBUI=std compile-std
$(MAKE) -f $(IAM) WEBUI=debug compile-debug

$(WEBDIR)/extjs-std.c: $(JAVASCRIPT_SRC) $(CSS_SRC)
$(VV)echo -e 'extjs_lcss(hq, "static/tvh.css.gz");' > $@
$(VV)echo -e 'extjs_load(hq, "static/tvh.js.gz");' >> $@

$(WEBDIR)/extjs-debug.c: $(JAVASCRIPT_SRC) $(CSS_SRC)
$(VV)echo -e '$(foreach f,$(CSS),extjs_lcss(hq, "$(f)");\r\n)' > $@
$(VV)echo -e '$(foreach f,$(JAVASCRIPT),extjs_load(hq, "$(f)");\r\n)' >> $@

$(WEBDIR)/extjs-tv-std.c: $(JAVASCRIPT_TV_SRC) $(CSS_TV_SRC)
$(VV)echo -e 'extjs_lcss(hq, "static/tvh-tv.css.gz");' > $@
$(VV)echo -e 'extjs_load(hq, "static/tvh-tv.js.gz");' >> $@

$(WEBDIR)/extjs-tv-debug.c: $(JAVASCRIPT_TV_SRC) $(CSS_TV_SRC)
$(VV)echo -e '$(foreach f,$(CSS_TV),extjs_lcss(hq, "$(f)");\r\n)' > $@
$(VV)echo -e '$(foreach f,$(JAVASCRIPT_TV),extjs_load(hq, "$(f)");\r\n)' >> $@

$(WEBDIR)/$(ROOTPATH)/tvh.js.gz: $(JAVASCRIPT_SRC)
$(call GO_JS)

$(WEBDIR)/$(ROOTPATH)/tvh.css.gz: $(CSS_SRC)
$(call GO_CSS)

$(WEBDIR)/$(ROOTPATH)/tvh-tv.js.gz: $(JAVASCRIPT_TV_SRC)
$(call GO_JS)

$(WEBDIR)/$(ROOTPATH)/tvh-tv.css.gz: $(CSS_TV_SRC)
$(call GO_CSS)

.PHONY: compile-std
compile-std: $(WEBDIR)/$(ROOTPATH)/tvh.js.gz $(WEBDIR)/$(ROOTPATH)/tvh.css.gz \
$(WEBDIR)/$(ROOTPATH)/tvh-tv.js.gz $(WEBDIR)/$(ROOTPATH)/tvh-tv.css.gz \
$(WEBDIR)/extjs-std.c $(WEBDIR)/extjs-tv-std.c
@echo "WEBUI std finished"

.PHONY: compile-debug
compile-debug: $(WEBDIR)/extjs-debug.c $(WEBDIR)/extjs-tv-debug.c
@echo "WEBUI debug finished"

.PHONY:
clean:
rm -f $(foreach f,tvh.js tvh.css tvh-tv.js tvh-tv.css,\
$(WEBDIR)/$(ROOTPATH)/$(f).gz \
$(WEBDIR)/$(ROOTPATH)/$(f).tmp \
$(WEBDIR)/$(ROOTPATH)/$(f).tmp2) \
$(WEBDIR)/extjs-std.c $(WEBDIR)/extjs-tv-std.c \
$(WEBDIR)/extjs-debug.c $(WEBDIR)/extjs-tv-debug.c
101 changes: 21 additions & 80 deletions src/webui/extjs.c
Expand Up @@ -113,81 +113,21 @@ extjs_root(http_connection_t *hc, const char *remain, void *opaque)
htsbuf_qprintf(hq, "<head>\n");

htsbuf_qprintf(hq, "<meta name=\"apple-itunes-app\" content=\"app-id=638900112\">\n");

if (tvheadend_webui_debug) {

extjs_load(hq, EXTJSPATH "/adapter/ext/ext-base%s.js", tvheadend_webui_debug ? "-debug" : "");
extjs_load(hq, EXTJSPATH "/ext-all%s.js", tvheadend_webui_debug ? "-debug" : "");
extjs_lcss(hq, EXTJSPATH "/resources/css/ext-all-notheme.css");
extjs_lcss(hq, EXTJSPATH "/resources/css/xtheme-blue.css");
extjs_lcss(hq, "static/livegrid/resources/css/ext-ux-livegrid.css");
extjs_lcss(hq, EXTJSPATH "/examples/ux/gridfilters/css/GridFilters.css");
extjs_lcss(hq, EXTJSPATH "/examples/ux/gridfilters/css/RangeMenu.css");
extjs_lcss(hq, "static/xcheckbox/xcheckbox.css");
extjs_lcss(hq, "static/app/ext.css");

extjs_exec(hq, "Ext.BLANK_IMAGE_URL = \'" EXTJSPATH "/resources/images/default/s.gif';");

/**
* Load extjs extensions
*/
extjs_load(hq, "static/app/extensions.js");
extjs_load(hq, "static/livegrid/livegrid-all.js");
extjs_load(hq, "static/lovcombo/lovcombo-all.js");
extjs_load(hq, "static/multiselect/multiselect.js");
extjs_load(hq, "static/multiselect/ddview.js");
extjs_load(hq, "static/xcheckbox/xcheckbox.js");
extjs_load(hq, "static/checkcolumn/CheckColumn.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/GridFilters.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/Filter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/BooleanFilter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/DateFilter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/ListFilter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/NumericFilter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/filter/StringFilter.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/menu/ListMenu.js");
extjs_load(hq, EXTJSPATH "/examples/ux/gridfilters/menu/RangeMenu.js");

/**
* Create a namespace for our app
*/
extjs_exec(hq, "Ext.namespace('tvheadend');");

/**
* Load all components
*/
extjs_load(hq, "static/smoothie.js");
extjs_load(hq, "static/app/comet.js");
extjs_load(hq, "static/app/tableeditor.js");
extjs_load(hq, "static/app/cteditor.js");
extjs_load(hq, "static/app/acleditor.js");
#if ENABLE_CWC || ENABLE_CAPMT
extjs_load(hq, "static/app/caclient.js");
#endif
extjs_load(hq, "static/app/tvadapters.js");
extjs_load(hq, "static/app/idnode.js");
extjs_load(hq, "static/app/esfilter.js");
#if ENABLE_MPEGTS
extjs_load(hq, "static/app/mpegts.js");
#endif
#if ENABLE_TIMESHIFT
extjs_load(hq, "static/app/timeshift.js");
#endif
extjs_load(hq, "static/app/chconf.js");
extjs_load(hq, "static/app/epg.js");
extjs_load(hq, "static/app/dvr.js");
extjs_load(hq, "static/app/epggrab.js");
extjs_load(hq, "static/app/config.js");
extjs_load(hq, "static/app/tvhlog.js");
extjs_load(hq, "static/app/status.js");
extjs_load(hq, "static/tv.js");
extjs_load(hq, "static/app/servicemapper.js");

/**
* Finally, the app itself
*/
extjs_load(hq, "static/app/tvheadend.js");
extjs_exec(hq, "Ext.onReady(tvheadend.app.init, tvheadend.app);");

#include "extjs-debug.c"

} else {

#include "extjs-std.c"

}

extjs_exec(hq, "\
Ext.BLANK_IMAGE_URL = \'" EXTJSPATH "/resources/images/default/s.gif';\r\n\
Ext.onReady(tvheadend.app.init, tvheadend.app);\
");


htsbuf_qprintf(hq,
Expand All @@ -213,6 +153,7 @@ extjs_root(http_connection_t *hc, const char *remain, void *opaque)
"<div id=\"systemlog\"></div>\n"
"</body></html>\n",
tvheadend_version);

http_output_html(hc);
return 0;
}
Expand All @@ -230,17 +171,17 @@ extjs_livetv(http_connection_t *hc, const char *remain, void *opaque)
htsbuf_qprintf(hq, "<html>\n");
htsbuf_qprintf(hq, "<head>\n");
htsbuf_qprintf(hq, "<title>HTS Tvheadend %s</title>\n", tvheadend_version);
extjs_lcss(hq, "static/tv.css");

if(tvheadend_webui_debug) {
extjs_load(hq, EXTJSPATH "/adapter/ext/ext-base-debug.js");
extjs_load(hq, EXTJSPATH "/ext-all-debug.js");
if (tvheadend_webui_debug) {

#include "extjs-tv-debug.c"

} else {
extjs_load(hq, EXTJSPATH "/adapter/ext/ext-base.js");
extjs_load(hq, EXTJSPATH "/ext-all.js");

#include "extjs-tv-std.c"

}

extjs_load(hq, "static/tv.js");
extjs_exec(hq, "Ext.onReady(tv.app.init, tv.app);");

htsbuf_qprintf(hq, "</head>\n");
Expand Down

3 comments on commit 4aca9be

@EricV2
Copy link

@EricV2 EricV2 commented on 4aca9be May 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks compil on debian.
CC src/webui/extjs.o
In file included from src/webui/extjs.c:119:0:
src/webui/extjs-debug.c: In function ‘extjs_root’:
src/webui/extjs-debug.c:1:2: error: ‘e’ undeclared (first use in this function)
-e extjs_lcss(hq, "static/extjs/resources/css/ext-all-notheme.css");
^
src/webui/extjs-debug.c:1:2: note: each undeclared identifier is reported only once for each function it appears in
src/webui/extjs-debug.c:1:4: error: expected ‘;’ before ‘extjs_lcss’
-e extjs_lcss(hq, "static/extjs/resources/css/ext-all-notheme.css");
^
src/webui/extjs-debug.c:9:4: error: expected ‘;’ before ‘extjs_load’
-e extjs_load(hq, "static/extjs/adapter/ext/ext-base-debug.js");
^
In file included from src/webui/extjs.c:123:0:
src/webui/extjs-std.c:1:4: error: expected ‘;’ before ‘extjs_lcss’
-e extjs_lcss(hq, "static/tvh.css.gz");
^
src/webui/extjs-std.c:2:4: error: expected ‘;’ before ‘extjs_load’
-e extjs_load(hq, "static/tvh.js.gz");
^

more src/webui/extjs-tv-debug.c
-e extjs_lcss(hq, "static/tv.css");

-e extjs_load(hq, "static/extjs/adapter/ext/ext-base-debug.js");
extjs_load(hq, "static/extjs/ext-all-debug.js");
extjs_load(hq, "static/tv.js");

@Quonith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have same problem with compilation. Debian jessie on raspberry pi 2.

@perexg
Copy link
Contributor Author

@perexg perexg commented on 4aca9be May 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest master - the 'echo -e' was replaced with 'printf'.

Please sign in to comment.