diff options
| author | srdusr <trevorgray@srdusr.com> | 2024-06-13 13:11:05 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2024-06-13 13:11:05 +0200 |
| commit | d0fbb19623e4fb6097e1ff3ee49c6a76a0928d0e (patch) | |
| tree | 937531ddf423d3935c6e20c8a9227e39ce782241 /.config/ags/lib/iconUtils.js | |
| parent | 4ccbe0270c25ecab492508b5b0209ae53b9c35bd (diff) | |
| download | dotfiles-d0fbb19623e4fb6097e1ff3ee49c6a76a0928d0e.tar.gz dotfiles-d0fbb19623e4fb6097e1ff3ee49c6a76a0928d0e.zip | |
Add ags
Diffstat (limited to '.config/ags/lib/iconUtils.js')
| -rw-r--r-- | .config/ags/lib/iconUtils.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/.config/ags/lib/iconUtils.js b/.config/ags/lib/iconUtils.js new file mode 100644 index 0000000..db79553 --- /dev/null +++ b/.config/ags/lib/iconUtils.js @@ -0,0 +1,48 @@ +const { Gio, Gdk, Gtk } = imports.gi; + +function fileExists(filePath) { + let file = Gio.File.new_for_path(filePath); + return file.query_exists(null); +} + +//计算多个数组的笛卡尔积 +function cartesianProduct(arrays) { + if (arrays.length === 0) { + return [[]]; + } + + const [head, ...tail] = arrays; + const tailCartesian = cartesianProduct(tail); + const result = []; + + for (const item of head) { + for (const tailItem of tailCartesian) { + result.push([item, ...tailItem]); + } + } + return result; +} + +export const find_icon = app_class => { + //主题路径 x 可能的尺寸大小 x apps x app的名称 x icon文件类型 + const themPath = [ + ['/usr/share/icons/WhiteSur/', '/usr/share/icons/WhiteSur-dark/'], + ['512x512/', '128x128/', '64x64/', '96x96/', '72x72/', '48x48/', '36x36/'], + ['apps/', ''], + [app_class + '.png', app_class + '.svg', app_class + '.xpm'], + ]; + + let real_path = ''; + const all_icon_dir = cartesianProduct(themPath); + + for (let index = 0; index < all_icon_dir.length; index++) { + const pathItem = all_icon_dir[index]; + const icon_path = pathItem.join(''); + if (fileExists(icon_path)) { + real_path = icon_path; + break; + } + } + + return real_path; +}; |
