1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Night-mode: Allow global user-overrides for night-mode css / logo

This commit is contained in:
gnosygnu
2017-06-25 15:47:30 -04:00
parent 67fc90d43f
commit f1da174c5c
16 changed files with 160 additions and 36 deletions

View File

@@ -43,7 +43,11 @@ public class Xoav_app implements Xoa_app, Gfo_invk {
this.utl_msg_log = Gfo_msg_log.Test();
this.html__bridge_mgr = new Xoh_bridge_mgr(utl__json_parser);
this.gui__tab_mgr = tab_mgr;
// user
this.user = new Xouv_user(this, "anonymous", root_dir.GenSubDir_nest("user", "anonymous"));
this.fsys_mgr.Url_finder().Init_by_user(user.Fsys_mgr());
this.api_root = null;
this.site_cfg_mgr = new Xoa_site_cfg_mgr(this);
this.bldr = new Xob_bldr(null);

View File

@@ -30,6 +30,7 @@ public class Xoa_fsys_mgr implements Gfo_invk {
this.cfg_wiki_core_dir = bin_xowa_dir.GenSubDir_nest("cfg", "wiki", "core");
this.cfg_site_meta_fil = bin_xowa_dir.GenSubFil_nest("cfg", "wiki", "site_meta.sqlite3");
this.home_wiki_dir = bin_xowa_dir.GenSubDir_nest("wiki", Xow_domain_itm_.Str__home);
this.url_finder = new Xoa_url_finder(this);
}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir; // EX: /xowa/
public Io_url Wiki_dir() {return wiki_dir;} private final Io_url wiki_dir; // EX: /xowa/wiki/
@@ -37,7 +38,7 @@ public class Xoa_fsys_mgr implements Gfo_invk {
public Io_url Css_dir() {return css_dir;} private final Io_url css_dir; // EX: /xowa/user/anonymous/wiki/
public Io_url Bin_plat_dir() {return bin_plat_dir;} private final Io_url bin_plat_dir; // EX: /xowa/bin/lnx_64/
public Io_url Bin_any_dir() {return bin_any_dir;} private final Io_url bin_any_dir; // EX: /xowa/bin/any
public Io_url Bin_xowa_dir() {return bin_xowa_dir;} private final Io_url bin_xowa_dir;
public Io_url Bin_xowa_dir() {return bin_xowa_dir;} private final Io_url bin_xowa_dir; // EX: /xowa/bin/any/xowa
public Io_url Bin_xowa_file_dir() {return bin_xowa_file_dir;} private final Io_url bin_xowa_file_dir;
public Io_url Bin_xtns_dir() {return bin_xtns_dir;} private final Io_url bin_xtns_dir;
public Io_url Bin_addon_dir() {return bin_addon_dir;} private final Io_url bin_addon_dir;
@@ -49,6 +50,7 @@ public class Xoa_fsys_mgr implements Gfo_invk {
public Io_url Home_wiki_dir() {return home_wiki_dir;} private final Io_url home_wiki_dir;
public Io_url Cfg_app_fil() {return cfg_app_fil;} private final Io_url cfg_app_fil;
public Io_url Http_root() {return http_root;} private final Io_url http_root; // EX: file:///xowa/ or file:///android_asset/xowa/
public Xoa_url_finder Url_finder() {return url_finder;} private final Xoa_url_finder url_finder;
public void Init_by_app(Gfo_invk app_mgr_invk) {this.app_mgr_invk = app_mgr_invk;} private Gfo_invk app_mgr_invk; // for gfs and app.launcher
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_apps)) return app_mgr_invk;
@@ -56,4 +58,7 @@ public class Xoa_fsys_mgr implements Gfo_invk {
else return Gfo_invk_.Rv_unhandled;
}
private static final String Invk_apps = "apps", Invk_root_dir = "root_dir";
public static Xoa_fsys_mgr New_by_plat(String plat_name, Io_url root_dir) { // TEST:
return new Xoa_fsys_mgr(plat_name, root_dir, root_dir.GenSubDir("wiki"), root_dir.GenSubDir("file"), root_dir.GenSubDir("css"), root_dir.GenSubDir("html"));
}
}

