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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/apps/reader/modules/readergesture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ local action_strings = {
cycle_highlight_action = _("Cycle highlight action"),
cycle_highlight_style = _("Cycle highlight style"),
wallabag_download = _("Wallabag retrieval"),
load_next_profile = _("Load next profile"),
load_previous_profile = _("Load previous profile"),
}

local custom_multiswipes_path = DataStorage:getSettingsDir().."/multiswipes.lua"
Expand Down Expand Up @@ -491,6 +493,8 @@ function ReaderGesture:buildMenu(ges, default)
{"cycle_highlight_action", not self.is_docless},
{"cycle_highlight_style", not self.is_docless},
{"wallabag_download", self.ui.wallabag ~= nil},
{"load_next_profile", self.ui.profiles ~= nil},
{"load_previous_profile", self.ui.profiles ~= nil},
}
local return_menu = {}
-- add default action to the top of the submenu
Expand Down Expand Up @@ -1053,6 +1057,10 @@ function ReaderGesture:gestureAction(action, ges)
self.ui:handleEvent(Event:new("CycleHighlightAction"))
elseif action == "cycle_highlight_style" then
self.ui:handleEvent(Event:new("CycleHighlightStyle"))
elseif action == "load_next_profile" then
self.ui:handleEvent(Event:new("LoadNextProfile"))
elseif action == "load_previous_profile" then
self.ui:handleEvent(Event:new("LoadPreviousProfile"))
end
return true
end
Expand Down
1 change: 1 addition & 0 deletions frontend/ui/elements/filemanager_menu_order.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ local order = {
"news_downloader",
"send2ebook",
"text_editor",
"profiles",
"----------------------------",
"more_plugins",
"plugin_management",
Expand Down
1 change: 1 addition & 0 deletions frontend/ui/elements/reader_menu_order.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ local order = {
"news_downloader",
"send2ebook",
"text_editor",
"profiles",
"----------------------------",
"more_plugins",
"plugin_management",
Expand Down
6 changes: 6 additions & 0 deletions plugins/profiles.koplugin/_meta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local _ = require("gettext")
return {
name = 'profiles',
fullname = _("Profiles"),
description = _([[This plugin allows combining multiple settings to make switchable 'profiles'.]]),
}
83 changes: 83 additions & 0 deletions plugins/profiles.koplugin/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
local DataStorage = require("datastorage")
local Event = require("ui/event")
local FFIUtil = require("ffi/util")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local _ = require("gettext")
local logger = require("logger")
local T = FFIUtil.template

local Profiles = WidgetContainer:new{
name = "profiles",
}

local last_profile = 1
local number_of_profiles = 2

function Profiles:init()
logger.info("Profiles:init()")
self.ui.menu:registerToMainMenu(self)
end

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

Choose a reason for hiding this comment

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

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.

text = _("Profiles"),
sub_item_table = {
{
text = _("Profile 1"),
keep_menu_open = true,
callback = function()
-- Profile configuration via GUI not yet implemented
logger.dbg("Profile 1 menu callback")
end,
},
{
text = _("Profile 2"),
keep_menu_open = true,
callback = function()
-- Profile configuration via GUI not yet implemented
logger.dbg("Profile 2 menu callback")
end,
},
{
text = _("Load next profile"),
callback = function()
self.ui:handleEvent(Event:new("LoadNextProfile"))
end,
},
{
text = _("Load previous profile"),
callback = function()
self.ui:handleEvent(Event:new("LoadPreviousProfile"))
end,
},
},
}
end

function Profiles:loadProfile(profile_number)
local profile_path = T(_("%1/profiles/profile_%2.lua"), DataStorage:getFullDataDir(), profile_number)
logger.dbg("Executing profile file", profile_path)
local ok, err = xpcall(dofile, debug.traceback, profile_path)
if not ok then
logger.dbg("Problem executing profile:", err)
end
end

function Profiles:onLoadNextProfile()
last_profile = last_profile + 1
if last_profile > number_of_profiles then
last_profile = 1
end
self:loadProfile(last_profile)
end

function Profiles:onLoadPreviousProfile()
last_profile = last_profile - 1
if last_profile <= 0 then
last_profile = 1
end
self:loadProfile(last_profile)
end

return Profiles
14 changes: 14 additions & 0 deletions plugins/profiles.koplugin/profile_1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local Device = require("device")
local Screen = require("device").screen
Copy link
Member

Choose a reason for hiding this comment

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

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

local UIManager = require("ui/uimanager")

local night_mode = G_reader_settings:isTrue("night_mode")
if night_mode then
Screen:toggleNightMode()
UIManager:setDirty("all", "full")
G_reader_settings:saveSetting("night_mode", false)
end

local powerd = Device:getPowerDevice()
powerd:setIntensity(16)
powerd:setWarmth(30)
14 changes: 14 additions & 0 deletions plugins/profiles.koplugin/profile_2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local Device = require("device")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")

local night_mode = G_reader_settings:isTrue("night_mode")
if not night_mode then
Screen:toggleNightMode()
UIManager:setDirty("all", "full")
G_reader_settings:saveSetting("night_mode", true)
end

local powerd = Device:getPowerDevice()
powerd:setIntensity(1)
powerd:setWarmth(100)