Update google search app widget

This commit is contained in:
Evgeny
2025-07-15 21:03:39 +08:00
parent 4d3ee33c01
commit 51f0eac6ee

View File

@@ -2,9 +2,9 @@
-- description = "AIO wrapper for the Google search app widget - open widget settings for options" -- description = "AIO wrapper for the Google search app widget - open widget settings for options"
-- type = "widget" -- type = "widget"
-- author = "Theodor Galanis (t.me/TheodorGalanis)" -- author = "Theodor Galanis (t.me/TheodorGalanis)"
-- version = "2.7" -- version = "2.8"
-- foldable = "false" -- foldable = "false"
-- uses_app: "com.google.android.googlequicksearchbox" -- uses_app = "com.google.android.googlequicksearchbox"
local prefs = require "prefs" local prefs = require "prefs"
@@ -16,78 +16,78 @@ function on_alarm()
setup_app_widget() setup_app_widget()
end end
if not prefs.mode then if not prefs.mode then
prefs.mode = 1 prefs.mode = 1
end end
mode = prefs.mode mode = prefs.mode
indices = set_indices() indices = set_indices()
widgets:request_updates(prefs.wid) widgets:request_updates(prefs.wid, "4x1")
end end
function on_app_widget_updated(bridge) function on_app_widget_updated(bridge)
w_bridge = bridge w_bridge = bridge
local tab = { local tab = {
{"button", "fa:magnifying-glass", {expand = true}}, {"button", "fa:magnifying-glass", {expand = true}},
{"spacer", 2}, {"spacer", 2},
{"button", "fa:sun-cloud"}, {"button", "fa:sun-cloud"},
{"spacer", 2}, {"spacer", 2},
{"button", "fa:asterisk"}, {"button", "fa:asterisk"},
{"spacer", 2}, {"spacer", 2},
{"button", "fa:microphone"}, {"button", "fa:microphone"},
{"spacer", 2}, {"spacer", 2},
{"button", "fa:camera"} {"button", "fa:camera"}
} }
tab = set_gui(tab) tab = set_gui(tab)
my_gui = gui(tab) my_gui = gui(tab)
my_gui.render() my_gui.render()
end end
function on_click(idx) function on_click(idx)
if idx == indices[1] then if idx == indices[1] then
w_bridge:click("image_4") w_bridge:click("image_2")
elseif idx == indices[2] then elseif idx == indices[2] then
intent:start_activity(open_weather()) intent:start_activity(open_weather())
elseif idx == indices[3] then elseif idx == indices[3] then
w_bridge:click("image_7") w_bridge:click("image_3")
elseif idx == indices[4] then elseif idx == indices[4] then
w_bridge:click("image_11") w_bridge:click("image_5")
elseif idx == indices[5] then elseif idx == indices[5] then
w_bridge:click("image_12") w_bridge:click("image_6")
else return else return
end end
end end
function on_settings() function on_settings()
local tab = {"Left-handed mode with weather", "Left-handed mode, no weather", "Right-handed mode with weather", "Right-handed mode, no weather" } local tab = {"Left-handed mode with weather", "Left-handed mode, no weather", "Right-handed mode with weather", "Right-handed mode, no weather" }
dialogs:show_radio_dialog("Select mode", tab, mode) dialogs:show_radio_dialog("Select mode", tab, mode)
end end
function on_long_click(idx) function on_long_click(idx)
if idx == indices[1] then if idx == indices[1] then
ui:show_toast("Google search") ui:show_toast("Google search")
elseif idx == indices[2] then elseif idx == indices[2] then
ui:show_toast("Google weather") ui:show_toast("Google weather")
elseif idx == indices[3] then elseif idx == indices[3] then
ui:show_toast("Google discover") ui:show_toast("Google discover")
elseif idx == indices[4] then elseif idx == indices[4] then
ui:show_toast("Google voice search") ui:show_toast("Google voice search")
elseif idx == indices[5] then elseif idx == indices[5] then
ui:show_toast("Google Lens") ui:show_toast("Google Lens")
end end
end end
function on_dialog_action(data) function on_dialog_action(data)
if data == -1 then if data == -1 then
return return
end end
prefs.mode = data prefs.mode = data
on_alarm() on_alarm()
end end
function setup_app_widget() function setup_app_widget()
local id = widgets:setup("com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.SearchWidgetProvider") local id = widgets:setup("com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.SearchWidgetProvider")
if (id ~= nil) then if (id ~= nil) then
prefs.wid = id prefs.wid = id
else else
ui:show_text("Can't add widget") ui:show_text("Can't add widget")
@@ -96,33 +96,33 @@ function setup_app_widget()
end end
function set_indices() function set_indices()
local temp = {1, 3, 5, 7, 9} local temp = {1, 3, 5, 7, 9}
if mode == 2 then if mode == 2 then
temp = {1, 9, 3, 5, 7} temp = {1, 9, 3, 5, 7}
elseif mode == 3 then elseif mode == 3 then
temp = reverse (temp) temp = reverse (temp)
elseif mode == 4 then elseif mode == 4 then
temp = {7, 9, 5, 3, 1} temp = {7, 9, 5, 3, 1}
end end
return temp return temp
end end
function set_gui(tab) function set_gui(tab)
local temp = tab local temp = tab
if mode == 2 or mode == 4 then if mode == 2 or mode == 4 then
table.remove(tab, 3) table.remove(tab, 3)
table.remove(tab, 3) table.remove(tab, 3)
end end
if mode > 2 then if mode > 2 then
temp = reverse(temp) temp = reverse(temp)
end end
return temp return temp
end end
function open_weather() function open_weather()
local tab ={} local tab ={}
tab.category = "MAIN" tab.category = "MAIN"
tab.package = "com.google.android.googlequicksearchbox" tab.package = "com.google.android.googlequicksearchbox"
tab.component = "com.google.android.googlequicksearchbox/com.google.android.apps.search.weather.WeatherExportedActivity" tab.component = "com.google.android.googlequicksearchbox/com.google.android.apps.search.weather.WeatherExportedActivity"
return tab return tab
end end