Skip to content

Commit 1a960f3

Browse files
committed
fix: Fixed crash when no external links were saved
1 parent d36c86b commit 1a960f3

5 files changed

Lines changed: 17 additions & 22 deletions

File tree

backend/install_extension/extension_builder.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
-- Extension settings builder for Chrome preferences
22

33
local sys_utils = require("utils")
4-
local install_utils = require("install_extension.utils")
4+
local install_utils = require("install_extension.json_helpers")
5+
local json = require("json")
56

67
local M = {}
78

@@ -28,23 +29,23 @@ function M.build_extension_settings(extension_dir, manifest)
2829

2930
return {
3031
active_permissions = {
31-
api = #api_permissions > 0 and api_permissions or install_utils.empty_array(),
32+
api = #api_permissions > 0 and api_permissions or json.empty_array,
3233
explicit_host = { "<all_urls>" },
33-
manifest_permissions = install_utils.empty_array(),
34+
manifest_permissions = json.empty_array,
3435
scriptable_host = { "<all_urls>" },
3536
},
3637
commands = {},
37-
content_settings = install_utils.empty_array(),
38+
content_settings = json.empty_array,
3839
creation_flags = 38,
3940
first_install_time = file_time,
4041
from_webstore = false,
4142
granted_permissions = {
42-
api = #api_permissions > 0 and api_permissions or install_utils.empty_array(),
43+
api = #api_permissions > 0 and api_permissions or json.empty_array,
4344
explicit_host = { "<all_urls>" },
44-
manifest_permissions = install_utils.empty_array(),
45+
manifest_permissions = json.empty_array,
4546
scriptable_host = { "<all_urls>" },
4647
},
47-
incognito_content_settings = install_utils.empty_array(),
48+
incognito_content_settings = json.empty_array,
4849
incognito_preferences = {},
4950
last_update_time = file_time,
5051
location = 4, -- kUnpacked (developer mode)

backend/install_extension/utils.lua

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
local M = {}
44

5-
-- Helper to create empty arrays that serialize as [] not {}
6-
-- cjson treats tables with no elements ambiguously, this ensures array serialization
7-
function M.empty_array()
8-
local arr = {}
9-
setmetatable(arr, { __jsontype = "array" })
10-
return arr
11-
end
12-
135
-- Ensure nested table path exists, creating tables as needed
146
-- Usage: ensure_nested(t, "a", "b", "c") ensures t.a.b.c exists
157
function M.ensure_nested(t, ...)

backend/main.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function GetPluginDir()
1919
return fs.parent_path(backend_path)
2020
end
2121

22-
---@return table|string
22+
---@return string
2323
function GetExternalLinks()
2424
local plugin_dir = GetPluginDir()
2525
if not plugin_dir then
2626
logger:error("Failed to get plugin directory")
27-
return utils.empty_array()
27+
return "[]"
2828
end
2929

3030
local external_links_path = fs.join(plugin_dir, EXTENDIUM_EXTERNAL_LINKS_FILE)
@@ -38,7 +38,7 @@ function GetExternalLinks()
3838
end
3939
end
4040

41-
return utils.empty_array()
41+
return "[]"
4242
end
4343

4444
---@param external_links string

backend_lib/json.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ cjson_safe.null = cjson.null
8989
cjson_safe._NAME = cjson._NAME
9090
cjson_safe._VERSION = cjson._VERSION
9191

92+
---Create an empty JSON array
93+
---@type table # Empty JSON array
94+
cjson.empty_array = cjson.empty_array
95+
9296
return cjson

frontend/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ export default async function PluginMain(): Promise<void> {
3030
const { openLinksInCurrentTab } = useSettingsStore.getState();
3131
UpdateSettings({ settings: JSON.stringify({ openLinksInCurrentTab }) });
3232

33-
const extendiumInfo = await GetExtendiumInfo();
34-
if (extendiumInfo !== undefined) {
35-
initInfos(JSON.parse(extendiumInfo) as ExtendiumInfo);
36-
}
33+
const extendiumInfo = await GetExtendiumInfo() ?? '{}';
34+
initInfos(JSON.parse(extendiumInfo) as ExtendiumInfo);
3735

3836
const wnd = g_PopupManager.GetExistingPopup('SP Desktop_uid0');
3937
if (wnd) {

0 commit comments

Comments
 (0)