indusy 2024-06-13 18:29:44 +08:00
parent 82077fc12a
commit 49851fe4c7
12 changed files with 112 additions and 17 deletions

2
define.d.ts vendored
View File

@ -1 +1 @@
export {}
export {};

View File

@ -7,6 +7,7 @@
"prebuild": "rimraf dist",
"build": "rollup -c",
"build:dev": "rollup -c --environment DEBUG",
"format": "prettier -c -w **/*.ts",
"test": "sh test.sh",
"push": "sh push.sh"
},
@ -15,6 +16,7 @@
"license": "ISC",
"packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631",
"devDependencies": {
"@girs/adw-1": "1.4.3-3.3.0",
"@girs/clutter-14": "14.0.0-4.0.0-beta.5",
"@girs/gio-2.0": "2.78.0-3.3.0",
"@girs/gjs": "^3.3.0",
@ -28,6 +30,7 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"rollup-plugin-copy": "^3.5.0",

View File

@ -8,6 +8,9 @@ importers:
.:
devDependencies:
'@girs/adw-1':
specifier: 1.4.3-3.3.0
version: 1.4.3-3.3.0
'@girs/clutter-14':
specifier: 14.0.0-4.0.0-beta.5
version: 14.0.0-4.0.0-beta.5
@ -47,6 +50,9 @@ importers:
'@rollup/plugin-terser':
specifier: ^0.4.4
version: 0.4.4(rollup@4.18.0)
prettier:
specifier: ^3.3.2
version: 3.3.2
rimraf:
specifier: ^5.0.7
version: 5.0.7
@ -68,6 +74,9 @@ packages:
'@girs/accountsservice-1.0@1.0.0-4.0.0-beta.5':
resolution: {integrity: sha512-+l+kEv7a54o8jMDtftOmOpOl0bG+2rLVaCf1LqQDyLeGe74tpVCeCGre4g27VyC4KI6dh5Tp2kOnzx4u4Q1+bw==}
'@girs/adw-1@1.4.3-3.3.0':
resolution: {integrity: sha512-BZBGnR+NjDyO4bUvY9WgWw2laFwVjNEye53NbyP/OyKgLViJmRd9eNdfb5743zLtjAvs3eB+5XIp1A5L0F9vqA==}
'@girs/adw-1@1.5.0-4.0.0-beta.5':
resolution: {integrity: sha512-bIndXhtH0jXL1che7tsfkdQd0rU0pnXuQTag/zeTSlVwOmkCF8RFASN96bHChK/npFaFQJ2psAu3L63sPob+3g==}
@ -700,6 +709,11 @@ packages:
resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}
engines: {node: '>=8'}
prettier@3.3.2:
resolution: {integrity: sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==}
engines: {node: '>=14'}
hasBin: true
queue-microtask@1.2.3:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
@ -861,6 +875,24 @@ snapshots:
'@girs/glib-2.0': 2.80.0-4.0.0-beta.5
'@girs/gobject-2.0': 2.80.0-4.0.0-beta.5
'@girs/adw-1@1.4.3-3.3.0':
dependencies:
'@girs/cairo-1.0': 1.0.0-4.0.0-beta.5
'@girs/freetype2-2.0': 2.0.0-4.0.0-beta.5
'@girs/gdk-4.0': 4.0.0-4.0.0-beta.5
'@girs/gdkpixbuf-2.0': 2.0.0-4.0.0-beta.5
'@girs/gio-2.0': 2.78.0-3.3.0
'@girs/gjs': 3.3.0
'@girs/glib-2.0': 2.78.0-3.3.0
'@girs/gmodule-2.0': 2.0.0-4.0.0-beta.5
'@girs/gobject-2.0': 2.78.0-3.3.0
'@girs/graphene-1.0': 1.0.0-4.0.0-beta.5
'@girs/gsk-4.0': 4.0.0-4.0.0-beta.5
'@girs/gtk-4.0': 4.12.5-3.3.0
'@girs/harfbuzz-0.0': 8.2.1-3.3.0
'@girs/pango-1.0': 1.51.0-3.3.0
'@girs/pangocairo-1.0': 1.0.0-4.0.0-beta.5
'@girs/adw-1@1.5.0-4.0.0-beta.5':
dependencies:
'@girs/cairo-1.0': 1.0.0-4.0.0-beta.5
@ -1830,6 +1862,8 @@ snapshots:
dependencies:
find-up: 4.1.0
prettier@3.3.2: {}
queue-microtask@1.2.3: {}
randombytes@2.1.0:

View File

