-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
403 additions
and
597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Widget from 'resource:///com/github/Aylur/ags/widget.js'; | ||
import App from 'resource:///com/github/Aylur/ags/app.js'; | ||
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js'; | ||
|
||
const WINDOW_NAME = 'applauncher'; | ||
|
||
/** @param {import('resource:///com/github/Aylur/ags/service/applications.js').Application} app */ | ||
const AppItem = app => Widget.Button({ | ||
on_clicked: () => { | ||
App.closeWindow(WINDOW_NAME); | ||
app.launch(); | ||
}, | ||
attribute: { app }, | ||
child: Widget.Box({ | ||
children: [ | ||
Widget.Icon({ | ||
icon: app.icon_name || '', | ||
size: 42, | ||
}), | ||
Widget.Label({ | ||
class_name: 'title', | ||
label: app.name, | ||
xalign: 0, | ||
vpack: 'center', | ||
truncate: 'end', | ||
}), | ||
], | ||
}), | ||
}); | ||
|
||
const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => { | ||
// list of application buttons | ||
let applications = Applications.query('').map(AppItem); | ||
|
||
// container holding the buttons | ||
const list = Widget.Box({ | ||
vertical: true, | ||
children: applications, | ||
spacing, | ||
}); | ||
|
||
// repopulate the box, so the most frequent apps are on top of the list | ||
function repopulate() { | ||
applications = Applications.query('').map(AppItem); | ||
list.children = applications; | ||
} | ||
|
||
// search entry | ||
const entry = Widget.Entry({ | ||
hexpand: true, | ||
css: `margin-bottom: ${spacing}px;`, | ||
|
||
// to launch the first item on Enter | ||
on_accept: () => { | ||
if (applications[0]) { | ||
App.toggleWindow(WINDOW_NAME); | ||
applications[0].attribute.app.launch(); | ||
} | ||
}, | ||
|
||
// filter out the list | ||
on_change: ({ text }) => applications.forEach(item => { | ||
item.visible = item.attribute.app.match(text); | ||
}), | ||
}); | ||
|
||
return Widget.Box({ | ||
vertical: true, | ||
css: `margin: ${spacing * 2}px;`, | ||
children: [ | ||
entry, | ||
|
||
// wrap the list in a scrollable | ||
Widget.Scrollable({ | ||
hscroll: 'never', | ||
css: ` | ||
min-width: ${width}px; | ||
min-height: ${height}px; | ||
`, | ||
child: list, | ||
}), | ||
], | ||
setup: self => self.hook(App, (_, windowName, visible) => { | ||
if (windowName !== WINDOW_NAME) | ||
return; | ||
|
||
// when the applauncher shows up | ||
if (visible) { | ||
repopulate(); | ||
entry.text = ''; | ||
entry.grab_focus(); | ||
} | ||
}), | ||
}); | ||
}; | ||
|
||
// there needs to be only one instance | ||
export const applauncher = Widget.Window({ | ||
name: WINDOW_NAME, | ||
popup: true, | ||
visible: false, | ||
focusable: true, | ||
child: Applauncher({ | ||
width: 500, | ||
height: 500, | ||
spacing: 12, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.