@axium/client 0.31.1 → 0.32.0

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/assets/styles.css CHANGED
@@ -232,15 +232,18 @@ div.success {
232
232
  }
233
233
 
234
234
  .danger {
235
- border: var(--border-error);
236
- background-color: hsl(from var(--bg-strong) 0 s l);
237
- color: hsl(0 33 var(--fg-light));
238
- --fill: hsl(0 33 var(--fg-light));
239
- accent-color: hsl(0 33 var(--fg-light));
240
- }
235
+ color: var(--fg-danger);
236
+ --fill: var(--fg-danger);
237
+ accent-color: var(--fg-danger);
238
+
239
+ &:is(button, div):not(.reset) {
240
+ border: var(--border-error);
241
+ background-color: var(--bg-danger);
241
242
 
242
- .danger:hover {
243
- background-color: hsl(0 20 calc(var(--bg-light) + (var(--light-step) * 3)));
243
+ &:hover {
244
+ background-color: hsl(0 20 calc(var(--bg-light) + (var(--light-step) * 3)));
245
+ }
246
+ }
244
247
  }
245
248
 
246
249
  :disabled,
@@ -274,6 +277,15 @@ div.success {
274
277
  background-color: var(--bg-strong);
275
278
  cursor: pointer;
276
279
  }
280
+
281
+ &.danger:where(button, div) {
282
+ border: none;
283
+ background-color: transparent;
284
+
285
+ &:hover {
286
+ background-color: var(--bg-danger);
287
+ }
288
+ }
277
289
  }
278
290
 
