@gjsify/adwaita-app 0.64.6 → 0.64.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -67,7 +67,13 @@ promise-job queue under `run()`).
67
67
  `flags`, `css`, `about` (`AboutInfo`) or `aboutAppdata`
68
68
  (`CreateAboutDialogOptions`, see below), `quitAction` (default on, `<primary>q`),
69
69
  `devtools` (`true` | `InstallDevtoolsOptions` | omitted = env-gated),
70
- `bundledIcons` (default on — see below), `onStartup`.
70
+ `bundledIcons` (default on — see below), `iconDir`, `onStartup`.
71
+ `iconDir` is the app's own `data/icons` root. An app run from its build tree
72
+ has no launcher exporting `XDG_DATA_DIRS`, so GTK cannot find the app icon
73
+ (the About dialog shows an empty square). On `startup`, when the icon theme
74
+ lacks the app icon, the dir is added: `iconDir`, else `GJSIFY_ICON_DIR`, else
75
+ the nearest `data/icons` within six levels above the bundle. No-op when the
76
+ icon already resolves.
71
77
  - `AdwaitaApp` — the configured `Adw.Application` subclass, if you need the
72
78
  instance instead of `runAdwaitaApp`.
73
79
 
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{lastPathSeparatorIndex as e}from"@gjsify/utils/core";const t=6;function resolveIconDir(e={}){let t=nonEmpty(e.iconDir)??nonEmpty(e.env?.GJSIFY_ICON_DIR);if(t!==void 0)return t;if(!(e.startDir===void 0||e.isDirectory===void 0))return searchUp(e.startDir,e.isDirectory)}function bundleDirFromUrl(t){if(t===void 0||!t.startsWith(`file://`))return;let n=decodeURIComponent(new URL(t).pathname),r=e(n);if(!(r<0))return r===0?`/`:n.slice(0,r)}function searchUp(t,n){let r=t;for(let t=0;t<6;t++){let t=`${r===`/`?``:r}/data/icons`;if(n(t))return t;let i=e(r);if(i<=0){if(r===`/`)break;r=`/`}else r=r.slice(0,i)}}function nonEmpty(e){if(e===void 0)return;let t=e.trim();return t===``?void 0:t}export{t as ICON_DIR_SEARCH_DEPTH,bundleDirFromUrl,resolveIconDir};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{bundleDirFromUrl as e,resolveIconDir as t}from"./app-icon-dir.js";import n from"gi://GLib?version=2.0";function addAppIconDir(r,i,a={}){if(r.has_icon(i))return!1;let o=t({iconDir:a.iconDir,env:{GJSIFY_ICON_DIR:n.getenv(`GJSIFY_ICON_DIR`)??void 0},startDir:a.startDir??e(import.meta.url),isDirectory:e=>n.file_test(e,n.FileTest.IS_DIR)});return o===void 0?!1:(r.add_search_path(o),!0)}export{addAppIconDir};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{applyAboutLinks as e,createAboutDialog as t}from"./about-dialog.js";import{installBundledIconTheme as n}from"./icon-theme.js";import r from"gi://Adw?version=1";import i from"gi://Gio?version=2.0";import a from"gi://Gtk?version=4.0";import o from"gi://Gdk?version=4.0";import s from"gi://GObject?version=2.0";import c from"system";import{installDevtools as l}from"@gjsify/devtools";var u=class AdwaitaApp extends r.Application{static{s.registerClass({GTypeName:`GjsifyAdwaitaApp`},AdwaitaApp)}constructor(e){super({application_id:e.applicationId,flags:e.flags??i.ApplicationFlags.DEFAULT_FLAGS}),this._window=null,this._options=e,this._initActions(),this.connect(`startup`,()=>this._onStartup()),this.connect(`activate`,()=>this._onActivate())}_initActions(){if(this._options.quitAction!==!1){let e=new i.SimpleAction({name:`quit`});e.connect(`activate`,()=>this.quit()),this.add_action(e),this.set_accels_for_action(`app.quit`,[`<primary>q`])}if(this._options.about||this._options.aboutAppdata){let e=new i.SimpleAction({name:`about`});e.connect(`activate`,()=>this._showAbout()),this.add_action(e)}}_onStartup(){this._installBundledIcons(),this._options.css&&this._loadCss(this._options.css),this._installDevtools(),this._options.onStartup?.(this)}_installBundledIcons(){let e=this._options.bundledIcons;e!==!1&&n(typeof e==`object`?e:{})}_loadCss(e){let t=o.Display.get_default();if(!t){console.error(`@gjsify/adwaita-app: no default display; CSS not applied`);return}let n=new a.CssProvider;n.load_from_string(e),a.StyleContext.add_provider_for_display(t,n,a.STYLE_PROVIDER_PRIORITY_APPLICATION)}_installDevtools(){let e=this._options.devtools;if(e===!1)return;let t=typeof e==`object`?e:{enabled:e||void 0};l(this,t)}_onActivate(){this._window||=this._options.createWindow(this),this._window.present()}_showAbout(){let n=this._options.aboutAppdata;if(n){t(n).present(this.get_active_window());return}let i=this._options.about;if(!i)return;let a=new r.AboutDialog({application_name:i.applicationName,application_icon:i.applicationIcon??this._options.applicationId});i.version&&(a.version=i.version),i.developerName&&(a.developer_name=i.developerName),i.website&&(a.website=i.website),i.issueUrl&&(a.issue_url=i.issueUrl),i.license&&(a.license=i.license),i.comments&&(a.comments=i.comments),i.copyright&&(a.copyright=i.copyright),i.developers?.length&&a.set_developers(i.developers),e(a,i.links),a.present(this.get_active_window())}};async function runAdwaitaApp(e){return runApplication(new u(e),[c.programInvocationName,...c.programArgs])}async function runApplication(e,t){let n=!1;try{e.register(null),n=e.get_is_remote()}catch{n=!1}let r=await e.runAsync(t);return n&&console.error(`${e.applicationId??`This application`} is already running — brought the existing instance to the front instead of opening a second window.`),r}s.type_ensure(u.$gtype);export{u as AdwaitaApp,runAdwaitaApp,runApplication};
1
+ import"./_virtual/_rolldown/runtime.js";import{applyAboutLinks as e,createAboutDialog as t}from"./about-dialog.js";import{addAppIconDir as n}from"./app-icon.js";import{installBundledIconTheme as r}from"./icon-theme.js";import i from"gi://Adw?version=1";import a from"gi://Gio?version=2.0";import o from"gi://Gtk?version=4.0";import s from"gi://Gdk?version=4.0";import c from"gi://GObject?version=2.0";import l from"system";import{installDevtools as u}from"@gjsify/devtools";var d=class AdwaitaApp extends i.Application{static{c.registerClass({GTypeName:`GjsifyAdwaitaApp`},AdwaitaApp)}constructor(e){super({application_id:e.applicationId,flags:e.flags??a.ApplicationFlags.DEFAULT_FLAGS}),this._window=null,this._options=e,this._initActions(),this.connect(`startup`,()=>this._onStartup()),this.connect(`activate`,()=>this._onActivate())}_initActions(){if(this._options.quitAction!==!1){let e=new a.SimpleAction({name:`quit`});e.connect(`activate`,()=>this.quit()),this.add_action(e),this.set_accels_for_action(`app.quit`,[`<primary>q`])}if(this._options.about||this._options.aboutAppdata){let e=new a.SimpleAction({name:`about`});e.connect(`activate`,()=>this._showAbout()),this.add_action(e)}}_onStartup(){this._installBundledIcons(),this._installAppIcon(),this._options.css&&this._loadCss(this._options.css),this._installDevtools(),this._options.onStartup?.(this)}_installBundledIcons(){let e=this._options.bundledIcons;e!==!1&&r(typeof e==`object`?e:{})}_installAppIcon(){let e=s.Display.get_default();e&&n(o.IconTheme.get_for_display(e),this._options.about?.applicationIcon??this._options.applicationId,{iconDir:this._options.iconDir})}_loadCss(e){let t=s.Display.get_default();if(!t){console.error(`@gjsify/adwaita-app: no default display; CSS not applied`);return}let n=new o.CssProvider;n.load_from_string(e),o.StyleContext.add_provider_for_display(t,n,o.STYLE_PROVIDER_PRIORITY_APPLICATION)}_installDevtools(){let e=this._options.devtools;if(e===!1)return;let t=typeof e==`object`?e:{enabled:e||void 0};u(this,t)}_onActivate(){this._window||=this._options.createWindow(this),this._window.present()}_showAbout(){let n=this._options.aboutAppdata;if(n){t(n).present(this.get_active_window());return}let r=this._options.about;if(!r)return;let a=new i.AboutDialog({application_name:r.applicationName,application_icon:r.applicationIcon??this._options.applicationId});r.version&&(a.version=r.version),r.developerName&&(a.developer_name=r.developerName),r.website&&(a.website=r.website),r.issueUrl&&(a.issue_url=r.issueUrl),r.license&&(a.license=r.license),r.comments&&(a.comments=r.comments),r.copyright&&(a.copyright=r.copyright),r.developers?.length&&a.set_developers(r.developers),e(a,r.links),a.present(this.get_active_window())}};async function runAdwaitaApp(e){return runApplication(new d(e),[l.programInvocationName,...l.programArgs])}async function runApplication(e,t){let n=!1;try{e.register(null),n=e.get_is_remote()}catch{n=!1}let r=await e.runAsync(t);return n&&console.error(`${e.applicationId??`This application`} is already running — brought the existing instance to the front instead of opening a second window.`),r}c.type_ensure(d.$gtype);export{d as AdwaitaApp,runAdwaitaApp,runApplication};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{appdataLocale as e,parseAppdata as t}from"./appdata.js";import{applyAppdataFields as n,buildAboutDialogFromAppdata as r,createAboutDialog as i,hasAppdataConstructor as a,licenseTypeFor as o}from"./about-dialog.js";import{BUNDLED_ICON_COUNT as s,BUNDLED_ICON_RESOURCE_PATH as c}from"./icons.generated.js";import{BUNDLED_ICON_THEME_NAME as l,addBundledIconsToTheme as u,installBundledIconTheme as d,registerBundledIconResource as f}from"./icon-theme.js";import{AdwaitaApp as p,runAdwaitaApp as m,runApplication as h}from"./application.js";import{readAppDevHooks as g}from"./dev-hooks.js";import{confirmDialog as _,errorDialog as v}from"./dialogs.js";import{pickFile as y,saveFile as b}from"./file-dialog.js";import{createNavShell as x}from"./nav-shell.js";import{LoadToken as S,loadIntoStack as C}from"./view-loader.js";import{LoadingStack as w}from"./loading-stack.js";import{registerToastOverlay as T,showToast as E}from"./toast.js";import{SYSTEM_LOCALE_DIR as D,resolveLocaleDir as O,systemLocaleDir as k}from"./locale-dir.js";import{LOCALE_ENV_VARS as A,localeEnvToSet as j,posixLocale as M}from"./locale-env.js";import{initLocale as N}from"./locale.js";import{APPLE_ACCENT_COLOR_ARGV as P,MACOS_ACCENT_POLL_SECONDS as F,onMacosAccentColorChanged as I,readMacosAccentColor as L}from"./system-accent.js";import{findNavItem as R,resolveInitialNavIndex as z}from"./nav-model.js";export{P as APPLE_ACCENT_COLOR_ARGV,p as AdwaitaApp,s as BUNDLED_ICON_COUNT,c as BUNDLED_ICON_RESOURCE_PATH,l as BUNDLED_ICON_THEME_NAME,A as LOCALE_ENV_VARS,S as LoadToken,w as LoadingStack,F as MACOS_ACCENT_POLL_SECONDS,D as SYSTEM_LOCALE_DIR,u as addBundledIconsToTheme,e as appdataLocale,n as applyAppdataFields,r as buildAboutDialogFromAppdata,_ as confirmDialog,i as createAboutDialog,x as createNavShell,v as errorDialog,R as findNavItem,a as hasAppdataConstructor,N as initLocale,d as installBundledIconTheme,o as licenseTypeFor,C as loadIntoStack,j as localeEnvToSet,I as onMacosAccentColorChanged,t as parseAppdata,y as pickFile,M as posixLocale,g as readAppDevHooks,L as readMacosAccentColor,f as registerBundledIconResource,T as registerToastOverlay,z as resolveInitialNavIndex,O as resolveLocaleDir,m as runAdwaitaApp,h as runApplication,b as saveFile,E as showToast,k as systemLocaleDir};
1
+ import{appdataLocale as e,parseAppdata as t}from"./appdata.js";import{applyAppdataFields as n,buildAboutDialogFromAppdata as r,createAboutDialog as i,hasAppdataConstructor as a,licenseTypeFor as o}from"./about-dialog.js";import{ICON_DIR_SEARCH_DEPTH as s,bundleDirFromUrl as c,resolveIconDir as l}from"./app-icon-dir.js";import{BUNDLED_ICON_COUNT as u,BUNDLED_ICON_RESOURCE_PATH as d}from"./icons.generated.js";import{BUNDLED_ICON_THEME_NAME as f,addBundledIconsToTheme as p,installBundledIconTheme as m,registerBundledIconResource as h}from"./icon-theme.js";import{AdwaitaApp as g,runAdwaitaApp as _,runApplication as v}from"./application.js";import{readAppDevHooks as y}from"./dev-hooks.js";import{confirmDialog as b,errorDialog as x}from"./dialogs.js";import{pickFile as S,saveFile as C}from"./file-dialog.js";import{createNavShell as w}from"./nav-shell.js";import{LoadToken as T,loadIntoStack as E}from"./view-loader.js";import{LoadingStack as D}from"./loading-stack.js";import{registerToastOverlay as O,showToast as k}from"./toast.js";import{SYSTEM_LOCALE_DIR as A,resolveLocaleDir as j,systemLocaleDir as M}from"./locale-dir.js";import{LOCALE_ENV_VARS as N,localeEnvToSet as P,posixLocale as F}from"./locale-env.js";import{initLocale as I}from"./locale.js";import{APPLE_ACCENT_COLOR_ARGV as L,MACOS_ACCENT_POLL_SECONDS as R,onMacosAccentColorChanged as z,readMacosAccentColor as B}from"./system-accent.js";import{findNavItem as V,resolveInitialNavIndex as H}from"./nav-model.js";export{L as APPLE_ACCENT_COLOR_ARGV,g as AdwaitaApp,u as BUNDLED_ICON_COUNT,d as BUNDLED_ICON_RESOURCE_PATH,f as BUNDLED_ICON_THEME_NAME,s as ICON_DIR_SEARCH_DEPTH,N as LOCALE_ENV_VARS,T as LoadToken,D as LoadingStack,R as MACOS_ACCENT_POLL_SECONDS,A as SYSTEM_LOCALE_DIR,p as addBundledIconsToTheme,e as appdataLocale,n as applyAppdataFields,r as buildAboutDialogFromAppdata,c as bundleDirFromUrl,b as confirmDialog,i as createAboutDialog,w as createNavShell,x as errorDialog,V as findNavItem,a as hasAppdataConstructor,I as initLocale,m as installBundledIconTheme,o as licenseTypeFor,E as loadIntoStack,P as localeEnvToSet,z as onMacosAccentColorChanged,t as parseAppdata,S as pickFile,F as posixLocale,y as readAppDevHooks,B as readMacosAccentColor,h as registerBundledIconResource,O as registerToastOverlay,l as resolveIconDir,H as resolveInitialNavIndex,j as resolveLocaleDir,_ as runAdwaitaApp,v as runApplication,C as saveFile,k as showToast,M as systemLocaleDir};
@@ -0,0 +1,27 @@
1
+ /** How many directories above the bundle are tried. Room to spare for `dist/app/x.gjs.mjs`. */
2
+ export declare const ICON_DIR_SEARCH_DEPTH = 6;
3
+ export interface ResolveIconDirOptions {
4
+ /** Wins over everything: a dev tree, or a test fixture. */
5
+ iconDir?: string;
6
+ /** Environment to read `GJSIFY_ICON_DIR` from. */
7
+ env?: Record<string, string | undefined>;
8
+ /** Directory of the running bundle, where the upward search starts. Omitted skips the search. */
9
+ startDir?: string;
10
+ /** Whether a directory exists. Injected so the decision needs no disk. */
11
+ isDirectory?: (path: string) => boolean;
12
+ }
13
+ /**
14
+ * Resolve the app's icon theme root, or `undefined` when nothing names or contains one.
15
+ *
16
+ * Precedence: explicit option, then `GJSIFY_ICON_DIR`, then a bounded upward search from
17
+ * `startDir` for `data/icons`. An EMPTY value counts as unset, as with `GJSIFY_LOCALE_DIR`:
18
+ * `add_search_path('')` would add the current directory.
19
+ *
20
+ * The search is bounded because the bundle's depth below the app root differs by layout
21
+ * (`src/frontends/desktop` is three levels, `dist/app` two). A fixed "one up" once landed in
22
+ * the non-existent `dist/data`. Without an answer the caller adds nothing, which leaves the
23
+ * theme exactly as it was.
24
+ */
25
+ export declare function resolveIconDir(options?: ResolveIconDirOptions): string | undefined;
26
+ /** `dirname` of a `file:` URL, or `undefined` for any other scheme (or nothing). */
27
+ export declare function bundleDirFromUrl(url: string | undefined): string | undefined;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import type Gtk from 'gi://Gtk?version=4.0';
2
+ import { type ResolveIconDirOptions } from './app-icon-dir.js';
3
+ export interface AddAppIconDirOptions extends Pick<ResolveIconDirOptions, 'iconDir'> {
4
+ /** Where the upward search starts. Defaults to the directory of this module's bundle. */
5
+ startDir?: string;
6
+ }
7
+ /**
8
+ * Make `iconName` resolvable on `theme`, adding the app's `data/icons` when the theme lacks it.
9
+ *
10
+ * Returns whether a directory was added. `false` is the normal answer for a packaged install,
11
+ * whose launcher exports `XDG_DATA_DIRS` so the theme already has the icon: nothing is touched
12
+ * there. Call it before anything asks the theme for the name, since `Gtk.IconTheme` caches a
13
+ * lookup.
14
+ */
15
+ export declare function addAppIconDir(theme: Gtk.IconTheme, iconName: string, options?: AddAppIconDirOptions): boolean;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -30,6 +30,15 @@ export interface AdwaitaAppOptions {
30
30
  * shipped set authoritative. See {@link BundledIconThemeOptions}.
31
31
  */
32
32
  bundledIcons?: boolean | BundledIconThemeOptions;
33
+ /**
34
+ * The app's own icon theme root (`<app>/data/icons`, holding `hicolor/...`). Added to
35
+ * the icon theme on `startup` when the theme cannot already find the app icon, which is
36
+ * the case for an app run straight from its build tree.
37
+ *
38
+ * Omitted: `GJSIFY_ICON_DIR`, then an upward search from the bundle for `data/icons`.
39
+ * A packaged install needs none of this, its launcher exports `XDG_DATA_DIRS`.
40
+ */
41
+ iconDir?: string;
33
42
  /** When set, wires an `app.about` action opening an `Adw.AboutDialog`. */
34
43
  about?: AboutInfo;
35
44
  /**
@@ -65,6 +74,7 @@ export declare class AdwaitaApp extends Adw.Application {
65
74
  private _initActions;
66
75
  private _onStartup;
67
76
  private _installBundledIcons;
77
+ private _installAppIcon;
68
78
  private _loadCss;
69
79
  private _installDevtools;
70
80
  private _onActivate;
@@ -18,6 +18,8 @@ export { pickFile, saveFile } from './file-dialog.js';
18
18
  export type { FileFilterSpec, PickFileOptions } from './file-dialog.js';
19
19
  export { initLocale } from './locale.js';
20
20
  export type { InitLocaleOptions, Translator } from './locale.js';
21
+ export { ICON_DIR_SEARCH_DEPTH, bundleDirFromUrl, resolveIconDir } from './app-icon-dir.js';
22
+ export type { ResolveIconDirOptions } from './app-icon-dir.js';
21
23
  export { SYSTEM_LOCALE_DIR, resolveLocaleDir, systemLocaleDir } from './locale-dir.js';
22
24
  export type { ResolveLocaleDirOptions } from './locale-dir.js';
23
25
  export { LOCALE_ENV_VARS, localeEnvToSet, posixLocale } from './locale-env.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/adwaita-app",
3
- "version": "0.64.6",
3
+ "version": "0.64.8",
4
4
  "description": "Native Adwaita application shell for GJS/GTK apps — Adw.Application lifecycle (runAsync + devtools + CSS), a data-driven NavigationSplitView nav shell, an async-view mounter, promise dialog/toast/file helpers, and a display-less reader of the desktop accent and colour scheme (`./appearance`)",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -57,14 +57,14 @@
57
57
  "@girs/glib-2.0": "5.4.0",
58
58
  "@girs/gobject-2.0": "5.4.0",
59
59
  "@girs/gtk-4.0": "5.4.0",
60
- "@gjsify/adwaita-core": "^0.64.6",
61
- "@gjsify/devtools": "^0.64.6",
62
- "@gjsify/utils": "^0.64.6"
60
+ "@gjsify/adwaita-core": "^0.64.8",
61
+ "@gjsify/devtools": "^0.64.8",
62
+ "@gjsify/utils": "^0.64.8"
63
63
  },
64
64
  "devDependencies": {
65
- "@gjsify/cli": "^0.64.6",
66
- "@gjsify/storybook": "^0.64.6",
67
- "@gjsify/unit": "^0.64.6",
65
+ "@gjsify/cli": "^0.64.8",
66
+ "@gjsify/storybook": "^0.64.8",
67
+ "@gjsify/unit": "^0.64.8",
68
68
  "@types/node": "^25.9.2",
69
69
  "typescript": "^6.0.3"
70
70
  },