Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Profiles plugin #5079

Open
wants to merge 2 commits into
base: master
from

Conversation

@Thra11
Copy link
Contributor

commented Jun 15, 2019

I've been thinking about how, depending on whether it's day or night, I adjust a number of settings, but I usually end up with one of two states:

Setting Dark Light
Frontlight Brightness 1 16
Frontlight Warmth 100 30
Night Mode On Off
Font Contrast Higher Low

My idea to make this more convenient is as follows.

  • The user is able to configure two (possibly more) "profiles".
  • With a UI similar to the gesture configuration UI, the user can choose multiple settings (with values) to add to the profile.
  • Loading a profile simply sets the chosen settings to the selected values (After setting the settings, KOReader doesn't need to remember which profile was loaded, and the user can adjust the settings as usual).
  • An action to toggle (or cycle) between profiles could be made available, so a gesture can toggle between profiles.

Would probably also solve some other issues, such as #1427 & #5019.

So far, this is a proof-of-concept which allows you to use gestures to "cycle through profiles" (execute one of two lua files). At the moment, the "profiles" are hand-written scripts (copy them into koreader/profiles/ to use them): It doesn't have a GUI to select desired settings and values yet.

Remarks
I thought about trying to hook into the gesture manager's actions, as a way to have a selection of relevant actions available instead of arbitrary code execution. However, actions are too limited for my use case, as they don't allow you to select custom values (e.g. there's a "toggle frontlight" action, but there's no "set frontlight intensity to x", nor support in the GUI for choosing x. Similarly, there's a "toggle night mode", but no "turn night mode on", etc.).

Thra11 added 2 commits Jun 15, 2019
Profiles plugin: First prototype
Plugin which executes lua scripts in order to set mutiple koreader settings to
selected values. Can cycle through profiles as an action in reponse to a
gesture.
Profiles plugin: Example profile files
If placed in koreader/profiles/, allows you to quickly toggle between a
'daytime' profile (no night mode, cool, bright frontlight), and a
'nighttime' profile (night mode, warm, dim frontlight).

@Thra11 Thra11 force-pushed the Thra11:profiles-plugin branch from 55b8727 to 89c9080 Jun 15, 2019

@Frenzie

This comment has been minimized.

Copy link
Member

commented Jun 15, 2019

I thought about trying to hook into the gesture manager's actions, as a way to have a selection of relevant actions available instead of arbitrary code execution. However, actions are too limited for my use case, as they don't allow you to select custom values (e.g. there's a "toggle frontlight" action, but there's no "set frontlight intensity to x", nor support in the GUI for choosing x. Similarly, there's a "toggle night mode", but no "turn night mode on", etc.).

Doesn't mean there shouldn't be. ;-)

Interesting concept!

@@ -0,0 +1,14 @@
local Device = require("device")
local Screen = require("device").screen

This comment has been minimized.

Copy link
@Frenzie

Frenzie Jun 15, 2019

Member

It doesn't make much practical difference but according to the coding style that should be:

Suggested change
local Screen = require("device").screen
local Screen = Device.screen

function Profiles:addToMainMenu(menu_items)
logger.info("Profiles:addToMainMenu")
menu_items.profiles = {

This comment has been minimized.

Copy link
@Frenzie

Frenzie Jun 15, 2019

Member

You should also add a sorting_hint = "tools",.

PS I haven't tried it yet or thought about where it'd be best to put it.

@Frenzie Frenzie added this to the 2019.07 milestone Jun 15, 2019

@Thra11

This comment has been minimized.

Copy link
Contributor Author

commented Jun 15, 2019

It should be simple enough to just store a table of parameters (nothing/empty table for actions which don't need a parameter) along with the string which identifies the action. So instead of storing
"toggle_frontlight",
you'd store something like
{ "set_frontlight_intensity", 50 }
Lua seems to be quite good at handling things which might not be there: it would be nice if we could leave existing settings untouched.

In addition to the action_strings, we'd need a list of parameters that an action takes, with each parameter specifying its type (boolean, integer, enumeration, etc.), valid values (e.g. min & max for integers, possible choices for enumerations). Then the UI could decide what type of control to show, such as a checkbox for a boolean, an input text box for an integer, or a menu for an enumeration.

If we did implement this, then a profile would simply be a list of actions, and loading a profile would consist of iterating over the list triggering each action.

@poire-z

This comment has been minimized.

Copy link
Contributor

commented Jun 15, 2019

Then the UI could decide what type of control to show, such as a checkbox for a boolean, an input text box for an integer, or a menu for an enumeration

Just a thought if you feel like going with a UI:
Instead of having a specific UI with again some ways to configure stuff (that we can already configure each in their own place), you could just show a list of checkbox'able settings display name (without their value, and no way to configure them), and the user would just check all the settings he wants included in this profile, and ignore other. You would then just save the ones checked, with their current (not shown to the user) value(s) in your profile file. Like:

Settings to include in this new profile
   [x] nighmode
   [x] frontlight level
   [ ] font size
   [x] font contrast
...

(No way to edit a current one, except applying it, and just reselect what settings to include, and replace.)

@Frenzie Frenzie modified the milestones: 2019.07, 2019.08 Jul 15, 2019

@Frenzie

This comment has been minimized.

Copy link
Member

commented Aug 3, 2019

@Thra11 Btw, other than my minor nits I have no objection to merging this as is for now. :-)

@Thra11

This comment has been minimized.

Copy link
Contributor Author

commented Aug 3, 2019

when I have time, I think @poire-z's suggestion of creating profiles by saving the current setup with a filter to select which settings to include is probably the best way to do it, but I haven't had time to implement it so far. In the meantime, I've no objection to it being merged as is (with your changes). It can't hurt anyone by existing, and somebody might find it useful.

I'll leave it to you to decide :-)

@Frenzie

This comment has been minimized.

Copy link
Member

commented Aug 3, 2019

I'm of the opinion that it's easier for others to build upon once it's in. :-)

@Frenzie Frenzie modified the milestones: 2019.08, 2019.09 Aug 5, 2019

@Frenzie Frenzie modified the milestones: 2019.09, 2019.10 Aug 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.