View File

@@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.xowa.users.*;
public class Xoa_url_finder {
private final Xoa_fsys_mgr app_fsys_mgr;
private Xou_fsys_mgr usr_fsys_mgr;
public Xoa_url_finder(Xoa_fsys_mgr app_fsys_mgr) {
this.app_fsys_mgr = app_fsys_mgr;
}
public void Init_by_user(Xou_fsys_mgr usr_fsys_mgr) {
this.usr_fsys_mgr = usr_fsys_mgr;
}
public Io_url Find_by_css_or_app_bin(String wiki, String file, String[] app_dir_parts) {return Find_by_css_or(wiki, file, app_dir_parts, true);}
public Io_url Find_by_css_or(String wiki, String file, String[] app_dir_parts, boolean app_bin_if_missing) {
// check wiki_css dir; EX: /xowa/user/anonymous/wiki/en.wikipedia.org/html/logo.png
Io_url usr_css_fil = usr_fsys_mgr.Wiki_html_dir(wiki).GenSubFil(file);
if (Io_mgr.Instance.ExistsFil(usr_css_fil))
return usr_css_fil;
// check usr_bin dir; EX: /xowa/user/app/overrides/bin/any/xowa/html/css/nightmode/logo.png
Io_url usr_bin_fil = usr_fsys_mgr.App_root_dir().GenSubDir("overrides").GenSubDir_nest(app_dir_parts).GenSubFil(file);
if (Io_mgr.Instance.ExistsFil(usr_bin_fil))
return usr_bin_fil;
// check app_bin dir; EX: /xowa/bin/any/xowa/html/css/nightmode/logo.png
Io_url app_bin_fil = app_fsys_mgr.Root_dir().GenSubDir_nest(app_dir_parts).GenSubFil(file);
if (Io_mgr.Instance.ExistsFil(app_bin_fil))
return app_bin_fil;
// nothing found
return app_bin_if_missing ? app_bin_fil : null;
}
}

View File

@@ -0,0 +1,64 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.apps.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.core.tests.*;
import gplx.xowa.users.*;
public class Xoa_url_finder_tst {
private final Xoa_url_finder_fxt fxt = new Xoa_url_finder_fxt();
@Test public void Find_by_css_or_null() {
// init
String wiki = "en.wikipedia.org";
String file = "logo_night.png";
String[] subs = String_.Ary("bin", "any", "xowa", "html", "css", "nightmode");
String expd = null;
// null case
expd = null;
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
// app_bin
expd = "mem/xowa/bin/any/xowa/html/css/nightmode/logo_night.png";
fxt.Init__Fsys__save(expd);
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
// usr_bin
expd = "mem/xowa/user/anonymous/app/overrides/bin/any/xowa/html/css/nightmode/logo_night.png";
fxt.Init__Fsys__save(expd);
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
// wiki_css
expd = "mem/xowa/user/anonymous/wiki/en.wikipedia.org/html/logo_night.png";
fxt.Init__Fsys__save(expd);
fxt.Test__Find_by_css_or_null(expd, wiki, file, subs);
}
}
class Xoa_url_finder_fxt {
private final Xoa_url_finder finder;
public Xoa_url_finder_fxt() {
Io_url root_dir = Io_url_.mem_dir_("mem/xowa/");
Xoa_fsys_mgr app_fsys_mgr = Xoa_fsys_mgr.New_by_plat("lnx", root_dir);
Xou_fsys_mgr usr_fsys_mgr = new Xou_fsys_mgr(root_dir.GenSubDir_nest("user", "anonymous"));
this.finder = new Xoa_url_finder(app_fsys_mgr);
finder.Init_by_user(usr_fsys_mgr);
}
public void Init__Fsys__save(String url) {
Io_mgr.Instance.SaveFilStr(url, "");
}
public void Test__Find_by_css_or_null(String expd, String wiki, String file, String[] dir_parts) {
Io_url actl = finder.Find_by_css_or(wiki, file, dir_parts, false);
Gftest.Eq__str(expd, actl == null ? null : actl.Raw());
}
}