151 Commits

Author SHA1 Message Date
David
5ac434183d [minor] Rename file_cap to max_files (#14522)
See <https://github.com/koreader/koreader/pull/14521#issuecomment-3452885094>.
2025-10-28 12:43:08 +01:00
David
393837b919 [Screensaver] Add an adjustable cap (default 256) to the number of random images processed (#14521) 2025-10-27 19:31:04 +01:00
hius07
0bea354d3b Export highlights: secure export filename (#14325) 2025-09-15 17:02:42 +03:00
spfenwick
c00df15aee OPDS Plugin: Ensure the default download filename is consistent across different platforms (#13709)
* Ensure the default download filename is consistent across different platforms.
The OPDS plugin correctly uses util.getSafeFilename() to remove any special characters from the filename for downloads. However this function works differently on different platforms, with some common characters like : and ? being allowed on some platforms but not others. In particular this may break Process Sync if it is configured to rely on file names. This change gives a better default behaviour by ensuring the default filename is the same across different platforms, while still letting the user change the filename to include special characters if the platform supports them.

* Make util.replaceAllInvalidChars() global and call it rather than copying code.
2025-08-16 21:33:01 +02:00
Michał Mnich
8db0dee5e0 [fix] Improve handling of illegal vFAT filenames. (#14043)
This change fixes an issue where a file/directory is not created when its name contains trailing spaces or dots.
The issue has been observed on a Kobo device, but probably also applies to other systems using vFAT.

We also might want to consider handling other illegal vFAT filenames like `NUL` or `AUX`.

Please see the [official Microsoft documentation](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions)
for more details on the naming conventions of vFAT (this change addresses the last bullet point).
2025-07-13 22:34:17 +02:00
hius07
a4bb9d688b util: enable comma in filenames (#13985) 2025-06-23 20:53:33 +02:00
gray
cf0f803d1b Fix file transfer from Calibre to Remarkable Paper Pro (#13732)
The output of df wraps on to multiple lines on the rmpp due to the device mapped mount points. Enabling the posix -P option to df prevents this and allow the output to be parsed as normal.
2025-05-05 18:19:35 +02:00
Robert Greener
edb8f29de0 Quote directory in util.diskUsage (#13448)
If not quoted, this function does not work with directories that include a space in their name
2025-04-09 13:01:47 +02:00
Frans de Jonge
f7337a88aa [minor] Remove accidental self from util.calcFreeMem() (#13096) 2025-01-19 22:20:53 +01:00
hius07
f025cce059 Collections: add books from a folder (#12892) 2024-12-15 18:22:05 +02:00
mergen3107
e95541ffd3 [Kindle NT] fix terminal and timesync (#12765)
Closes #12760
Credits go to @benoit-pierre (Thank you!)
2024-11-23 19:30:48 +01:00
hius07
c2d1099976 Profiles: more auto-exec triggers 2 (#12691) 2024-10-31 20:26:21 +02:00
hius07
1778c698b5 Profiles: more auto-exec triggers (#12651) 2024-10-23 12:56:46 +03:00
hius07
9f7dc85084 DocSettingsTweak: apply to books with status (#12606) 2024-10-09 19:28:37 +03:00
NiLuJe
f8df76e5c4 misc: Move cleanupSelectedText to util (#12477)
Instead of duplicating it across ReaderHighlight, languagesupport, and potentially VocabBuilder.

Re: #12469
2024-09-06 23:06:28 +02:00
mergen3107
b5a822cf8b WebDav: Simplify path manipulations to fix wonky heuristics (#12038)
This prevents the current directory from appearing in the listing.
2024-06-20 19:46:03 +02:00
hasezoey
42c93a7623 FileChooser collates: use "item.sort_percent" for sorting + extra on-hold handling (#11592)
re https://github.com/koreader/koreader/pull/11524#issuecomment-1984110990
re https://github.com/koreader/koreader/pull/11542#issuecomment-2018164346

re #11592
2024-03-30 14:04:43 +01:00
poire-z
70e6f4ce09 util.prettifyCSS(): handle better :is() and similar 2024-03-10 17:06:14 +01:00
hius07
962477e7c6 TextViewer: make find result bold (#11427) 2024-02-03 10:32:33 +02:00
mergen3107
57cbde5901 [plugin] Add folder check in move-to-archive (#11262) 2023-12-27 20:45:16 +01:00
hius07
c92d94af4d writeToFile: centralize (#11012) 2023-10-17 07:42:07 +03:00
hius07
2ed2c2c23d md5: centralize and deduplicate (#11003)
Document partial md5 hash is calculated by util.partialMD5() and stored in doc_settings as "partial_md5_checksum" on the first document opening.
2023-10-15 07:47:09 +03:00
yparitcher
0e26d4499b util.htmlEntitiesToUtf8: add some more semi common entities (#10979) 2023-10-12 14:46:37 +02:00
Ryan W West
27104ea011 Add hash-based document metadata storage option (#10945)
This option saves metadata sidecar (sdr) directories not next to the book or in koreader/docsettings/, but in koreader/hashdocsettings/ using the partial md5 hash of each documents, allowing users to move, rename, and copy their documents outside of KOReader without accidentally losing their highlights/notes/progress. Included are various warnings and info to users of the benefits and drawbacks of this non-default option.

Closes #10892.
2023-10-11 10:39:33 +02:00
poire-z
e641c89eee View HTML & CSS: fix minor spacing issues 2023-08-10 16:57:12 +02:00
poire-z
626864f856 [chore] replace utf8 bytes with Unicode escape sequence 2023-08-02 01:28:24 +02:00
poire-z
7bff61150a util.prettifyCSS(): do better with more complex CSS 2023-08-02 01:28:24 +02:00
NiLuJe
9c8e55b3e5 Kobo: Yet another attempt at working around the hangs on the latest NXP boards (#10771)
* Notification: Drop the fencing from #10083; it never actually helped, and had subtle side-effects we could do without.
* VirtualKeyBoard: Flash on close, otherwise, some of the fast refresh glitches may be burned into the working buffer until a flash. Making sure we flash ourselves prevent it from sticking around on the page ;).
* util: Move `writeToSysfs` to base (i.e., `ffi/util`), as we need it there (and it actually makes more sense there anyway ;p).
* Bump base for https://github.com/koreader/koreader-base/pull/1645, which is where the actual workaround (hopefully) lives.

Re #8414, #9806, #10558
2023-08-01 23:53:10 +02:00
Sunny
9e0f185174 rM: Work around LD_PRELOAD weirdness on forks on rM 2 (#10490) 2023-05-26 20:51:15 +02:00
yparitcher
1102c030fa Kindle: toggle cover events
Allow disabling the hall efect sensor via the sysfs knob, so the kindle system wont sleep & wake the device

for those of use that stay in koreader, are caseless and have get spurious wakeups
2023-05-03 10:26:35 -04:00
NiLuJe
08b0c088e5 util: Add removePath (#10129)
Will attempt to prune empty directories from the given path, going as far back up as possible.
2023-02-17 23:24:42 +01:00
NiLuJe
318a22d913 util: Rewrite makePath (#10111)
The previous iteration, besides failing to handle leaf-only input,
was relying on splitFilePathName, which just doesn't do what's required
to incrementally build the directory tree the right way around ;).

This should more closely match mkdir -p, i.e., it will *fail* if any
part (or all of it) of the path exists but is *not* a directory.

Re #10074
2023-02-12 23:48:33 +01:00
zwim
192a243b4d Add datetime.lua
Move date and time related functions from util.lua
(and the statistics plugin) to a new datetime.lua.
2022-12-06 17:36:08 +01:00
NiLuJe
da65ac8b02 Cleanup various varargs shenanigans (#9624)
* Iterate over varargs directly via select if possible
* Use table.pack otherwise (https://github.com/koreader/koreader-base/pull/1535).
* This allows us to simplify a few Logger calls, as logger now handles nil values.
2022-10-12 19:59:48 +02:00
zwim
4969811c08 Optimization: Use constant folding for divisions not a power of two (#9609) 2022-10-10 22:21:27 +02:00
NiLuJe
ed96b15a3f util: Add a set of binary searches implementation (#9614) 2022-10-10 15:16:16 +02:00
NiLuJe
5c24470ea9 Logger: Use serpent instead of dump (#9588)
* Persist: support serpent, and use by default over dump (as we assume consistency > readability in Persist).
* Logger/Dbg: Use serpent instead of dump to dump tables (it's slightly more compact, honors __tostring, and will tag tables with their ref, which can come in handy when debugging).
* Dbg: Don't duplicate Logger's log function, just use it directly.
* Fontlist/ConfigDialog: Use serpent for the debug dump.
* Call `os.setlocale(C, "numeric")` on startup instead of peppering it around dump calls. It's process-wide, so it didn't make much sense.
* Trapper: Use LuaJIT's serde facilities instead of dump. They're more reliable in the face of funky input, much faster, and in this case, the data never makes it to human eyes, so a human-readable format didn't gain us anything.
2022-10-06 02:21:03 +02:00
NiLuJe
62059f8d68 Misc: Get rid of the legacy defaults.lua globals (#9546)
* This removes support for the following deprecated constants: `DTAP_ZONE_FLIPPING`, `DTAP_ZONE_BOOKMARK`, `DCREREADER_CONFIG_DEFAULT_FONT_GAMMA`
* The "Advanced settings" panel now highlights modified values in bold (think about:config in Firefox ;)).
* LuaData: Isolate global table lookup shenanigans, and fix a few issues in unused-in-prod codepaths.
* CodeStyle: Require module locals for Lua/C modules, too.
* ScreenSaver: Actually garbage collect our widget on close (ScreenSaver itself is not an instantiated object).
* DateTimeWidget: Code cleanups to ensure child widgets can be GC'ed.
2022-09-28 01:10:50 +02:00
NiLuJe
38919c22eb ImageViewer: Clamp zoom factor to sane values (#9529)
Should avoid egregious values that would potentially alloc insanely large buffers (and likely fail to do so).

In the process, tweak the scale_factor computations when zooming so as to produce slightly less annoying behavior.
2022-09-19 23:25:18 +02:00
hius07
56388aa491 TextViewer: add Find (#9507) 2022-09-13 17:09:49 -04:00
zwim
b26d3e9815 Autoturn: change to minutes and seconds (#9055)
fix #9051
and add some internal improvements (default values) to the datetimewidget.
2022-06-01 00:04:46 +02:00
zwim
d5d5867d4e DoubleSpinWidget, SpinWidget: add units, make usage more consistent (#9046) 2022-05-24 00:25:50 +02:00
zwim
b029a6a1ff [autosuspend, plugin] Switch to datetimewidget and provide default values (#8480) 2021-11-28 22:18:44 +01:00
zwim
e9ba854ff0 DeviceMenu: Colons and more information (#8435)
Add information to device menu entries
2021-11-23 21:17:07 +01:00
Aleksa Sarai
ac907df634 util: add reversible table method wrapping helper
In some cases, it's useful to be able to wrap a function and either
replace its contents entirely or have some callback be run before
calling the underlying function.

The most obvious users for this feature are the Japanese and Korean
keyboards (both of which need to wrap the inputbox methods with either
their own versions or have basic callbacks be run before the method is
executed).

This is loosely based on how busted/luassert spies work.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-11-07 19:23:56 +01:00
Aleksa Sarai
d0d2d0d1d6 *: luacheck fixes (#8368)
These weren't caught during the Japanese support plugin review.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-10-24 10:58:14 +02:00
Aleksa Sarai
6f1b70e5eb util.utf8: improve CJK character detection
Previously the CJK character detection defined only characters in the
range U+4000..U+AFFF as "CJK characters". This excludes an incredibly
large number of CJK characters within the BMP, let alone the whole two
planes dedicated to rarer CJK characters (the SIP and TIP). As a result,
a very large number of Chinese, Japanese, and Korean characters were not
detected as being CJK characters.

While slightly less elegant-looking, it is far more accurate to compute
the codepoint from the utf8 character and then see if it falls within
one of the defined CJK blocks. This is not future-proof against future
CJK ideograph extensions in future Unicode versions, but there is no
real way to accurately predict such changes so this is the best we can
do without accidentally treating characters explicitily defined as being
non-CJK in Unicode as CJK.

While we're at it, copy Lua 5.3's utf8.charpattern constant definition
so that we can more easily write utf8 iterators with string.gmatch (at
least in the interim until there is a rework of utf8 handling in
KOReader and everything is rebuilt on top of utf8proc).

Some unit tests are added for Korean and Japanese text, and the existing
unit tests needed a minor adjustment to handle the fact that
isSplittable now correctly detects CJK punctuation as a character to
compare against the forbidden split rules.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2021-10-23 15:49:54 +02:00
zwim
20f7d14495 Plugin: Auto warmth and night mode (#8129)
("Auto nightmode" only on devices without warmth.)
2021-09-25 11:02:10 +02:00
NiLuJe
1c739f1d54 ReadTimer: More QoL tweaks (#8107)
* Cleanup util.secondsFrom*Clock stuff (simpler maths, tail calls, meaningful printf tokens).
* Use util.secondsToClockDuration in ReadTimer instead of reinventing the wheel three different ways.
* Reschedule unexpired timers properly on resume (as best as we can, given the unreliable nature of REALTIME).
* Make clock timers tick on the dot, instead of at the same second as when being set.
* Speaking of clock timers, leave the math to os.date & os.time, don't reinvent the wheel yet again.
2021-08-22 00:34:09 +02:00
yparitcher
120eaf9193 secondsToHClock(): always floor seconds for consistency (#7987)
Fixes: #7984
2021-07-18 20:18:56 +02:00