Skip to content

Commit 866b7e1

Browse files
mmstickjackpot51
authored andcommitted
feat(launcher): Implement help plugin
1 parent 6fc020d commit 866b7e1

File tree

4 files changed

+103
-45
lines changed

4 files changed

+103
-45
lines changed

src/dialog_launcher.ts

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -77,54 +77,56 @@ export class Launcher extends search.Search {
7777

7878
const pattern = pat.toLowerCase()
7979

80-
const needles = pattern.split(' ');
80+
if (pat !== '?') {
81+
const needles = pattern.split(' ');
8182

82-
const contains_pattern = (haystack: string, needles: Array<string>): boolean => {
83-
const hay = haystack.toLowerCase();
84-
return needles.every((n) => hay.includes(n));
85-
};
83+
const contains_pattern = (haystack: string, needles: Array<string>): boolean => {
84+
const hay = haystack.toLowerCase();
85+
return needles.every((n) => hay.includes(n));
86+
};
8687

87-
// Filter matching windows
88-
for (const window of ext.tab_list(Meta.TabList.NORMAL, null)) {
89-
const retain = contains_pattern(window.name(ext), needles)
90-
|| contains_pattern(window.meta.get_title(), needles);
88+
// Filter matching windows
89+
for (const window of ext.tab_list(Meta.TabList.NORMAL, null)) {
90+
const retain = contains_pattern(window.name(ext), needles)
91+
|| contains_pattern(window.meta.get_title(), needles);
9192

92-
if (retain) {
93-
windows.push(window_selection(ext, window, this.icon_size()))
93+
if (retain) {
94+
windows.push(window_selection(ext, window, this.icon_size()))
95+
}
9496
}
95-
}
96-
97-
// Filter matching desktop apps
98-
for (const [where, app] of this.desktop_apps) {
99-
const name = app.name()
100-
const keywords = app.keywords()
101-
const exec = app.exec()
102-
103-
let app_items = name.split(' ')
104-
if (keywords !== null) app_items = app_items.concat(keywords)
105-
if (exec !== null) app_items = app_items.concat(exec)
106-
107-
for (const item of app_items) {
108-
const item_match = item.toLowerCase()
109-
if ( item_match.startsWith(pattern)
110-
|| item_match.includes(pattern)
111-
|| levenshtein.compare(item_match, pattern) < 3) {
112-
const generic = app.generic_name();
113-
const button = new launch.SearchOption(
114-
name,
115-
generic ? generic + " — " + where : where,
116-
'new-window-symbolic',
117-
{ gicon: app.icon() },
118-
this.icon_size(),
119-
{ app },
120-
exec,
121-
keywords
122-
)
123-
124-
DedicatedGPU.addPopup(app, button.widget)
12597

126-
this.options.push(button)
127-
break
98+
// Filter matching desktop apps
99+
for (const [where, app] of this.desktop_apps) {
100+
const name = app.name()
101+
const keywords = app.keywords()
102+
const exec = app.exec()
103+
104+
let app_items = name.split(' ')
105+
if (keywords !== null) app_items = app_items.concat(keywords)
106+
if (exec !== null) app_items = app_items.concat(exec)
107+
108+
for (const item of app_items) {
109+
const item_match = item.toLowerCase()
110+
if ( item_match.startsWith(pattern)
111+
|| item_match.includes(pattern)
112+
|| levenshtein.compare(item_match, pattern) < 3) {
113+
const generic = app.generic_name();
114+
const button = new launch.SearchOption(
115+
name,
116+
generic ? generic + " — " + where : where,
117+
'new-window-symbolic',
118+
{ gicon: app.icon() },
119+
this.icon_size(),
120+
{ app },
121+
exec,
122+
keywords
123+
)
124+
125+
DedicatedGPU.addPopup(app, button.widget)
126+
127+
this.options.push(button)
128+
break
129+
}
128130
}
129131
}
130132
}

src/dialog_search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Search {
6060
x_expand: true
6161
});
6262

63-
this.entry.set_hint_text(' Type to search apps')
63+
this.entry.set_hint_text(' Type to search apps. Press \'?\' for more options')
6464

6565
this.text = this.entry.get_clutter_text();
6666
(this.text as any).set_use_markup(true)

src/launcher_service.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ const { Plugin } = plugins
1414

1515
import * as plugin_scripts from 'plugin_scripts'
1616
import * as plugin_shell from 'plugin_shell'
17+
import * as plugin_help from 'plugin_help'
18+
19+
const BUILTIN_HELP: PluginType.Source = {
20+
backend: {
21+
builtin: new plugin_help.ShellBuiltin()
22+
},
23+
config: {
24+
name: "Shell Help",
25+
description: "Show additional prefixes available",
26+
pattern: "",
27+
exec: "",
28+
icon: "system-help-symbolic"
29+
},
30+
pattern: null
31+
};
1732

1833
export var BUILTINS: Array<PluginType.Source> = [
1934
{
@@ -55,7 +70,7 @@ const LOCAL_PLUGINS: string = GLib.get_home_dir() + "/.local/share/pop-shell/lau
5570
const SYSTEM_PLUGINS: string = "/usr/lib/pop-shell/launcher/"
5671

5772
export class LauncherService {
58-
private plugins: Map<string, PluginType.Source> = new Map()
73+
plugins: Map<string, PluginType.Source> = new Map()
5974

6075
destroy(ext: Ext) {
6176
for (const plugin of this.plugins.values()) Plugin.quit(ext, plugin)
@@ -124,6 +139,11 @@ export class LauncherService {
124139
}
125140

126141
private *match_query(ext: Ext, query: string): IterableIterator<PluginType.Source> {
142+
if (query === "?") {
143+
yield BUILTIN_HELP;
144+
return
145+
}
146+
127147
for (const plugin of BUILTINS) {
128148
if (!plugin.pattern || plugin.pattern.test(query)) {
129149
yield plugin

src/plugin_help.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @ts-ignore
2+
const Me = imports.misc.extensionUtils.getCurrentExtension()
3+
4+
import * as plugins from 'launcher_plugins'
5+
6+
import type { Response, Selection } from 'launcher_plugins'
7+
import type { Ext } from './extension'
8+
9+
export class ShellBuiltin extends plugins.Builtin {
10+
init() {}
11+
12+
query(ext :Ext, _: string): Response.Response {
13+
let selections = []
14+
let id = 0;
15+
16+
for (const [name, service] of ext.window_search.service.plugins) {
17+
if (service.config.pattern?.length > 0) {
18+
selections.push({
19+
id,
20+
name,
21+
description: service.config.description + `: ${service.config.pattern}`,
22+
})
23+
id += 1;
24+
}
25+
}
26+
27+
return {
28+
event: "queried",
29+
selections
30+
}
31+
}
32+
33+
submit(ext: Ext, id: number): Response.Response {
34+
return { event: "fill", text: "" }
35+
}
36+
}

0 commit comments

Comments
 (0)