Skip to content

Commit

Permalink
Migrated from gi-types to girs
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Mar 10, 2024
1 parent 42b01b6 commit 5fbf4fd
Show file tree
Hide file tree
Showing 52 changed files with 1,036 additions and 766 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@gi-types/adw1": "^1.1.1",
"@gi-types/clutter10": "^10.0.1",
"@gi-types/gdk4": "^4.0.1",
"@gi-types/gdkpixbuf2": "^2.0.2",
"@gi-types/gio2": "^2.72.1",
"@gi-types/glib2": "^2.72.1",
"@gi-types/gobject2": "^2.72.1",
"@gi-types/gtk4": "^4.6.1",
"@gi-types/soup2": "^2.74.1",
"@gi-types/soup3": "^3.0.1",
"@gi-types/st1": "^1.0.1"
"@girs/adw-1": "^1.4.3-3.2.9",
"@girs/clutter-10": "^10.0.0-3.2.9",
"@girs/gdk-4.0": "^4.0.0-3.2.9",
"@girs/gdkpixbuf-2.0": "^2.0.0-3.2.9",
"@girs/gio-2.0": "^2.78.0-3.2.9",
"@girs/glib-2.0": "^2.78.0-3.2.9",
"@girs/gobject-2.0": "^2.78.0-3.2.9",
"@girs/gtk-4.0": "^4.12.5-3.2.9",
"@girs/soup-2.4": "^2.74.3-3.2.9",
"@girs/soup-3.0": "^3.4.4-3.2.9",
"@girs/st-1.0": "^1.0.0-3.2.9"
}
}
22 changes: 11 additions & 11 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ const metadata: ExtensionMetadata = JSON.parse(data) as ExtensionMetadata;

const globals = {
// Dirty hack to make class that require Adwaita to work even in Gnome < 42
'@gi-types/adw1': 'imports.gi.versions.Adw ? imports.gi.Adw : { ActionRow: imports.gi.Gtk.Widget }',
'@gi-types/clutter10': 'imports.gi.Clutter',
'@gi-types/gdk4': 'imports.gi.Gdk',
'@gi-types/gdkpixbuf2': 'imports.gi.GdkPixbuf',
'@gi-types/gio2': 'imports.gi.Gio',
'@gi-types/glib2': 'imports.gi.GLib',
'@gi-types/gobject2': 'imports.gi.GObject',
'@gi-types/gtk4': 'imports.gi.Gtk',
'@gi-types/soup2': 'imports.gi.Soup',
'@gi-types/soup3': 'imports.gi.Soup',
'@gi-types/st1': 'imports.gi.St',
'@girs/adw-1': 'imports.gi.versions.Adw ? imports.gi.Adw : { ActionRow: imports.gi.Gtk.Widget }',
'@girs/clutter-10': 'imports.gi.Clutter',
'@girs/gdk-4.0': 'imports.gi.Gdk',
'@girs/gdkpixbuf-2.0': 'imports.gi.GdkPixbuf',
'@girs/gio-2.0': 'imports.gi.Gio',
'@girs/glib-2.0': 'imports.gi.GLib',
'@girs/gobject-2.0': 'imports.gi.GObject',
'@girs/gtk-4.0': 'imports.gi.Gtk',
'@girs/soup-2.4': 'imports.gi.Soup',
'@girs/soup-3.0': 'imports.gi.Soup',
'@girs/st-1.0': 'imports.gi.St',
'@gnome-shell/misc/extensionUtils': 'imports.misc.extensionUtils',
'@gnome-shell/ui': 'imports.ui',
'@gnome-shell/ui/panel': 'imports.ui.panel',
Expand Down
6 changes: 3 additions & 3 deletions src/main/types/gnome-shell/misc/extensionUtils.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File, Settings } from '@gi-types/gio2';
import Gio from '@girs/gio-2.0';

