@crossbind/extension-files 0.0.0-bootstrap.0 → 2.0.0-beta.69
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/LICENSE +21 -0
- package/README.md +26 -3
- package/crossbind.extension.js +13 -0
- package/native/files.cpp +11 -0
- package/package.json +40 -6
- package/page.d.ts +20 -0
- package/page.js +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Buğra Sarı and crossbind contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
# @crossbind/extension-files
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
package that exists, so it reserves the name for the crossbind release workflow.
|
|
3
|
+
The files the system opens the app with.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
An app has it by having `@crossbind/core-app-host`, which lists it as a dependency: there is nothing to install or list.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { app, events } from 'crossbind/app';
|
|
11
|
+
|
|
12
|
+
events.on('open-files', ({ paths }) => openAll(paths));
|
|
13
|
+
openAll(await app.launchFiles());
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Options
|
|
17
|
+
|
|
18
|
+
`app.fileTypes` lists the types of files the app opens, as `[{ name: 'GeoJSON', extensions: ['geojson'] }]`. The page
|
|
19
|
+
gets those no extension's type takes. The app has this extension only where a type is listed.
|
|
20
|
+
|
|
21
|
+
## Platforms
|
|
22
|
+
|
|
23
|
+
macOS, Linux, Windows, iOS and Android.
|
|
24
|
+
|
|
25
|
+
## Replace or leave out
|
|
26
|
+
|
|
27
|
+
It holds the role `files`. An extension that gives `replaces: 'files'` takes it; `app: { without: ['files'] }` in `crossbind.config.js` leaves it out. Leaving it out while `app.fileTypes` is set stops the build. [The guide](https://crossbind.dev/guide/extensions/#replace) shows how, and [extensions.md](https://github.com/crossbind/crossbind/blob/main/docs/api/extensions.md#the-hosts-own-extensions) what a replacement answers.
|
|
28
|
+
|
|
29
|
+
[app.md](https://github.com/crossbind/crossbind/blob/main/docs/api/app.md#files) has each platform's rules.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function files() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'files',
|
|
4
|
+
contract: 1,
|
|
5
|
+
root: import.meta.dirname,
|
|
6
|
+
reads: ['fileTypes'],
|
|
7
|
+
// An app that opens files of any owner, whose files no extension owns it hands the page.
|
|
8
|
+
fromApp: (api) => (api.app.fileTypes.length > 0 ? {} : null),
|
|
9
|
+
app: {
|
|
10
|
+
sources: ['native/files.cpp'],
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
package/native/files.cpp
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The files the system opens the app with that no extension's type takes, those of app.fileTypes among them, which the
|
|
2
|
+
// build gives this extension: the page asks for those that came before it listened with crossbind/app's
|
|
3
|
+
// app.launchFiles(), and hears of each later opening as the event open-files.
|
|
4
|
+
#include "crossbind/app.h"
|
|
5
|
+
#include "crossbind/extension.h"
|
|
6
|
+
|
|
7
|
+
void crossbind_extension_files(crossbind::Registry ®istry) {
|
|
8
|
+
registry.onOpenFiles([](const crossbind::OpenFiles &open) {
|
|
9
|
+
crossbind::app::holdEvent("open-files", crossbind::Value(crossbind::Value::Object{{"paths", open.paths}}).json());
|
|
10
|
+
});
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"name": "@crossbind/extension-files",
|
|
3
|
+
"version": "2.0.0-beta.69",
|
|
4
|
+
"description": "crossbind app extension: the files the system opens the app with.",
|
|
5
|
+
"homepage": "https://github.com/crossbind/crossbind/tree/main/extensions/files#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/crossbind/crossbind.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./page": {
|
|
14
|
+
"types": "./page.d.ts",
|
|
15
|
+
"default": "./page.js"
|
|
16
|
+
},
|
|
17
|
+
"./crossbind.extension.js": "./crossbind.extension.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"crossbind.extension.js",
|
|
21
|
+
"native",
|
|
22
|
+
"page.d.ts",
|
|
23
|
+
"page.js"
|
|
24
|
+
],
|
|
25
|
+
"crossbind": {
|
|
26
|
+
"extension": "./crossbind.extension.js"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"crossbind": "^2.0.0-beta.69"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"crossbind": "^2.0.0-beta.69"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"crossbind-extension",
|
|
36
|
+
"crossbind",
|
|
37
|
+
"launch",
|
|
38
|
+
"files",
|
|
39
|
+
"app"
|
|
40
|
+
]
|
|
41
|
+
}
|
package/page.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** What the event open-files carries: the absolute paths of the files the system opened the app with at once. */
|
|
2
|
+
export interface OpenFiles {
|
|
3
|
+
paths: string[];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export declare const app: {
|
|
7
|
+
/** The files the system opened the app with that have not reached the page yet, those of app.fileTypes in crossbind.config.js and those no extension's type takes, the launch's own among them, each by its absolute path. Once the page has asked, each later opening comes as the event open-files while it listens, so listening first, then asking, misses none. */
|
|
8
|
+
launchFiles(): Promise<string[]>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
declare module 'crossbind/app/core' {
|
|
12
|
+
interface AppEvents {
|
|
13
|
+
/** Calls listener with each set of files the system opens the app with once the page has called app.launchFiles(), or events.held('open-files'), until the function it returns is called. */
|
|
14
|
+
'open-files': OpenFiles;
|
|
15
|
+
}
|
|
16
|
+
interface HeldEvents {
|
|
17
|
+
/** The files the host held for the page, which came before it asked since it loaded, as app.launchFiles() gives their paths. */
|
|
18
|
+
'open-files': OpenFiles;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/page.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { events } from 'crossbind/app/core';
|
|
2
|
+
|
|
3
|
+
export const app = {
|
|
4
|
+
// The files the system opened the app with that have not reached the page yet, those no extension's type takes, the
|
|
5
|
+
// launch's own among them, which the host holds as the events open-files; later ones come as the event.
|
|
6
|
+
launchFiles: async () => (await events.held('open-files')).flatMap((value) => (Array.isArray(value?.paths) ? value.paths : []))
|
|
7
|
+
.filter((path) => typeof path === 'string'),
|
|
8
|
+
};
|