-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Closed
WIP: Profiles plugin #5079
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'.]]), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||
local Device = require("device") | ||||||
local Screen = require("device").screen | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.