Gestures: Refactor to use Dispatcher

reviewable/pr6467/r1
yparitcher 4 years ago
parent 79c5e088af
commit 9e0ac734ba

@ -2,5 +2,5 @@ local _ = require("gettext")
return {
name = 'gestures',
fullname = _("Gestures"),
description = _([[This plugin allows using gestures.]]),
description = _([[This plugin provides gesture support.]]),
}

@ -0,0 +1,136 @@
-- we can read Lua syntax here!
local Device = require("device")
return {
gesture_fm = {
tap_top_left_corner = nil,
tap_top_right_corner = {show_plus_menu = true,},
tap_right_bottom_corner = nil,
tap_left_bottom_corner = Device:hasFrontlight() and {toggle_frontlight = true,} or nil,
hold_top_left_corner = nil,
hold_top_right_corner = nil,
hold_bottom_left_corner = nil,
hold_bottom_right_corner = nil,
one_finger_swipe_left_edge_down = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
one_finger_swipe_left_edge_up = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
one_finger_swipe_right_edge_down = Device:hasNaturalLight() and {decrease_frontlight_warmth = 0,} or nil,
one_finger_swipe_right_edge_up = Device:hasNaturalLight() and {increase_frontlight_warmth = 0,} or nil,
one_finger_swipe_top_edge_right = nil,
one_finger_swipe_top_edge_left = nil,
one_finger_swipe_bottom_edge_right = nil,
one_finger_swipe_bottom_edge_left = nil,
double_tap_left_side = nil,
double_tap_right_side = nil,
double_tap_top_left_corner = nil,
double_tap_top_right_corner = nil,
double_tap_bottom_left_corner = nil,
double_tap_bottom_right_corner = nil,
two_finger_tap_top_left_corner = nil,
two_finger_tap_top_right_corner = nil,
two_finger_tap_bottom_left_corner = nil,
two_finger_tap_bottom_right_corner = nil,
short_diagonal_swipe = {full_refresh = true,},
multiswipe = {},
multiswipe_west_east = {},
multiswipe_east_west = {},
multiswipe_north_east = {},
multiswipe_north_west = {folder_shortcuts = true,},
multiswipe_north_south = {folder_up = true,},
multiswipe_east_north = {history = true,},
multiswipe_west_north = {},
multiswipe_east_south = {go_to = true,},
multiswipe_south_north = {},
multiswipe_south_east = {},
multiswipe_south_west = {show_frontlight_dialog = true,},
multiswipe_west_south = {back = true,},
multiswipe_north_south_north = {},
multiswipe_south_north_south = {},
multiswipe_west_east_west = {open_previous_document = true,},
multiswipe_east_west_east = {favorites = true,},
multiswipe_east_north_west = {},
multiswipe_south_east_north = {},
multiswipe_east_north_west_east = {},
multiswipe_south_east_north_south = {},
multiswipe_east_south_west_north = {full_refresh = true,},
multiswipe_southeast_northeast = {},
multiswipe_northwest_southwest_northwest = Device:hasWifiToggle() and {toggle_wifi = true,} or {},
multiswipe_southeast_southwest_northwest = Device:hasWifiToggle() and {wifi_off = true,} or {},
multiswipe_southeast_northeast_northwest = Device:hasWifiToggle() and {wifi_on = true,} or {},
two_finger_swipe_east = nil,
two_finger_swipe_west = {folder_shortcuts = true,},
two_finger_swipe_south = Device:hasFrontlight() and {decrease_frontlight = true,} or nil,
two_finger_swipe_north = Device:hasFrontlight() and {increase_frontlight = true,} or nil,
two_finger_swipe_northeast = nil,
two_finger_swipe_northwest = nil,
two_finger_swipe_southeast = nil,
two_finger_swipe_southwest = nil,
spread_gesture = nil,
pinch_gesture = nil,
},
gesture_reader = {
tap_top_left_corner = {toggle_page_flipping = true,},
tap_top_right_corner = {toggle_bookmark = true,},
tap_right_bottom_corner = nil,
tap_left_bottom_corner = Device:hasFrontlight() and {toggle_frontlight = true,} or nil,
hold_top_left_corner = nil,
hold_top_right_corner = nil,
hold_bottom_left_corner = nil,
hold_bottom_right_corner = nil,
one_finger_swipe_left_edge_down = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
one_finger_swipe_left_edge_up = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
one_finger_swipe_right_edge_down = Device:hasNaturalLight() and {decrease_frontlight_warmth = 0,} or nil,
one_finger_swipe_right_edge_up = Device:hasNaturalLight() and {increase_frontlight_warmth = 0,} or nil,
one_finger_swipe_top_edge_right = nil,
one_finger_swipe_top_edge_left = nil,
one_finger_swipe_bottom_edge_right = nil,
one_finger_swipe_bottom_edge_left = nil,
double_tap_left_side = {page_jmp = -10,},
double_tap_right_side = {page_jmp = 10,},
double_tap_top_left_corner = nil,
double_tap_top_right_corner = nil,
double_tap_bottom_left_corner = nil,
double_tap_bottom_right_corner = nil,
two_finger_tap_top_left_corner = nil,
two_finger_tap_top_right_corner = nil,
two_finger_tap_bottom_left_corner = nil,
two_finger_tap_bottom_right_corner = nil,
short_diagonal_swipe = {full_refresh = true,},
multiswipe = {}, -- otherwise registerGesture() won't pick up on multiswipes
multiswipe_west_east = {previous_location = true,},
multiswipe_east_west = {latest_bookmark = true,},
multiswipe_north_east = {toc = true,},
multiswipe_north_west = {bookmarks = true,},
multiswipe_north_south = {},
multiswipe_east_north = {history = true,},
multiswipe_west_north = {book_status = true,},
multiswipe_east_south = {go_to = true,},
multiswipe_south_north = {skim = true,},
multiswipe_south_east = {toggle_reflow = true,},
multiswipe_south_west = {show_frontlight_dialog = true,},
multiswipe_west_south = {back = true,},
multiswipe_north_south_north = {prev_chapter = true,},
multiswipe_south_north_south = {next_chapter = true,},
multiswipe_west_east_west = {open_previous_document = true,},
multiswipe_east_west_east = {favorites = true,},
multiswipe_east_north_west = {zoom = "contentwidth",},
multiswipe_south_east_north = {zoom = "contentheight",},
multiswipe_east_north_west_east = {zoom = "pagewidth",},
multiswipe_south_east_north_south = {zoom = "pageheight",},
multiswipe_east_south_west_north = {full_refresh = true,},
multiswipe_southeast_northeast = {follow_nearest_link = true,},
multiswipe_northwest_southwest_northwest = Device:hasWifiToggle() and {toggle_wifi = true,} or {},
multiswipe_southeast_southwest_northwest = Device:hasWifiToggle() and {wifi_off = true,} or {},
multiswipe_southeast_northeast_northwest = Device:hasWifiToggle() and {wifi_on = true,} or {},
two_finger_swipe_east = {toc = true,},
two_finger_swipe_west = {bookmarks = true,},
two_finger_swipe_south = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
two_finger_swipe_north = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
two_finger_swipe_northeast = nil,
two_finger_swipe_northwest = nil,
two_finger_swipe_southeast = nil,
two_finger_swipe_southwest = nil,
spread_gesture = {increase_font = 0,},
pinch_gesture = {decrease_font = 0,},
},
custom_multiswipes = {},
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,197 @@
local DataStorage = require("datastorage")
local LuaData = require("luadata")
local Migration = {}
local custom_multiswipes_path = DataStorage:getSettingsDir().."/multiswipes.lua"
local custom_multiswipes = LuaData:open(custom_multiswipes_path, { name = "MultiSwipes" })
local custom_multiswipes_table = custom_multiswipes:readSetting("multiswipes")
function Migration:convertAction(location, ges, action)
local result
if action == "ignore" then
result = nil
elseif action == "nothing" then
result = {}
elseif action == "reading_progress" then
result = {reading_progress = true,}
elseif action == "book_statistics" then
result = {book_statistics = true,}
elseif action == "stats_calendar_view" then
result = {stats_calendar_view = true,}
elseif action == "toc" then
result = {toc = true,}
elseif action == "night_mode" then
result = {night_mode = true,}
elseif action == "full_refresh" then
result = {full_refresh = true,}
elseif action == "bookmarks" then
result = {bookmarks = true,}
elseif action == "history" then
result = {history = true,}
elseif action == "favorites" then
result = {favorites = true,}
elseif action == "book_info" then
result = {book_info = true,}
elseif action == "book_description" then
result = {book_description = true,}
elseif action == "book_cover" then
result = {book_cover = true,}
elseif action == "book_status" then
result = {book_status = true}
elseif action == "page_jmp_fwd_10" then
result = {page_jmp = 10,}
elseif action == "page_jmp_fwd_1" then
result = {page_jmp = 1,}
elseif action == "page_jmp_back_10" then
result = {page_jmp = -10,}
elseif action == "page_jmp_back_1" then
result = {page_jmp = -1,}
elseif action == "next_chapter" then
result = {next_chapter = true,}
elseif action == "first_page" then
result = {first_page = true,}
elseif action == "last_page" then
result = {last_page = true,}
elseif action == "prev_chapter" then
result = {prev_chapter = true,}
elseif action == "next_bookmark" then
result = {next_bookmark = true,}
elseif action == "prev_bookmark" then
result = {prev_bookmark = true,}
elseif action == "go_to" then
result = {go_to = true,}
elseif action == "skim" then
result = {skim = true,}
elseif action == "back" then
result = { back = true,}
elseif action == "previous_location" then
result = {previous_location = true,}
elseif action == "latest_bookmark" then
result = {latest_bookmark = true,}
elseif action == "follow_nearest_link" then
result = {follow_nearest_link = true,}
elseif action == "follow_nearest_internal_link" then
result = {follow_nearest_internal_link = true,}
elseif action == "clear_location_history" then
result = {clear_location_history = true,}
elseif action == "filemanager" then
result = {filemanager = true,}
elseif action == "file_search" then
result = {file_search = true,}
elseif action == "folder_up" then
result = {folder_up = true,}
elseif action == "show_plus_menu" then
result = {show_plus_menu = true,}
elseif action == "folder_shortcuts" then
result = {folder_shortcuts = true,}
elseif action == "open_previous_document" then
result = {open_previous_document = true,}
elseif action == "dictionary_lookup" then
result = {dictionary_lookup = true,}
elseif action == "wikipedia_lookup" then
result = {wikipedia_lookup = true,}
elseif action == "fulltext_search" then
result = {fulltext_search = true,}
elseif action == "show_menu" then
result = {show_menu = true,}
elseif action == "show_config_menu" then
result = {show_config_menu = true,}
elseif action == "show_frontlight_dialog" then
result = {show_frontlight_dialog = true,}
elseif action == "increase_frontlight" then
result = {increase_frontlight = 0,}
elseif action == "decrease_frontlight" then
result = {decrease_frontlight = 0,}
elseif action == "increase_frontlight_warmth" then
result = {increase_frontlight_warmth = 0,}
elseif action == "decrease_frontlight_warmth" then
result = {decrease_frontlight_warmth = 0,}
elseif action == "toggle_bookmark" then
result = {toggle_bookmark = true,}
elseif action == "toggle_inverse_reading_order" then
result = {toggle_inverse_reading_order = true,}
elseif action == "toggle_frontlight" then
result = {toggle_frontlight = true,}
elseif action == "toggle_hold_corners" then
result = {toggle_hold_corners = true,}
elseif action == "toggle_gsensor" then
result = {toggle_gsensor = true,}
elseif action == "toggle_page_flipping" then
result = {toggle_page_flipping = true,}
elseif action == "toggle_reflow" then
result = {toggle_reflow = true,}
elseif action == "toggle_rotation" then
result = {toggle_rotation = true,}
elseif action == "toggle_wifi" then
result = {toggle_wifi = true,}
elseif action == "wifi_off" then
result = {wifi_off = true,}
elseif action == "wifi_on" then
result = {wifi_on = true,}
elseif action == "increase_font" then
result = {increase_font = 0,}
elseif action == "decrease_font" then
result = {decrease_font = 0,}
elseif action == "suspend" then
result = {suspend = true,}
elseif action == "exit" then
result = {exit = true,}
elseif action == "restart" then
result = {restart = true,}
elseif action == "reboot" then
result = {reboot = true,}
elseif action == "poweroff" then
result = {poweroff = true,}
elseif action == "zoom_contentwidth" then
result = {zoom = "contentwidth",}
elseif action == "zoom_contentheight" then
result = {zoom = "contentheight",}
elseif action == "zoom_pagewidth" then
result = {zoom = "pagewidth",}
elseif action == "zoom_pageheight" then
result = {zoom = "pageheight",}
elseif action == "zoom_column" then
result = {zoom = "column",}
elseif action == "zoom_content" then
result = {zoom = "content",}
elseif action == "zoom_page" then
result = {zoom = "page",}
elseif action == "wallabag_download" then
result = {wallabag_download = true,}
elseif action == "cycle_highlight_action" then
result = {cycle_highlight_action = true,}
elseif action == "cycle_highlight_style" then
result = {cycle_highlight_style = true,}
elseif action == "kosync_push_progress" then
result = {kosync_push_progress = true,}
elseif action == "kosync_pull_progress" then
result = {kosync_pull_progress = true,}
elseif action == "calibre_search" then
result = {calibre_search = true,}
elseif action == "calibre_browse_tags" then
result = {calibre_browse_tags = true,}
elseif action == "calibre_browse_series" then
result = {calibre_browse_series = true,}
else return end
location[ges] = result
end
function Migration:migrateGestures(caller)
for _, ges_mode in ipairs({"gesture_fm", "gesture_reader"}) do
for k, v in pairs(G_reader_settings:readSetting(ges_mode)) do
Migration:convertAction(caller.settings_data.data[ges_mode], k, v)
end
caller.settings_data:flush()
G_reader_settings:delSetting(ges_mode)
end
--custom multiswipes
for k, v in pairs(custom_multiswipes_table) do
local multiswipe = "multiswipe_" .. caller:safeMultiswipeName(v)
caller.settings_data.data.custom_multiswipes[multiswipe] = true
end
caller.settings_data:flush()
G_reader_settings:saveSetting("gestures_migrated", true)
end
return Migration
Loading…
Cancel
Save