refactor(ags): replace imports file with imports from ressource directly

This commit is contained in:
matt1432 2023-10-31 08:32:40 -04:00
parent 297e274c9a
commit 4ff3dbbc1c
43 changed files with 137 additions and 144 deletions

View file

@ -1,28 +1,29 @@
// Has to be a traditional function for 'this' scope
Array.prototype.remove = function (el) { this.splice(this.indexOf(el), 1); };
import { App, Utils } from './imports.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
import { exec, execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import closeAll from './js/misc/closer.js';
import closeAll from './js/misc/closer.js';
globalThis.closeAll = closeAll;
import Powermenu from './js/powermenu.js';
import * as Bar from './js/bar/main.js';
import NotifCenter from './js/notifications/center.js';
import NotifPopups from './js/notifications/popup.js';
import Calendar from './js/date.js';
import QuickSettings from './js/quick-settings/main.js';
import Overview from './js/overview/main.js';
import AppLauncher from './js/applauncher/main.js';
import * as Corners from './js/screen-corners.js';
import Powermenu from './js/powermenu.js';
import * as Bar from './js/bar/main.js';
import NotifCenter from './js/notifications/center.js';
import NotifPopups from './js/notifications/popup.js';
import Calendar from './js/date.js';
import QuickSettings from './js/quick-settings/main.js';
import Overview from './js/overview/main.js';
import AppLauncher from './js/applauncher/main.js';
import * as Corners from './js/screen-corners.js';
const scss = App.configDir + '/scss/main.scss';
const css = App.configDir + '/style.css';
Utils.exec(`sassc ${scss} ${css}`);
exec(`sassc ${scss} ${css}`);
Utils.execAsync(['bash', '-c', '$AGS_PATH/startup.sh']).catch(print);
execAsync(['bash', '-c', '$AGS_PATH/startup.sh']).catch(print);
export default {

View file

@ -1,19 +0,0 @@
const resource = file => `resource:///com/github/Aylur/ags/${file}.js`;
const require = async file => (await import(resource(file))).default;
const service = async file => (await require(`service/${file}`));
export const App = await require('app');
export const Widget = await require('widget');
export const Service = await require('service');
export const Variable = await require('variable');
export const Utils = await import(resource('utils'));
export const Applications = await service('applications');
export const Audio = await service('audio');
export const Battery = await service('battery');
export const Bluetooth = await service('bluetooth');
export const Hyprland = await service('hyprland');
export const Mpris = await service('mpris');
export const Network = await service('network');
export const Notifications = await service('notifications');
export const SystemTray = await service('systemtray');

View file

@ -1,5 +1,8 @@
import { App, Applications, Utils, Widget } from '../../imports.js';
const { Label, Box, Icon, Button, Scrollable, Entry } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
import { Label, Box, Icon, Button, Scrollable, Entry } from 'resource:///com/github/Aylur/ags/widget.js';
import { exec } from 'resource:///com/github/Aylur/ags/utils.js';
import Separator from '../misc/separator.js';
import PopupWindow from '../misc/popup.js';
@ -20,7 +23,7 @@ const AppItem = (app, window) => {
className: 'app',
connections: [['clicked', () => {
App.closeWindow(window);
Utils.exec(`hyprctl dispatch exec ${app.executable}`);
exec(`hyprctl dispatch exec ${app.executable}`);
// TODO: focus on new client. Is this only needed after launch?
++app.frequency;
}]],

View file

@ -1,5 +1,5 @@
import { Audio, Widget } from '../../imports.js';
const { Label, Box, Icon } = Widget;
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import { Label, Box, Icon } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,5 @@
import { Battery, Widget } from '../../imports.js';
const { Label, Icon, Stack, Box } = Widget;
import Battery from 'resource:///com/github/Aylur/ags/service/battery.js';
import { Label, Icon, Stack, Box } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';

View file

@ -1,5 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { ProgressBar, Overlay, Box } = Widget;
import { ProgressBar, Overlay, Box } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import Separator from '../misc/separator.js';
import Heart from './heart.js';
@ -11,7 +11,7 @@ export default () => Overlay({
className: 'toggle-off brightness',
connections: [
[200, self => {
Utils.execAsync('brightnessctl get').then(out => {
execAsync('brightnessctl get').then(out => {
const br = out / 255;
if (br > 0.33)
self.value = br;

View file

@ -1,5 +1,5 @@
import { App, Widget } from '../../imports.js';
const { Box, Label } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import GLib from 'gi://GLib';
const { DateTime } = GLib;

View file

@ -1,5 +1,5 @@
import { Widget, Hyprland } from '../../imports.js';
const { Label } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Label } from 'resource:///com/github/Aylur/ags/widget.js';
export default () => Label({

View file

@ -1,5 +1,9 @@
import { App, Widget, Hyprland, Utils, Variable } from '../../imports.js';
const { Box, EventBox, Overlay } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
import { Widget, Box, EventBox, Overlay } from 'resource:///com/github/Aylur/ags/widget.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { RoundedCorner } from '../screen-corners.js';
import Gesture from './gesture.js';
@ -40,7 +44,7 @@ export default props => Overlay({
BgGradient.visible = !Revealed.value;
if (Revealed.value) {
Utils.timeout(2000, () => {
timeout(2000, () => {
if (Revealed.value)
self.revealChild = false;
});
@ -55,7 +59,7 @@ export default props => Overlay({
onHoverLost: self => {
Hovering.value = false;
if (Revealed.value) {
Utils.timeout(2000, () => {
timeout(2000, () => {
if (!Hovering.value) {
self.get_parent().get_parent().children[1].revealChild = true;
self.get_parent().revealChild = false;
@ -70,7 +74,7 @@ export default props => Overlay({
Widget.Revealer({
connections: [[Revealed, self => {
if (Revealed.value) {
Utils.timeout(2000, () => {
timeout(2000, () => {
if (Revealed.value)
self.revealChild = true;
});

View file

@ -1,5 +1,5 @@
import { Widget, App } from '../../imports.js';
const { CenterBox, EventBox } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import { CenterBox, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';

View file

@ -1,6 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { Box, Label } = Widget;
const { subprocess, execAsync } = Utils;
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { subprocess, execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,6 @@
import { Hyprland, Utils, Widget } from '../../imports.js';
const { Label, Box, Icon } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { exec } from 'resource:///com/github/Aylur/ags/utils.js';
import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js';
const DEFAULT_KB = 'at-translated-set-2-keyboard';
@ -13,7 +14,7 @@ export default () => Box({
Label({
connections: [[Hyprland, (self, _n, layout) => {
if (!layout) {
const obj = Utils.exec('hyprctl devices -j');
const obj = exec('hyprctl devices -j');
const keyboards = JSON.parse(obj)['keyboards'];
const kb = keyboards.find(val => val.name === DEFAULT_KB);

View file

@ -1,5 +1,4 @@
import { Widget } from '../../imports.js';
const { Window, CenterBox, Box } = Widget;
import { Window, CenterBox, Box } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';
import CurrentWindow from './current-window.js';

View file

@ -1,5 +1,6 @@
import { App, Notifications, Widget } from '../../imports.js';
const { Box, Label, Icon } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
import { Box, Icon, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,6 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { Box, Label } = Widget;
const { subprocess } = Utils;
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,5 @@
import { Widget, App } from '../../imports.js';
const { Box, Label } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,6 @@
import { SystemTray, Utils, Widget } from '../../imports.js';
const { Box, Revealer, Icon, MenuItem } = Widget;
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Box, Icon, MenuItem, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';
@ -44,7 +45,7 @@ const SysTray = () => {
return;
widget._items.get(id).child.revealChild = false;
Utils.timeout(400, () => {
timeout(400, () => {
widget._items.get(id).destroy();
widget._items.delete(id);
});

View file

@ -1,6 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { Box, Label } = Widget;
const { subprocess } = Utils;
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,6 +1,6 @@
import { Hyprland, Utils, Widget } from '../../imports.js';
const { Box, Overlay, Revealer } = Widget;
const { execAsync } = Utils;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import { Box, Overlay, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,4 @@
import { Widget } from '../imports.js';
const { Box, Label } = Widget;
import { Widget, Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';
import GLib from 'gi://GLib';

View file

@ -1,5 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { Box, Overlay, EventBox } = Widget;
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import { Box, EventBox, Overlay } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';
@ -73,7 +73,7 @@ export default ({
opacity: 0;
${playerBox._bgStyle}`);
}
Utils.timeout(500, () => {
timeout(500, () => {
overlay.reorder_overlay(playerBox, 0);
playerBox.setStyle(playerBox._bgStyle);
overlay._selected = overlay.list().at(-1);

View file

@ -1,6 +1,6 @@
import { Mpris, Utils, Widget } from '../../imports.js';
const { Button, Icon, Label, Stack, Slider, CenterBox, Box } = Widget;
const { execAsync, lookUpIcon } = Utils;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import { Button, Icon, Label, Stack, Slider, CenterBox, Box } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync, lookUpIcon } from 'resource:///com/github/Aylur/ags/utils.js';
import Gdk from 'gi://Gdk';
const display = Gdk.Display.get_default();

View file

@ -1,5 +1,6 @@
import { Mpris, Variable, Widget } from '../../imports.js';
const { Box, CenterBox } = Widget;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
import { Box, CenterBox } from 'resource:///com/github/Aylur/ags/widget.js';
import * as mpris from './mpris.js';
import PlayerGesture from './gesture.js';

View file

@ -1,4 +1,4 @@
import { App } from '../../imports.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
// TODO: find a way to not need this?
import Pointers from '../../services/pointers.js';

View file

@ -1,4 +1,4 @@
import { Widget } from '../../imports.js';
import { Widget } from 'resource:///com/github/Aylur/ags/widget.js';
import Gdk from 'gi://Gdk';
const display = Gdk.Display.get_default();

View file

@ -1,6 +1,5 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
const { Revealer, Box, Window } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import { Revealer, Box, Window } from 'resource:///com/github/Aylur/ags/widget.js';
export default ({

View file

@ -1,5 +1,4 @@
import { Widget } from '../../imports.js';
const { Box } = Widget;
import { Box } from 'resource:///com/github/Aylur/ags/widget.js';
export default (size, { vertical = false } = {}) => {

View file

@ -1,6 +1,6 @@
import { Applications, Utils, Widget } from '../../imports.js';
const { lookUpIcon, execAsync } = Utils;
const { Box, Icon, Label, Button } = Widget;
import Applications from 'resource:///com/github/Aylur/ags/service/applications.js';
import { Box, Icon, Label, Button } from 'resource:///com/github/Aylur/ags/widget.js';
import { lookUpIcon, execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import GLib from 'gi://GLib';

View file

@ -1,6 +1,7 @@
import { Notifications, App, Utils, Widget } from '../../imports.js';
const { Button, Label, Box, Icon, Scrollable, Revealer } = Widget;
const { timeout } = Utils;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
import { Button, Label, Box, Icon, Scrollable, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import Notification from './base.js';
import PopupWindow from '../misc/popup.js';

View file

@ -1,5 +1,5 @@
import { Utils, Widget } from '../../imports.js';
const { Box, EventBox } = Widget;
import { Box, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
import { timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import Gtk from 'gi://Gtk';
import Gdk from 'gi://Gdk';
@ -97,14 +97,14 @@ export default ({
margin-right: ${Number(maxOffset + endMargin)}px;
margin-bottom: 0px; margin-top: 0px; opacity: 0;`);
Utils.timeout(500, () => {
timeout(500, () => {
self.setStyle(`transition: margin 0.5s ease, opacity 0.5s ease;
margin-left: ${startMargin}px;
margin-right: ${startMargin}px;
margin-bottom: unset; margin-top: unset;
opacity: 1;`);
});
Utils.timeout(1000, () => self._ready = true);
timeout(1000, () => self._ready = true);
return;
}
@ -114,18 +114,18 @@ export default ({
if (offset > 0) {
self.setStyle(rightAnim1);
widget.sensitive = false;
Utils.timeout(500, () => {
timeout(500, () => {
self.setStyle(rightAnim2);
});
}
else {
self.setStyle(leftAnim1);
widget.sensitive = false;
Utils.timeout(500, () => {
timeout(500, () => {
self.setStyle(leftAnim2);
});
}
Utils.timeout(1000, () => {
timeout(1000, () => {
command();
self.destroy();
});

View file

@ -1,5 +1,6 @@
import { Notifications, Utils, Widget } from '../../imports.js';
const { Box, Revealer, Window } = Widget;
import Notifications from 'resource:///com/github/Aylur/ags/service/notifications.js';
import { Box, Revealer, Window } from 'resource:///com/github/Aylur/ags/widget.js';
import { interval, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import GLib from 'gi://GLib';
@ -18,7 +19,7 @@ const Popups = () => Box({
if (box._map.size - 1 === 0)
box.get_parent().reveal_child = false;
Utils.timeout(200, () => {
timeout(200, () => {
const notif = box._map.get(id);
if (notif.interval) {
GLib.source_remove(notif.interval);
@ -44,17 +45,17 @@ const Popups = () => Box({
box.children = Array.from(box._map.values()).reverse();
Utils.timeout(10, () => {
timeout(10, () => {
box.get_parent().revealChild = true;
});
box._map.get(id).interval = Utils.interval(4500, () => {
box._map.get(id).interval = interval(4500, () => {
const notif = box._map.get(id);
if (!notif._hovered) {
notif.child.setStyle(notif.child._leftAnim1);
if (notif.interval) {
Utils.timeout(500, () => notif.destroy());
timeout(500, () => notif.destroy());
GLib.source_remove(notif.interval);
notif.interval = undefined;
}

View file

@ -1,6 +1,7 @@
import { App, Hyprland, Utils, Widget } from '../../imports.js';
const { Icon, Revealer } = Widget;
const { execAsync } = Utils;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Icon, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import { WindowButton } from './dragndrop.js';
import * as VARS from './variables.js';

View file

@ -1,5 +1,5 @@
import { Hyprland, Widget } from '../../imports.js';
const { Box } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Box } from 'resource:///com/github/Aylur/ags/widget.js';
import * as VARS from './variables.js';
const DEFAULT_STYLE = `

View file

@ -1,6 +1,6 @@
import { App, Utils, Widget } from '../../imports.js';
const { EventBox } = Widget;
const { execAsync } = Utils;
import App from 'resource:///com/github/Aylur/ags/app.js';
import { EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import Gtk from 'gi://Gtk';
import Gdk from 'gi://Gdk';

View file

@ -1,5 +1,6 @@
import { App, Hyprland, Widget } from '../../imports.js';
const { Box, Overlay } = Widget;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Box, Overlay } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from '../misc/popup.js';
import { WorkspaceRow, getWorkspaces, updateWorkspaces } from './workspaces.js';

View file

@ -1,5 +1,5 @@
import { Hyprland, Widget } from '../../imports.js';
const { Revealer, CenterBox, Box, EventBox, Label, Overlay } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { Revealer, CenterBox, Box, EventBox, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';

View file

@ -1,5 +1,4 @@
import { Widget } from '../imports.js';
const { CenterBox, Label } = Widget;
import { CenterBox, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import PopupWindow from './misc/popup.js';
import Button from './misc/cursorbox.js';

View file

@ -1,6 +1,9 @@
import { Network, Bluetooth, Audio, App, Utils, Widget } from '../../imports.js';
const { Box, CenterBox, Label, Icon } = Widget;
const { execAsync } = Utils;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js';
import Network from 'resource:///com/github/Aylur/ags/service/network.js';
import { Box, CenterBox, Label, Icon } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import EventBox from '../misc/cursorbox.js';

View file

@ -1,5 +1,4 @@
import { Widget } from '../../imports.js';
const { Box, Label, Revealer } = Widget;
import { Box, Label, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
import ButtonGrid from './button-grid.js';
import SliderBox from './slider-box.js';

View file

@ -1,6 +1,6 @@
import { Audio, Utils, Widget } from '../../imports.js';
const { Box, Slider, Icon, EventBox } = Widget;
const { execAsync } = Utils;
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import { Box, Slider, Icon, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
const items = {
101: 'audio-volume-overamplified-symbolic',

View file

@ -1,8 +1,8 @@
import { Mpris, Widget } from '../../imports.js';
const { Icon } = Widget;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import { Icon } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';
import EventBox from '../misc/cursorbox.js';
import EventBox from '../misc/cursorbox.js';
export default () => {
const widget = EventBox({});

View file

@ -1,5 +1,5 @@
import { Widget } from '../imports.js';
const { Gtk } = imports.gi;
import { Widget } from 'resource:///com/github/Aylur/ags/widget.js';
import Gtk from 'gi://Gtk';
const Lang = imports.lang;
export const RoundedCorner = (place, props) => Widget.Box({

View file

@ -1,4 +1,6 @@
import { App, Service, Utils } from '../imports.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
import Service from 'resource:///com/github/Aylur/ags/service.js';
import { execAsync, subprocess } from 'resource:///com/github/Aylur/ags/utils.js';
import GUdev from 'gi://GUdev';
const UDEV_POINTERS = [
@ -85,7 +87,7 @@ class Pointers extends Service {
args.push(dev);
});
this.proc = Utils.subprocess(
this.proc = subprocess(
['libinput', 'debug-events', ...args],
output => {
if (output.includes('cancelled'))
@ -145,10 +147,10 @@ class Pointers extends Service {
if (!toClose)
return;
Utils.execAsync('hyprctl layers -j').then(layers => {
execAsync('hyprctl layers -j').then(layers => {
layers = JSON.parse(layers);
Utils.execAsync('hyprctl cursorpos -j').then(pos => {
execAsync('hyprctl cursorpos -j').then(pos => {
pos = JSON.parse(pos);
Object.values(layers).forEach(key => {