279
291
  .menu-header {
package/assets/theme.css CHANGED
@@ -36,6 +36,7 @@ html {
36
36
  --bg-alt: hsl(var(--hue) 5 calc(var(--bg-light) + var(--light-step)));
37
37
  --bg-strong: hsl(var(--hue) 20 calc(var(--bg-light) + var(--light-step)));
38
38
  --bg-elevated: hsl(from var(--bg-menu) h s l / 95%);
39
+ --bg-danger: hsl(from var(--bg-strong) 0 s l);
39
40
 
40
41
  --bg-error: hsl(0 40 var(--bg-light-status));
41
42
  --bg-warning: hsl(60 40 var(--bg-light-status));
@@ -45,10 +46,13 @@ html {
45
46
  --fg-accent: hsl(var(--hue) 15 var(--fg-light));
46
47
  --fg-strong: hsl(var(--hue) 25 calc(var(--fg-light) - var(--light-step)));
47
48
  --fg-disabled: hsl(0 0 calc(var(--fg-light) - var(--light-step)));
49
+ --fg-danger: hsl(0 33 var(--fg-light));
48
50
 
49
51
  --fg-error: hsl(0 50 calc(var(--fg-light) - var(--light-step)));
50
52
  --fg-warning: hsl(60 50 calc(var(--fg-light) - var(--light-step)));
51
53
 
54
+ --green: hsl(140 50 50);
55
+
52
56
  --border-disabled: 1px solid hsl(0 5 calc(var(--bg-light) - var(--light-step)));
53
57
  --border-accent: 1px solid hsl(var(--hue) 10 calc(var(--bg-light) + (var(--light-step) * 3)));
54
58
  --border-alt: 1px solid var(--bg-alt);
@@ -11,7 +11,7 @@ FailureAction=none
11
11
  [Service]
12
12
  Type=simple
13
13
  ExecStartPre=/usr/bin/env cd "%Y/../../.."
14
- ExecStart=/usr/bin/env npx --prefix "%Y/../../.." axium-client run
14
+ ExecStart=/usr/bin/env npx --prefix "%Y/../../.." axium-client daemon
15
15
  ExecReload=kill -HUP $MAINPID
16
16
  SyslogIdentifier=axium-client
17
17
  Restart=on-failure
package/dist/cli/cache.js CHANGED
@@ -136,9 +136,15 @@ export async function update(force = false) {
136
136
  }
137
137
  export function clear() {
138
138
  for (const handle of handles)
139
- unlinkSync(handle.path);
139
+ try {
140
+ unlinkSync(handle.path);
141
+ }
142
+ catch { }
140
143
  for (const { path } of persistedAPICaches)
141
- unlinkSync(path);
144
+ try {
145
+ unlinkSync(path);
146
+ }
147
+ catch { }
142
148
  }
143
149
  export async function* info() {
144
150
  for (const handle of handles) {
@@ -1,4 +1,5 @@
1
1
  export declare const configDir: string;
2
+ export declare const axcConfigPath: string;
2
3
  export declare function session(): {
3
4
  id: string;
4
5
  userId: string;
@@ -8,9 +8,9 @@ import { setPrefix, setToken } from '../requests.js';
8
8
  import * as cache from './cache.js';
9
9
  export const configDir = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'axium');
10
10
  mkdirSync(configDir, { recursive: true });
11
- const axcConfig = join(configDir, 'config.json');
12
- if (!existsSync(axcConfig))
13
- writeFileSync(axcConfig, '{}');
11
+ export const axcConfigPath = join(configDir, 'config.json');
12
+ if (!existsSync(axcConfigPath))
13
+ writeFileSync(axcConfigPath, '{}');
14
14
  export function session() {
15
15
  if (!config.token)
16
16
  io.exit('Not logged in.', 4);
@@ -20,19 +20,19 @@ export function session() {
20
20
  }
21
21
  export async function loadConfig(safe) {
22
22
  try {
23
- Object.assign(config, io.readJSON(axcConfig, ClientConfig));
23
+ Object.assign(config, io.readJSON(axcConfigPath, ClientConfig));
24
24
  if (config.server)
25
25
  setPrefix(config.server);
26
26
  if (config.token)
27
27
  setToken(config.token);
28
28
  for (const plugin of config.plugins ?? [])
29
- await loadPlugin('client', plugin, axcConfig, safe);
29
+ await loadPlugin('client', plugin, axcConfigPath, safe);
30
30
  }
31
31
  catch (e) {
32
32
  io.warn('Failed to load config: ' + io.errorText(e));
33
33
  }
34
34
  }
35
35
  export function saveConfig() {
36
- io.writeJSON(axcConfig, config);
37
- io.debug('Saved config to ' + axcConfig);
36
+ io.writeJSON(axcConfigPath, config);
37
+ io.debug('Saved config to ' + axcConfigPath);
38
38
  }
package/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env node
2
2
  import { formatBytes } from '@axium/core';
3
- import { outputDaemonStatus, pluginText } from '@axium/core/node';
3
+ import { loadPlugin, outputDaemonStatus, pluginText } from '@axium/core/node';
4
4
  import { _findPlugin, plugins } from '@axium/core/plugins';
5
5
  import { CommanderError, program } from 'commander';
6
6
  import * as io from 'ioium/node';
@@ -10,10 +10,11 @@ import * as z from 'zod';
10
10
  import $pkg from '../../package.json' with { type: 'json' };
11
11
  import { config } from '../config.js';
12
12
  import { prefix, useUserAgent } from '../requests.js';
13
+ import { connect as connectSocket } from '../socket.js';
13
14
  import { logout } from '../user.js';
14
15
  import { clientUA, login } from './auth.js';
15
16
  import * as cache from './cache.js';
16
- import { loadConfig, saveConfig, session } from './config.js';
17
+ import { axcConfigPath, loadConfig, saveConfig, session } from './config.js';
17
18
  const safe = z.stringbool().default(false).parse(process.env.SAFE?.toLowerCase()) || process.argv.includes('--safe');
18
19
  const debug = z.stringbool().default(false).parse(process.env.DEBUG?.toLowerCase()) || process.argv.includes('--debug');
19
20
  if (debug)
@@ -62,18 +63,26 @@ program.command('status').action(() => {
62
63
  outputDaemonStatus('axium-client');
63
64
  });
64
65
  program
65
- .command('run')
66
- .argument('[plugin]', 'The plugin to run')
67
- .action(async (name) => {
68
- if (name) {
69
- const plugin = _findPlugin(name);
70
- await plugin._client?.run();
71
- return;
72
- }
66
+ .command('daemon')
67
+ .description('Run as the Axium client daemon')
68
+ .option('--no-socket', 'do not open a socket connection to the server')
69
+ .option('--insecure', 'allow connecting to a server with an untrusted (e.g. self-signed) TLS certificate', false)
70
+ .action(async (opt) => {
73
71
  for (const plugin of plugins.values())
74
- await plugin._client?.run();
72
+ await plugin._client?.run?.();
73
+ // Hold a socket connection to the server for the lifetime of the daemon.
74
+ if (opt.socket && config.token)
75
+ await connectSocket({ rejectUnauthorized: !opt.insecure });
75
76
  });
76
77
  const axcPlugin = program.command('plugin').alias('plugins').description('Manage plugins');
78
+ axcPlugin
79
+ .command('run')
80
+ .description('Run a plugin')
81
+ .argument('<plugin>', 'the plugin to run')
82
+ .action(async (search) => {
83
+ const plugin = _findPlugin(search);
84
+ await plugin._client?.run?.();
85
+ });
77
86
  axcPlugin
78
87
  .command('list')
79
88
  .alias('ls')
@@ -103,6 +112,31 @@ axcPlugin
103
112
  for (const line of pluginText(plugin))
104
113
  console.log(line);
105
114
  });
115
+ axcPlugin
116
+ .command('add')
117
+ .description('Add a plugin')
118
+ .option('-k, --keep-going', 'continue adding plugins even if one fails')
119
+ .argument('<spec...>', 'the plugin specifier (e.g. a package name) to add')
120
+ .action(async (specs, { keepGoing }) => {
121
+ for (const spec of specs) {
122
+ try {
123
+ if (config.plugins.includes(spec))
124
+ throw `Plugin "${spec}" is already added.`;
125
+ const plugin = await loadPlugin('client', spec, axcConfigPath, safe);
126
+ if (!plugin)
127
+ throw `Failed to load a client plugin from "${spec}".`;
128
+ config.plugins.push(spec);
129
+ saveConfig();
130
+ console.log('Added plugin:', plugin.name, styleText('dim', 'v' + plugin.version));
131
+ }
132
+ catch (e) {
133
+ if (keepGoing)
134
+ io.error(e);
135
+ else
136
+ io.exit(e);
137
+ }
138
+ }
139
+ });
106
140
  axcPlugin
107
141
  .command('remove')
108
142
  .alias('rm')
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export * from './access.js';
2
- export * as preferences from './preferences.js';
3
2
  export * from './cache.js';
4
3
  export * from './config.js';
5
4
  export * from './locales.js';
5
+ export * as preferences from './preferences.js';
6
6
  export * from './requests.js';
7
+ export * as socket from './socket.js';
7
8
  export * from './user.js';
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  export * from './access.js';
2
- export * as preferences from './preferences.js';
3
2
  export * from './cache.js';
4
3
  export * from './config.js';
5
4
  export * from './locales.js';
5
+ export * as preferences from './preferences.js';
6
6
  export * from './requests.js';
7
+ export * as socket from './socket.js';
7
8
  export * from './user.js';
@@ -5,6 +5,7 @@ export declare let token: string | null;
5
5
  export declare function setToken(value: string | null): void;
6
6
  export declare let prefix: string, origin: string;
7
7
  export declare function setPrefix(value: string): void;
8
+ export declare let userAgent: string | null;
8
9
  /**
9
10
  * Only for use on non-browser clients, e.g. Node.js
10
11
  */
package/dist/requests.js CHANGED
@@ -14,7 +14,7 @@ export function setPrefix(value) {
14
14
  prefix = value;
15
15
  origin = new URL(prefix, origin).origin;
16
16
  }
17
- let userAgent = null;
17
+ export let userAgent = null;
18
18
  /**
19
19
  * Only for use on non-browser clients, e.g. Node.js
20
20
  */
@@ -0,0 +1,10 @@
1
+ import type { ClientToServerEvents, ServerToClientEvents } from '@axium/core/socket';
2
+ import { ServerToClient } from '@axium/core/socket';
3
+ import type { ManagerOptions, Socket as PlainSocket, SocketOptions } from 'socket.io-client';
4
+ export interface Socket extends PlainSocket<ServerToClientEvents, ClientToServerEvents> {
5
+ }
6
+ export declare function addListener<T extends keyof ServerToClient & string>(event: T, listener: ServerToClientEvents[T]): void;
7
+ export interface ConnectOptions extends Partial<ManagerOptions & SocketOptions> {
8
+ }
9
+ export declare let socket: Socket | null;
10
+ export declare function connect(opts?: ConnectOptions): Promise<Socket>;
package/dist/socket.js ADDED
@@ -0,0 +1,40 @@
1
+ import { ServerToClient } from '@axium/core/socket';
2
+ import * as io from 'ioium';
3
+ import { io as socketIO } from 'socket.io-client';
4
+ import { origin, token, userAgent } from './requests.js';
5
+ const listeners = new Set();
6
+ export function addListener(event, listener) {
7
+ const schema = ServerToClient[event];
8
+ if (schema)
9
+ listeners.add([event, schema.implement(listener)]);
10
+ else {
11
+ io.warn(`Attaching a listener to the '${event}' socket event without schema`);
12
+ listeners.add([event, listener]);
13
+ }
14
+ }
15
+ export let socket = null;
16
+ export function connect(opts) {
17
+ if (socket)
18
+ return Promise.resolve(socket);
19
+ if (!token)
20
+ io.warn('Connecting to the server socket without a session token.');
21
+ const { extraHeaders = {} } = opts || {};
22
+ if (token)
23
+ extraHeaders.Authorization = 'Bearer ' + token;
24
+ if (userAgent)
25
+ extraHeaders['User-Agent'] = userAgent;
26
+ socket = socketIO(origin, { ...opts, extraHeaders });
27
+ for (const [event, listener] of listeners)
28
+ socket.on(event, listener);
29
+ const { promise, resolve, reject } = Promise.withResolvers();
30
+ socket.on('connect', () => {
31
+ io.debug('socket: Connected as ' + socket.id);
32
+ resolve(socket);
33
+ });
34
+ socket.on('connect_error', err => {
35
+ if (!socket.active)
36
+ socket = null;
37
+ reject(err);
38
+ });
39
+ return promise;
40
+ }
@@ -51,8 +51,8 @@
51
51
  <i>{text('AppMenu.failed')}</i>
52
52
  {/await}
53
53
 
54
- <button class="menu-item logout reset" command="show-modal" commandfor="logout">
55
- <Icon i="right-from-bracket" --size="1.5em" --fill="hsl(0 33 var(--fg-light))" />
54
+ <button class="menu-item danger reset" command="show-modal" commandfor="logout">
55
+ <Icon i="right-from-bracket" --size="1.5em" />
56
56
  <span>{text('generic.logout')}</span>
57
57
  </button>
58
58
  </Popover>
@@ -73,11 +73,6 @@
73
73
  background-color: var(--bg-alt);
74
74
  }
75
75
 
76
- .logout {
77
- color: hsl(0 33 var(--fg-light));
78
- font-size: 16px;
79
- }
80
-
81
76
  :global(.UserMenu + div:popover-open) {
82
77
  cursor: default;
83
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.31.1",
3
+ "version": "0.32.0",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -49,7 +49,7 @@
49
49
  "build": "tsc"
50
50
  },
51
51
  "peerDependencies": {
52
- "@axium/core": ">=0.32.0",
52
+ "@axium/core": ">=0.33.0",
53
53
  "ioium": "^1.0.2",
54
54
  "semver": "^7.7.4",
55
55
  "svelte": "^5.36.0",
@@ -59,6 +59,7 @@
59
59
  "dependencies": {
60
60
  "@simplewebauthn/browser": "^13.1.0",
61
61
  "commander": "^15.0.0",
62
- "music-metadata": "^11.12.3"
62
+ "music-metadata": "^11.12.3",
63
+ "socket.io-client": "^4.8.3"
63
64
  }
64
65
  }