-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
firefox: fix search engine icons #6505
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,11 +12,8 @@ let | |||||||||||||||||
"name" | ||||||||||||||||||
"isAppProvided" | ||||||||||||||||||
"loadPath" | ||||||||||||||||||
"hasPreferredIcon" | ||||||||||||||||||
"updateInterval" | ||||||||||||||||||
"updateURL" | ||||||||||||||||||
"iconUpdateURL" | ||||||||||||||||||
"iconURL" | ||||||||||||||||||
"iconMapObj" | ||||||||||||||||||
"metaData" | ||||||||||||||||||
"orderHint" | ||||||||||||||||||
|
@@ -26,23 +23,25 @@ let | |||||||||||||||||
searchForm = "__searchForm"; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
# Convenience to specify absolute path to icon | ||||||||||||||||||
iconUrl = icon: if hasPrefix "/" icon then "file://${icon}" else icon; | ||||||||||||||||||
|
||||||||||||||||||
processCustomEngineInput = input: | ||||||||||||||||||
(removeAttrs input [ "icon" ]) // optionalAttrs (input ? icon) { | ||||||||||||||||||
# Convenience to specify absolute path to icon | ||||||||||||||||||
iconURL = "file://${input.icon}"; | ||||||||||||||||||
} // (optionalAttrs (input ? iconUpdateURL) { | ||||||||||||||||||
# Convenience to default iconURL to iconUpdateURL so | ||||||||||||||||||
# the icon is immediately downloaded from the URL | ||||||||||||||||||
iconURL = input.iconURL or input.iconUpdateURL; | ||||||||||||||||||
} // { | ||||||||||||||||||
let | ||||||||||||||||||
iconMapObj = mapAttrs (name: iconUrl) (optionalAttrs (input ? icon) { | ||||||||||||||||||
# Convenience to specify single icon instead of map | ||||||||||||||||||
"16" = input.icon; | ||||||||||||||||||
} // (input.iconMapObj or { })); | ||||||||||||||||||
in (removeAttrs input [ "icon" "iconMapObj" ]) | ||||||||||||||||||
// optionalAttrs (iconMapObj != { }) { inherit iconMapObj; } // { | ||||||||||||||||||
# Required for custom engine configurations, loadPaths | ||||||||||||||||||
# are unique identifiers that are generally formatted | ||||||||||||||||||
# like: [source]/path/to/engine.xml | ||||||||||||||||||
loadPath = "[home-manager]/${ | ||||||||||||||||||
concatStringsSep "." (map strings.escapeNixIdentifier | ||||||||||||||||||
(modulePath ++ [ "engines" input.name ])) | ||||||||||||||||||
}"; | ||||||||||||||||||
}); | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
processEngineInput = name: input: | ||||||||||||||||||
let | ||||||||||||||||||
|
@@ -55,7 +54,11 @@ let | |||||||||||||||||
in if requiredInput.isAppProvided then | ||||||||||||||||||
requiredInput | ||||||||||||||||||
else | ||||||||||||||||||
processCustomEngineInput (input // requiredInput); | ||||||||||||||||||
pipe (input // requiredInput) [ | ||||||||||||||||||
migrateEngineToV11 | ||||||||||||||||||
migrateEngineToV12 | ||||||||||||||||||
processCustomEngineInput | ||||||||||||||||||
]; | ||||||||||||||||||
|
||||||||||||||||||
buildEngineConfig = name: input: | ||||||||||||||||||
mapAttrs' (name: value: { | ||||||||||||||||||
|
@@ -89,7 +92,7 @@ let | |||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
settings = { | ||||||||||||||||||
version = 6; | ||||||||||||||||||
version = 12; | ||||||||||||||||||
engines = sortEngineConfigs (mapAttrs buildEngineConfig engineInput); | ||||||||||||||||||
|
||||||||||||||||||
metaData = optionalAttrs (config.default != null) { | ||||||||||||||||||
|
@@ -155,6 +158,37 @@ let | |||||||||||||||||
mozlz4a <(echo "$json") "$out" | ||||||||||||||||||
fi | ||||||||||||||||||
''; | ||||||||||||||||||
|
||||||||||||||||||
migrateEngineToV11 = engine: | ||||||||||||||||||
engine // { | ||||||||||||||||||
iconMapObj = mapAttrs' (name: value: | ||||||||||||||||||
let nameToIntResult = builtins.tryEval (toInt name); | ||||||||||||||||||
in { | ||||||||||||||||||
name = if nameToIntResult.success then | ||||||||||||||||||
name | ||||||||||||||||||
else | ||||||||||||||||||
let size = toString (builtins.fromJSON name).width; | ||||||||||||||||||
in warn | ||||||||||||||||||
"JSON object names for iconMapObj are deprecated, use ${size} instead of ${name}" | ||||||||||||||||||
size; | ||||||||||||||||||
|
||||||||||||||||||
inherit value; | ||||||||||||||||||
}) (engine.iconMapObj or { }); | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
migrateEngineToV12 = engine: | ||||||||||||||||||
throwIf (engine ? hasPreferredIcon) "hasPreferredIcon has been removed" | ||||||||||||||||||
(removeAttrs engine [ "iconURL" "iconUpdateURL" ]) // { | ||||||||||||||||||
iconMapObj = optionalAttrs (engine ? iconURL) { | ||||||||||||||||||
"16" = warn "iconURL is deprecated, use icon = ${ | ||||||||||||||||||
strings.escapeNixString engine.iconURL | ||||||||||||||||||
} instead" engine.iconURL; | ||||||||||||||||||
Comment on lines
+183
to
+185
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.
Suggested change
|
||||||||||||||||||
} // optionalAttrs (engine ? iconUpdateURL) { | ||||||||||||||||||
"16" = warn "iconUpdateURL is deprecated, use icon = ${ | ||||||||||||||||||
strings.escapeNixString engine.iconUpdateURL | ||||||||||||||||||
} instead" engine.iconUpdateURL; | ||||||||||||||||||
} // (engine.iconMapObj or { }); | ||||||||||||||||||
Comment on lines
+187
to
+190
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.
Suggested change
|
||||||||||||||||||
}; | ||||||||||||||||||
in { | ||||||||||||||||||
imports = [ (pkgs.path + "/nixos/modules/misc/meta.nix") ]; | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -229,8 +263,8 @@ in { | |||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
"NixOS Wiki" = { | ||||||||||||||||||
urls = [{ template = "https://wiki.nixos.org/index.php?search={searchTerms}"; }]; | ||||||||||||||||||
iconUpdateURL = "https://wiki.nixos.org/favicon.png"; | ||||||||||||||||||
urls = [{ template = "https://wiki.nixos.org/w/index.php?search={searchTerms}"; }]; | ||||||||||||||||||
iconMapObj."16" = "https://wiki.nixos.org/favicon.png"; | ||||||||||||||||||
updateInterval = 24 * 60 * 60 * 1000; # every day | ||||||||||||||||||
definedAliases = [ "@nw" ]; | ||||||||||||||||||
}; | ||||||||||||||||||
|
@@ -245,7 +279,7 @@ in { | |||||||||||||||||
only have {var}`metaData` specified will be treated as builtin | ||||||||||||||||||
to ${appName}. | ||||||||||||||||||
|
||||||||||||||||||
See [SearchEngine.jsm](https://searchfox.org/mozilla-central/rev/669329e284f8e8e2bb28090617192ca9b4ef3380/toolkit/components/search/SearchEngine.jsm#1138-1177) | ||||||||||||||||||
See [SearchEngine.jsm](https://searchfox.org/mozilla-central/rev/e3f42ec9320748b2aab3d474d1e47075def9000c/toolkit/components/search/SearchEngine.sys.mjs#890-923) | ||||||||||||||||||
in ${appName}'s source for available options. We maintain a | ||||||||||||||||||
mapping to let you specify all options in the referenced link | ||||||||||||||||||
without underscores, but it may fall out of date with future | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -53,9 +53,9 @@ in { | |||||
"NixOS Wiki" = { | ||||||
urls = [{ | ||||||
template = | ||||||
"https://wiki.nixos.org/index.php?search={searchTerms}"; | ||||||
"https://wiki.nixos.org/w/index.php?search={searchTerms}"; | ||||||
}]; | ||||||
iconUpdateURL = "https://wiki.nixos.org/favicon.png"; | ||||||
iconMapObj."16" = "https://wiki.nixos.org/favicon.png"; | ||||||
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. this was inherited from the previous code, but while it's being updated anyways: 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. oh yep thanks for catching that! 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.
Suggested change
|
||||||
updateInterval = 24 * 60 * 60 * 1000; | ||||||
definedAliases = [ "@nw" ]; | ||||||
}; | ||||||
|
@@ -92,6 +92,46 @@ in { | |||||
}; | ||||||
}; | ||||||
}; | ||||||
|
||||||
migrateIcons = { | ||||||
id = 2; | ||||||
search = { | ||||||
force = true; | ||||||
engines = { | ||||||
"Nix Packages" = { | ||||||
urls = [{ | ||||||
template = "https://search.nixos.org/packages"; | ||||||
params = [ | ||||||
{ | ||||||
name = "type"; | ||||||
value = "packages"; | ||||||
} | ||||||
{ | ||||||
name = "query"; | ||||||
value = "{searchTerms}"; | ||||||
} | ||||||
]; | ||||||
}]; | ||||||
|
||||||
iconURL = "https://search.nixos.org/favicon.png"; | ||||||
iconUpdateURL = "https://search.nixos.org/favicon.png"; | ||||||
definedAliases = [ "@np" ]; | ||||||
}; | ||||||
|
||||||
"NixOS Wiki" = { | ||||||
urls = [{ | ||||||
template = | ||||||
"https://wiki.nixos.org/w/index.php?search={searchTerms}"; | ||||||
}]; | ||||||
iconMapObj."{\"width\":16,\"height\":16}" = | ||||||
"https://wiki.nixos.org/favicon.png"; | ||||||
updateInterval = 24 * 60 * 60 * 1000; | ||||||
definedAliases = [ "@nw" ]; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
|
||||||
}; | ||||||
}; | ||||||
} // { | ||||||
nmt.script = let | ||||||
|
@@ -133,6 +173,10 @@ in { | |||||
assertFirefoxSearchContent \ | ||||||
home-files/${cfg.configPath}/searchWithoutDefault/search.json.mozlz4 \ | ||||||
${withName ./expected-search-without-default.json} | ||||||
|
||||||
assertFirefoxSearchContent \ | ||||||
home-files/${cfg.configPath}/migrateIcons/search.json.mozlz4 \ | ||||||
${withName ./expected-migrate-icons.json} | ||||||
''; | ||||||
}); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"engines": [ | ||
{ | ||
"_definedAliases": [ | ||
"@np" | ||
], | ||
"_iconMapObj": { | ||
"16": "https://search.nixos.org/favicon.png" | ||
}, | ||
"_isAppProvided": false, | ||
"_loadPath": "[home-manager]/programs.@[email protected].\"Nix Packages\"", | ||
"_metaData": {}, | ||
"_name": "Nix Packages", | ||
"_urls": [ | ||
{ | ||
"params": [ | ||
{ | ||
"name": "type", | ||
"value": "packages" | ||
}, | ||
{ | ||
"name": "query", | ||
"value": "{searchTerms}" | ||
} | ||
], | ||
"template": "https://search.nixos.org/packages" | ||
} | ||
] | ||
}, | ||
{ | ||
"_definedAliases": [ | ||
"@nw" | ||
], | ||
"_iconMapObj": { | ||
"16": "https://wiki.nixos.org/favicon.png" | ||
}, | ||
"_isAppProvided": false, | ||
"_loadPath": "[home-manager]/programs.@[email protected].\"NixOS Wiki\"", | ||
"_metaData": {}, | ||
"_name": "NixOS Wiki", | ||
"_updateInterval": 86400000, | ||
"_urls": [ | ||
{ | ||
"template": "https://wiki.nixos.org/w/index.php?search={searchTerms}" | ||
} | ||
] | ||
} | ||
], | ||
"metaData": { | ||
"useSavedOrder": false | ||
}, | ||
"version": 12 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,5 @@ | |
"metaData": { | ||
"useSavedOrder": true | ||
}, | ||
"version": 6 | ||
"version": 12 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
"_definedAliases": [ | ||
"@np" | ||
], | ||
"_iconURL": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg", | ||
"_iconMapObj": { | ||
"16": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg" | ||
}, | ||
"_isAppProvided": false, | ||
"_loadPath": "[home-manager]/programs.@[email protected].\"Nix Packages\"", | ||
"_metaData": { | ||
|
@@ -31,8 +33,9 @@ | |
"_definedAliases": [ | ||
"@nw" | ||
], | ||
"_iconURL": "https://wiki.nixos.org/favicon.png", | ||
"_iconUpdateURL": "https://wiki.nixos.org/favicon.png", | ||
"_iconMapObj": { | ||
"16": "https://wiki.nixos.org/favicon.png" | ||
}, | ||
"_isAppProvided": false, | ||
"_loadPath": "[home-manager]/programs.@[email protected].\"NixOS Wiki\"", | ||
"_metaData": { | ||
|
@@ -42,7 +45,7 @@ | |
"_updateInterval": 86400000, | ||
"_urls": [ | ||
{ | ||
"template": "https://wiki.nixos.org/index.php?search={searchTerms}" | ||
"template": "https://wiki.nixos.org/w/index.php?search={searchTerms}" | ||
} | ||
] | ||
}, | ||
|
@@ -73,5 +76,5 @@ | |
"privateHash": null, | ||
"useSavedOrder": true | ||
}, | ||
"version": 6 | ||
"version": 12 | ||
} |
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.