@elephant-wiki/cli 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,54 @@
1
+ """Use the desktop portal when the system's Python Gio bindings are available."""
2
+
3
+ import sys
4
+ import uuid
5
+
6
+ from gi.repository import Gio, GLib
7
+
8
+ service = "org.freedesktop.portal.Desktop"
9
+ path = "/org/freedesktop/portal/desktop"
10
+ chooser = service.replace(".Desktop", ".FileChooser")
11
+ bus = Gio.bus_get_sync(Gio.BusType.SESSION)
12
+ version = bus.call_sync(
13
+ service, path, "org.freedesktop.DBus.Properties", "Get",
14
+ GLib.Variant("(ss)", (chooser, "version")), None, Gio.DBusCallFlags.NONE, 1500,
15
+ ).unpack()[0]
16
+ if version < 3:
17
+ sys.exit(2)
18
+
19
+ token = "elephant_" + uuid.uuid4().hex
20
+ sender = bus.get_unique_name()[1:].replace(".", "_")
21
+ handle = f"{path}/request/{sender}/{token}"
22
+ loop = GLib.MainLoop()
23
+ response = None
24
+
25
+
26
+ def on_response(_connection, _sender, _path, _interface, _member, parameters):
27
+ global response
28
+ response = parameters.unpack()
29
+ loop.quit()
30
+
31
+
32
+ bus.signal_subscribe(
33
+ service, "org.freedesktop.portal.Request", "Response", handle, None,
34
+ Gio.DBusSignalFlags.NONE, on_response,
35
+ )
36
+ options = {
37
+ "directory": GLib.Variant("b", True),
38
+ "accept_label": GLib.Variant("s", "Link folder"),
39
+ "handle_token": GLib.Variant("s", token),
40
+ }
41
+ bus.call_sync(
42
+ service, path, chooser, "OpenFile", GLib.Variant("(ssa{sv})", ("", sys.argv[1], options)),
43
+ None, Gio.DBusCallFlags.NONE, 3000,
44
+ )
45
+ loop.run()
46
+ code, result = response
47
+ if code == 1:
48
+ sys.exit(0)
49
+ if code != 0 or not result.get("uris"):
50
+ sys.exit(2)
51
+ folder = Gio.File.new_for_uri(result["uris"][0]).get_path()
52
+ if folder is None:
53
+ sys.exit(2)
54
+ print(folder)
@@ -0,0 +1,77 @@
1
+ $ErrorActionPreference = 'Stop'
2
+ [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
3
+
4
+ Add-Type -TypeDefinition @'
5
+ using System;
6
+ using System.Runtime.InteropServices;
7
+
8
+ public static class ElephantFolderPicker
9
+ {
10
+ [ComImport, Guid("42F85136-DB7E-439C-85F1-E4075D135FC8"),
11
+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
12
+ private interface IFileDialog
13
+ {
14
+ [PreserveSig] int Show(IntPtr parent);
15
+ void SetFileTypes(uint count, IntPtr specs);
16
+ void SetFileTypeIndex(uint index);
17
+ void GetFileTypeIndex(out uint index);
18
+ void Advise(IntPtr events, out uint cookie);
19
+ void Unadvise(uint cookie);
20
+ void SetOptions(uint options);
21
+ void GetOptions(out uint options);
22
+ void SetDefaultFolder(IShellItem item);
23
+ void SetFolder(IShellItem item);
24
+ void GetFolder(out IShellItem item);
25
+ void GetCurrentSelection(out IShellItem item);
26
+ void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string name);
27
+ void GetFileName(out IntPtr name);
28
+ void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string title);
29
+ void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string label);
30
+ void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string label);
31
+ void GetResult(out IShellItem item);
32
+ }
33
+
34
+ [ComImport, Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"),
35
+ InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
36
+ private interface IShellItem
37
+ {
38
+ void BindToHandler(IntPtr context, ref Guid handler, ref Guid iid, out IntPtr result);
39
+ void GetParent(out IShellItem parent);
40
+ void GetDisplayName(uint kind, out IntPtr name);
41
+ }
42
+
43
+ public static string Choose(string title)
44
+ {
45
+ var type = Type.GetTypeFromCLSID(new Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7"));
46
+ var dialog = (IFileDialog)Activator.CreateInstance(type);
47
+ try
48
+ {
49
+ uint options;
50
+ dialog.GetOptions(out options);
51
+ const uint pickFolders = 0x20, forceFileSystem = 0x40;
52
+ dialog.SetOptions(options | pickFolders | forceFileSystem);
53
+ dialog.SetTitle(title);
54
+ dialog.SetOkButtonLabel("Link folder");
55
+ int result = dialog.Show(IntPtr.Zero);
56
+ const int cancelled = unchecked((int)0x800704C7);
57
+ if (result == cancelled) return null;
58
+ Marshal.ThrowExceptionForHR(result);
59
+ IShellItem folder;
60
+ dialog.GetResult(out folder);
61
+ try
62
+ {
63
+ IntPtr path;
64
+ const uint fileSystemPath = 0x80058000;
65
+ folder.GetDisplayName(fileSystemPath, out path);
66
+ try { return Marshal.PtrToStringUni(path); }
67
+ finally { Marshal.FreeCoTaskMem(path); }
68
+ }
69
+ finally { Marshal.ReleaseComObject(folder); }
70
+ }
71
+ finally { Marshal.ReleaseComObject(dialog); }
72
+ }
73
+ }
74
+ '@
75
+
76
+ $folder = [ElephantFolderPicker]::Choose($env:ELEPHANT_PICKER_TITLE)
77
+ if ($null -ne $folder) { [Console]::WriteLine($folder) }
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
- {
2
- "name": "@elephant-wiki/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@elephant-wiki/cli",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Local Folder Sync for Elephant Wiki",
6
+ "bin": {
7
+ "elephant": "./dist/elephant.mjs"
8
+ },
9
+ "files": ["dist"],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "build": "node build.mjs",
15
+ "prepack": "npm run build"
16
+ },
17
+ "engines": {
18
+ "node": ">=22.22.0"
19
+ },
20
+ "dependencies": {
21
+ "@napi-rs/keyring": "^2.1.2",
22
+ "chokidar": "^4.0.3"
23
+ },
24
+ "devDependencies": {
25
+ "esbuild": "0.28.2"
26
+ }
27
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.