export interface ExtensionMetadata {
uuid: string;
Expand All @@ -15,7 +15,7 @@ export interface Extension {
metadata: ExtensionMetadata;
uuid: string;
type: number;
dir: File;
dir: Gio.File;
path: string;
error: string;
hasPrefs: boolean;
Expand All @@ -27,4 +27,4 @@ export interface Extension {
export function initTranslations(domain: string): void;
export function openPrefs(): void;
export function getCurrentExtension(): Extension;
export function getSettings(name?: string): Settings;
export function getSettings(name?: string): Gio.Settings;
30 changes: 15 additions & 15 deletions src/main/types/gnome-shell/ui/messageTray.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Actor } from '@gi-types/clutter10';
import { Icon } from '@gi-types/gio2';
import { DateTime } from '@gi-types/glib2';
import { Object as GObject } from '@gi-types/gobject2';
import { Button, Widget } from '@gi-types/st1';
import Clutter from '@girs/clutter-10';
import Gio from '@girs/gio-2.0';
import GLib from '@girs/glib-2.0';
import GObject from '@girs/gobject-2.0';
import St from '@girs/st-1.0';

export interface NotificationProperties {
gicon: Icon;
secondaryGIcon: Icon;
gicon: Gio.Icon;
secondaryGIcon: Gio.Icon;
bannerMarkup: boolean;
clear: boolean;
datetime: DateTime;
datetime: GLib.DateTime;
soundName: string;
soundFile: string;
}

export class Notification extends GObject {
export class Notification extends GObject.Object {
public constructor(source: Source, title: string, banner: string, params?: Partial<NotificationProperties>);

public title: string;
Expand All @@ -33,18 +33,18 @@ export class Notification extends GObject {

// NotificationBanner actually extends Calendar.NotificationMessage but it's not needed for this project
export class NotificationBanner {
public addButton(button: Button, callback: () => void): Button;
public addAction(label: string, callback: () => void): Button;
public addButton(button: St.Button, callback: () => void): St.Button;
public addAction(label: string, callback: () => void): St.Button;
}

export class Source extends GObject {
export class Source extends GObject.Object {
public notifications: Notification[];

public constructor(title: string, iconName: string);

public open(): void;
public destroy(reson?: string): void;
public getIcon(): Icon;
public getIcon(): Gio.Icon;

public showNotification(notification: Notification): void;
public pushNotification(notification: Notification): void;
Expand All @@ -56,7 +56,7 @@ export class SystemNotificationSource extends Source {
public constructor();
}

export interface MessageTray extends Widget {
export interface MessageTray extends St.Widget {
add(source: Source): void;
contains(source: Source | Actor): boolean;
contains(source: Source | Clutter.Actor): boolean;
}
6 changes: 3 additions & 3 deletions src/main/types/gnome-shell/ui/panel.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BoxLayout, Widget } from '@gi-types/st1';
import St from '@girs/st-1.0';

import { Button } from './panelMenu';

export interface Panel extends Widget {
_rightBox: BoxLayout;
export interface Panel extends St.Widget {
_rightBox: St.BoxLayout;

addToStatusArea(role: string, indicator: Button, position?: number, box?: number): Button;
}
6 changes: 3 additions & 3 deletions src/main/types/gnome-shell/ui/panelMenu.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Widget } from '@gi-types/st1';
import St from '@girs/st-1.0';

export class ButtonBox extends Widget {}
export class ButtonBox extends St.Widget {}

export class Button extends ButtonBox {
public constructor(menuAlignment: number, nameText: string, dontCreateMenu: boolean);
public add_actor(widget: Widget): void;
public add_actor(widget: St.Widget): void;
}
16 changes: 8 additions & 8 deletions src/main/typescript/client/Soup2HttpEngine.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { MemoryUse, Message, Session, URI } from '@gi-types/soup2';
import Soup from '@girs/soup-2.4';

import { HttpEngine, HttpRequest, HttpResponse } from './Http';

export class Soup2HttpEngine implements HttpEngine {
private readonly session: Session;
private readonly session: Soup.Session;

public constructor(userAgent: string) {
this.session = new Session();
this.session.user_agent = `${userAgent} via Soup2`;
this.session = new Soup.Session();
this.session.userAgent = `${userAgent} via Soup2`;
}

public send(request: HttpRequest): Promise<HttpResponse> {
const soupUri = URI.new(request.url);
const message = new Message({ method: request.method, uri: soupUri });
const soupUri = Soup.URI.new(request.url);
const message = new Soup.Message({ method: request.method, uri: soupUri });

// Set the headers
request.headers.forEach((value: string, name: string) => message.requestHeaders.append(name, value));

// Set the request body, if available
if (request.body !== undefined) {
const encoder = new TextEncoder();
message.set_request(request.body.contentType, MemoryUse.COPY, encoder.encode(request.body.data));
message.set_request(request.body.contentType, Soup.MemoryUse.COPY, encoder.encode(request.body.data));
}

return new Promise<HttpResponse>((resolve, reject) => {
try {
this.session.queue_message(message, (_: Session, msg: Message) => {
this.session.queue_message(message, (_: Soup.Session, msg: Soup.Message) => {
const headers = new Map<string, string>();
msg.requestHeaders.foreach((name, value) => headers.set(name, value));

Expand Down
19 changes: 11 additions & 8 deletions src/main/typescript/client/Soup3HttpEngine.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import { Bytes, PRIORITY_DEFAULT, Uri } from '@gi-types/glib2';
import { HTTP_URI_FLAGS, Message, Session } from '@gi-types/soup3';
import GLib from '@girs/glib-2.0';
import Soup from '@girs/soup-3.0';

import { HttpEngine, HttpRequest, HttpResponse } from './Http';

export class Soup3HttpEngine implements HttpEngine {
private readonly session: Session;
private readonly session: Soup.Session;

public constructor(userAgent: string) {
this.session = new Session();
this.session.user_agent = `${userAgent} via Soup3`;
this.session = new Soup.Session();
this.session.userAgent = `${userAgent} via Soup3`;
}

public async send(request: HttpRequest): Promise<HttpResponse> {
const message = Message.new_from_uri(request.method, Uri.parse(request.url, HTTP_URI_FLAGS));
const message = Soup.Message.new_from_uri(request.method, GLib.Uri.parse(request.url, Soup.HTTP_URI_FLAGS));

// Set the headers
request.headers.forEach((value: string, name: string) => message.requestHeaders.append(name, value));

// Set the request body, if available
if (request.body !== undefined) {
const encoder = new TextEncoder();
message.set_request_body_from_bytes(request.body.contentType, new Bytes(encoder.encode(request.body.data)));
message.set_request_body_from_bytes(
request.body.contentType,
new GLib.Bytes(encoder.encode(request.body.data))
);
}

const responseBody: string = await this.session
.send_and_read_async(message, PRIORITY_DEFAULT, null)
.send_and_read_async(message, GLib.PRIORITY_DEFAULT, null)
.then((bytes) => bytes.get_data() ?? new Uint8Array())
.then((data) => new TextDecoder('utf-8').decode(data));

Expand Down
6 changes: 3 additions & 3 deletions src/main/typescript/core/GitHubManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon, icon_new_for_string } from '@gi-types/gio2';
import Gio from '@girs/gio-2.0';
import { getCurrentExtension, getSettings } from '@gnome-shell/misc/extensionUtils';

import { NotificationController } from '@github-manager/notifications';
Expand All @@ -10,7 +10,7 @@ export class GitHubManager implements Disposable {
@lazy
private static readonly LOGGER: Logger = new Logger('core::GitHubManager');

private readonly githubIcon: Icon;
private readonly githubIcon: Gio.Icon;

private readonly eventDispatcher: EventDispatcher;

Expand All @@ -23,7 +23,7 @@ export class GitHubManager implements Disposable {
public constructor() {
GitHubManager.LOGGER.trace('Building and wiring components');

this.githubIcon = icon_new_for_string(`${getCurrentExtension().path}/github.svg`);
this.githubIcon = Gio.icon_new_for_string(`${getCurrentExtension().path}/github.svg`);

this.eventDispatcher = new EventDispatcher();
this.settings = new SettingsWrapper(getSettings(), this.eventDispatcher);
Expand Down
17 changes: 2 additions & 15 deletions src/main/typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import GObject from '@girs/gobject-2.0';

Check failure on line 1 in src/main/typescript/index.d.ts

View workflow job for this annotation

GitHub Actions / Static analysis with ESLint

'GObject' is defined but never used

export {};

declare global {
Expand All @@ -15,18 +17,3 @@ declare global {
export function log(message: string): void;
export function logError(e: unknown, message: string): void;
}

declare module '@gi-types/gobject2' {
export interface MetaInfo {
GTypeName: string;
GTypeFlags?: TypeFlags;
Implements?: { $gtype: GType }[];
Properties?: Record<string, ParamSpec>;
Signals?: Record<string, SignalDefinition>;
Requires?: { $gtype: GType }[];
CssName?: string;
Template?: string;
Children?: string[];
InternalChildren?: string[];
}
}
18 changes: 9 additions & 9 deletions src/main/typescript/notifications/NotificationAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon, icon_new_for_string } from '@gi-types/gio2';
import Gio from '@girs/gio-2.0';
import { Source, Notification as UINotification } from '@gnome-shell/ui/messageTray';

import { GitHub } from '@github-manager/client';
Expand All @@ -10,15 +10,15 @@ import { NotificationAction } from './actions/NotificationAction';

@registerGObject
class DigestSource extends Source {
private readonly icon: Icon;
private readonly icon: Gio.Icon;

public constructor(icon: Icon) {
public constructor(icon: Gio.Icon) {
super('Github Notifications', '');

this.icon = icon;
}

public getIcon(): Icon {
public getIcon(): Gio.Icon {
return this.icon;
}

Expand All @@ -30,17 +30,17 @@ class DigestSource extends Source {
@registerGObject
class ProjectSource extends Source {
private readonly avatarUrl: string;
private icon?: Icon;
private icon?: Gio.Icon;

public constructor(projectName: string, avatarUrl: string) {
super(projectName, '');

this.avatarUrl = avatarUrl;
}

public getIcon(): Icon {
public getIcon(): Gio.Icon {
if (this.icon === undefined) {
this.icon = icon_new_for_string(this.avatarUrl);
this.icon = Gio.icon_new_for_string(this.avatarUrl);
}

return this.icon;
Expand All @@ -60,11 +60,11 @@ export class NotificationAdapter {

private _secondaryAction?: NotificationAction;

private readonly digestIcon: Icon;
private readonly digestIcon: Gio.Icon;

public constructor(
notificationMode: NotificationMode,
digestIcon: Icon,
digestIcon: Gio.Icon,
activateAction?: NotificationAction,
primaryAction?: NotificationAction,
secondaryAction?: NotificationAction
Expand Down
4 changes: 2 additions & 2 deletions src/main/typescript/notifications/NotificationController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon } from '@gi-types/gio2';
import Gio from '@girs/gio-2.0';
import { main as ShellUI } from '@gnome-shell/ui';
import { Notification } from '@gnome-shell/ui/messageTray';

Expand All @@ -25,7 +25,7 @@ export class NotificationController {

private notifications: GitHub.Thread[];

public constructor(settings: SettingsWrapper, eventDispatcher: EventDispatcher, gitHubIcon: Icon) {
public constructor(settings: SettingsWrapper, eventDispatcher: EventDispatcher, gitHubIcon: Gio.Icon) {
this.settings = settings;
this.eventDispatcher = eventDispatcher;

Expand Down
Loading

0 comments on commit 5fbf4fd

Please sign in to comment.