@ -8,7 +8,7 @@ import json from "@rollup/plugin-json";
import terser from "@rollup/plugin-terser";
import typescript from "rollup-plugin-typescript2";
import copy from "rollup-plugin-copy";
import tsconfigPaths from 'rollup-plugin-tsconfig-paths'
import tsconfigPaths from "rollup-plugin-tsconfig-paths";
/** @type {(options: {matches: RegExp[]}) => import("rollup").Plugin} */
const excludeImports = (options) => {
@ -62,7 +62,18 @@ const config = defineConfig(() => {
],
};
return [extensionModule];
/** @type {import('rollup').RollupOptions} */
const prefsModule = {
input: "src/prefs.ts",
output: {
name: "[name].js",
dir: "dist",
format: "es",
},
plugins: [...commonPlugs],
};
return [extensionModule, prefsModule];
});
export default config;

View File

@ -1,10 +0,0 @@
import * as PopupMenu from "@girs/gnome-shell/ui/popupMenu";
import { registerGObjectClass } from "../utils/gjs";
@registerGObjectClass
export class Exit extends PopupMenu.PopupMenuItem {
constructor() {
super("退出");
}
}

View File

@ -16,7 +16,10 @@ import { ExtensionMetadata } from "@girs/gnome-shell/extensions/extension";
@registerGObjectClass
export class Indicator extends PanelMenu.Button {
metadata: ExtensionMetadata;
constructor(options: { metadata: ExtensionMetadata }) {
constructor(options: {
metadata: ExtensionMetadata;
openPreferences: () => void;
}) {
super(0.0, _("Clash Indicator"));
this.metadata = options.metadata;
@ -27,7 +30,7 @@ export class Indicator extends PanelMenu.Button {
})
);
this.menu = this.menu as PopupMenu.PopupMenu
this.menu = this.menu as PopupMenu.PopupMenu;
const enabler = new Enabler();
this.menu.addMenuItem(enabler);
@ -47,7 +50,7 @@ export class Indicator extends PanelMenu.Button {
const allowLAN = new AllowLAN();
this.menu.addMenuItem(allowLAN);
const settings = new Settings();
const settings = new Settings({ openPreferences: options.openPreferences });
this.menu.addMenuItem(settings);
const configure = new Configure({

View File

@ -4,7 +4,9 @@ import { registerGObjectClass } from "../utils/gjs";
@registerGObjectClass
export class Settings extends PopupMenu.PopupMenuItem {
constructor() {
constructor(options: { openPreferences: () => void }) {
super("打开设置面板");
this.connect('activate', options.openPreferences)
}
}

View File

@ -49,6 +49,7 @@ export default class ClashIndicatorExtension extends Extension {
enable() {
this.indicator = new Indicator({
metadata: this.metadata,
openPreferences: this.openPreferences.bind(this)
});
Main.panel.addToStatusArea(this.uuid, this.indicator);
}

View File

@ -0,0 +1,16 @@
import { Adw } from "@girs/adw-1";
import { Gtk } from "@girs/gtk-4.0";
import { registerGObjectClass } from "../../utils/gjs";
@registerGObjectClass
export class SwitchCore extends Adw.ComboRow {
constructor() {
super({ title: "切换内核" });
const options = ["clash-meta", "clash-meta-alpha"];
const coreOptions = new Gtk.StringList();
options.forEach(x => coreOptions.append(x));
this.model = coreOptions;
}
}

13
src/preferences/index.ts Normal file
View File

@ -0,0 +1,13 @@
import {Adw} from '@girs/adw-1'
import { registerGObjectClass } from "../utils/gjs";
import { UI } from './ui';
@registerGObjectClass
export class SettingsPage extends Adw.PreferencesPage {
constructor () {
super()
this.add(new UI())
}
}

12
src/preferences/ui.ts Normal file
View File

@ -0,0 +1,12 @@
import {Adw} from '@girs/adw-1'
import { registerGObjectClass } from '../utils/gjs'
import { SwitchCore } from './components/switch-core'
@registerGObjectClass
export class UI extends Adw.PreferencesGroup {
constructor () {
super({title: '界面设置'})
this.add(new SwitchCore())
}
}

10
src/prefs.ts Normal file
View File

@ -0,0 +1,10 @@
import { ExtensionPreferences } from "@girs/gnome-shell/extensions/prefs";
import { SettingsPage } from "./preferences";
export default class ClashIndicatorPreferences extends ExtensionPreferences {
fillPreferencesWindow(window: any) {
const page = new SettingsPage();
window.add(page);
}
}