jac-client 0.2.8__py3-none-any.whl → 0.2.10__py3-none-any.whl

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.
Files changed (64) hide show
  1. jac_client/examples/all-in-one/{app.jac → main.jac} +5 -5
  2. jac_client/examples/all-in-one/pages/BudgetPlanner.jac +8 -1
  3. jac_client/examples/all-in-one/pages/FeaturesTest.jac +16 -1
  4. jac_client/examples/all-in-one/pages/{FeaturesTest.cl.jac → features_test_ui.cl.jac} +11 -0
  5. jac_client/examples/all-in-one/pages/nestedDemo.jac +1 -1
  6. jac_client/examples/all-in-one/pages/notFound.jac +2 -7
  7. jac_client/plugin/cli.jac +491 -411
  8. jac_client/plugin/client.jac +25 -0
  9. jac_client/plugin/client_runtime.cl.jac +5 -1
  10. jac_client/plugin/impl/client.impl.jac +96 -55
  11. jac_client/plugin/impl/client_runtime.impl.jac +154 -0
  12. jac_client/plugin/plugin_config.jac +243 -15
  13. jac_client/plugin/src/config_loader.jac +1 -0
  14. jac_client/plugin/src/desktop_config.jac +31 -0
  15. jac_client/plugin/src/impl/compiler.impl.jac +1 -1
  16. jac_client/plugin/src/impl/config_loader.impl.jac +8 -0
  17. jac_client/plugin/src/impl/desktop_config.impl.jac +191 -0
  18. jac_client/plugin/src/impl/vite_bundler.impl.jac +97 -16
  19. jac_client/plugin/src/targets/desktop/sidecar/main.py +144 -0
  20. jac_client/plugin/src/targets/desktop_target.jac +37 -0
  21. jac_client/plugin/src/targets/impl/desktop_target.impl.jac +2334 -0
  22. jac_client/plugin/src/targets/impl/registry.impl.jac +64 -0
  23. jac_client/plugin/src/targets/impl/web_target.impl.jac +157 -0
  24. jac_client/plugin/src/targets/register.jac +21 -0
  25. jac_client/plugin/src/targets/registry.jac +87 -0
  26. jac_client/plugin/src/targets/web_target.jac +35 -0
  27. jac_client/plugin/src/vite_bundler.jac +6 -0
  28. jac_client/plugin/utils/__init__.jac +1 -0
  29. jac_client/plugin/utils/impl/node_installer.impl.jac +249 -0
  30. jac_client/plugin/utils/node_installer.jac +41 -0
  31. jac_client/templates/client.jacpack +72 -0
  32. jac_client/templates/fullstack.jacpack +61 -0
  33. jac_client/tests/conftest.py +48 -7
  34. jac_client/tests/test_cli.py +184 -70
  35. jac_client/tests/test_e2e.py +232 -0
  36. jac_client/tests/test_helpers.py +65 -0
  37. jac_client/tests/test_it.py +91 -135
  38. jac_client/tests/test_it_desktop.py +891 -0
  39. {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/METADATA +4 -4
  40. jac_client-0.2.10.dist-info/RECORD +115 -0
  41. {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/WHEEL +1 -1
  42. jac_client-0.2.8.dist-info/RECORD +0 -97
  43. /jac_client/examples/all-in-one/pages/{BudgetPlanner.cl.jac → budget_planner_ui.cl.jac} +0 -0
  44. /jac_client/examples/asset-serving/css-with-image/{src/app.jac → main.jac} +0 -0
  45. /jac_client/examples/asset-serving/image-asset/{src/app.jac → main.jac} +0 -0
  46. /jac_client/examples/asset-serving/import-alias/{src/app.jac → main.jac} +0 -0
  47. /jac_client/examples/basic/{src/app.jac → main.jac} +0 -0
  48. /jac_client/examples/basic-auth/{src/app.jac → main.jac} +0 -0
  49. /jac_client/examples/basic-auth-with-router/{src/app.jac → main.jac} +0 -0
  50. /jac_client/examples/basic-full-stack/{src/app.jac → main.jac} +0 -0
  51. /jac_client/examples/css-styling/js-styling/{src/app.jac → main.jac} +0 -0
  52. /jac_client/examples/css-styling/material-ui/{src/app.jac → main.jac} +0 -0
  53. /jac_client/examples/css-styling/pure-css/{src/app.jac → main.jac} +0 -0
  54. /jac_client/examples/css-styling/sass-example/{src/app.jac → main.jac} +0 -0
  55. /jac_client/examples/css-styling/styled-components/{src/app.jac → main.jac} +0 -0
  56. /jac_client/examples/css-styling/tailwind-example/{src/app.jac → main.jac} +0 -0
  57. /jac_client/examples/full-stack-with-auth/{src/app.jac → main.jac} +0 -0
  58. /jac_client/examples/little-x/{src/app.jac → main.jac} +0 -0
  59. /jac_client/examples/nested-folders/nested-advance/{src/app.jac → main.jac} +0 -0
  60. /jac_client/examples/nested-folders/nested-basic/{src/app.jac → main.jac} +0 -0
  61. /jac_client/examples/ts-support/{src/app.jac → main.jac} +0 -0
  62. /jac_client/examples/with-router/{src/app.jac → main.jac} +0 -0
  63. {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/entry_points.txt +0 -0
  64. {jac_client-0.2.8.dist-info → jac_client-0.2.10.dist-info}/top_level.txt +0 -0
@@ -5,10 +5,13 @@ configuration system, registering:
5
5
  - Plugin metadata (name, version)
6
6
  - Config schema for [plugins.client] section
7
7
  - npm dependency type for [dependencies.npm] section
8
+ - Project templates (client, fullstack)
8
9
  """
9
10
 
11
+ import os;
10
12
  import subprocess;
11
13
  import sys;
14
+ import json;
12
15
  import from pathlib { Path }
13
16
  import from typing { Any }
14
17
  import from jaclang.pycore.runtime { hookimpl }
@@ -68,6 +71,11 @@ class JacClientPluginConfig {
68
71
  "type": "dict",
69
72
  "default": {},
70
73
  "description": "TypeScript configuration overrides"
74
+ },
75
+ "configs": {
76
+ "type": "dict",
77
+ "default": {},
78
+ "description": "Generate config files for npm packages. Keys are config names (e.g., 'postcss', 'tailwind'), values are the config objects to export."
71
79
  }
72
80
  }
73
81
  };
@@ -79,15 +87,222 @@ class JacClientPluginConfig {
79
87
  return {
80
88
  "name": "npm",
81
89
  "dev_name": "npm.dev",
82
- "cli_flag": "--cl",
90
+ "cli_flag": "--npm",
83
91
  "install_dir": ".jac/client/configs",
84
92
  "install_handler": _npm_install_handler,
85
93
  "install_all_handler": _npm_install_all_handler,
86
94
  "remove_handler": _npm_remove_handler
87
95
  };
88
96
  }
97
+
98
+ """Register the client and fullstack project templates."""
99
+ @hookimpl
100
+ static def register_project_template -> list[dict[str, Any]] {
101
+ templates: list[dict[str, Any]] = [];
102
+
103
+ # Load templates from bundled JSON files
104
+ for template_name in ["client", "fullstack"] {
105
+ template = _load_template(template_name);
106
+ if template {
107
+ templates.append(template);
108
+ }
109
+ }
110
+
111
+ return templates;
112
+ }
113
+ }
114
+
115
+ # ===============================================================================
116
+ # Template Loader
117
+ # ===============================================================================
118
+ """Load a template from bundled JSON file."""
119
+ def _load_template(template_name: str) -> dict[str, Any] | None {
120
+ # Find the template JSON file relative to this module
121
+ # plugin_config.jac is in jac_client/plugin/, so .parent.parent = jac_client/
122
+ module_dir = Path(__file__).parent.parent; # jac_client directory
123
+ template_path = module_dir / "templates" / f"{template_name}.jacpack";
124
+
125
+ if not template_path.exists() {
126
+ # Fallback: look in installed package location
127
+ import from importlib.resources { files }
128
+ try {
129
+ package_files = files("jac_client");
130
+ template_path = Path(str(package_files)) / "templates" / f"{template_name}.jacpack";
131
+ } except Exception {
132
+ return None;
133
+ }
134
+ }
135
+
136
+ if not template_path.exists() {
137
+ return None;
138
+ }
139
+
140
+ try {
141
+ with open(template_path, "r") as f {
142
+ data = json.load(f);
143
+ }
144
+
145
+ # Attach the post_create hook
146
+ data["post_create"] = _post_create_client;
147
+
148
+ return data;
149
+ } except Exception as e {
150
+ print(
151
+ f"Warning: Could not load {template_name} template: {e}", file=sys.stderr
152
+ );
153
+ return None;
154
+ }
155
+ }
156
+
157
+ # ===============================================================================
158
+ # Post-create Hook for Client Template
159
+ # ===============================================================================
160
+ """Post-create hook to ensure Node.js is installed and optionally install npm packages."""
161
+ def _post_create_client(project_path: Path, project_name: str) -> None {
162
+ import from jac_client.plugin.src.vite_bundler { ViteBundler }
163
+ import from jac_client.plugin.utils.node_installer { NodeInstaller }
164
+ import from jaclang.cli.console { console }
165
+ import shutil;
166
+
167
+ # First, ensure Node.js is installed
168
+ console.print();
169
+ with console.status(
170
+ "[cyan]Checking Node.js installation...[/cyan]", spinner="dots"
171
+ ) as status {
172
+ node_result = NodeInstaller.ensure_node_installed(interactive=True);
173
+ node_installed = node_result[0];
174
+ message = node_result[1];
175
+ was_just_installed = node_result[2];
176
+ }
177
+
178
+ if not node_installed {
179
+ console.warning(f"Node.js is required for client development");
180
+ console.print(f"\n {message}", file=sys.stderr);
181
+ console.print(
182
+ " After installing Node.js, run: jac add --cl\n",
183
+ style="muted",
184
+ file=sys.stderr
185
+ );
186
+ return;
187
+ }
188
+
189
+ console.print(f" ✔ {message}", style="success");
190
+
191
+ # Check if npm package installation should be skipped
192
+ if os.environ.get("JAC_CLIENT_SKIP_NPM_INSTALL") {
193
+ console.print(
194
+ "\n ⏭ Skipping npm package installation (JAC_CLIENT_SKIP_NPM_INSTALL is set)",
195
+ style="muted"
196
+ );
197
+ console.print(
198
+ " Run 'jac add --npm' when ready to install packages.\n", style="muted"
199
+ );
200
+ return;
201
+ }
202
+
203
+ console.print();
204
+
205
+ try {
206
+ # Verify jac.toml exists
207
+ toml_path = project_path / "jac.toml";
208
+ if not toml_path.exists() {
209
+ print(
210
+ "Warning: jac.toml not found, skipping package installation",
211
+ file=sys.stderr
212
+ );
213
+ return;
214
+ }
215
+
216
+ # Create ViteBundler instance
217
+ bundler = ViteBundler(project_path);
218
+
219
+ # Generate package.json with default packages
220
+ bundler.create_package_json(project_name=project_name);
221
+
222
+ # Ensure .jac/client directory exists
223
+ client_dir = bundler._get_client_dir();
224
+ client_dir.mkdir(parents=True, exist_ok=True);
225
+
226
+ # Copy package.json to .jac/client/ for npm install
227
+ configs_package_json = client_dir / 'configs' / 'package.json';
228
+ build_package_json = client_dir / 'package.json';
229
+
230
+ if not configs_package_json.exists() {
231
+ print(
232
+ "Warning: package.json was not generated, skipping package installation",
233
+ file=sys.stderr
234
+ );
235
+ return;
236
+ }
237
+
238
+ shutil.copy2(configs_package_json, build_package_json);
239
+
240
+ # Run npm install using NodeInstaller to handle NVM environment
241
+ try {
242
+ console.print(" Installing npm packages...", style="cyan");
243
+ with console.status(
244
+ "[cyan]Installing npm packages...[/cyan]", spinner="dots"
245
+ ) as status {
246
+ NodeInstaller.run_npm_with_nvm(
247
+ ['install'], cwd=client_dir, timeout=300
248
+ );
249
+ }
250
+
251
+ # Move package-lock.json to configs/ if it was created
252
+ build_package_lock = client_dir / 'package-lock.json';
253
+ configs_package_lock = client_dir / 'configs' / 'package-lock.json';
254
+ if build_package_lock.exists() {
255
+ if configs_package_lock.exists() {
256
+ configs_package_lock.unlink();
257
+ }
258
+ shutil.move(str(build_package_lock), str(configs_package_lock));
259
+ }
260
+
261
+ console.print(" ✔ npm packages installed", style="success");
262
+ } except subprocess.CalledProcessError as e {
263
+ console.warning(f"Failed to install packages: {e.stderr}");
264
+ console.print(
265
+ " 💡 You can install packages later with: jac add --cl\n",
266
+ style="muted"
267
+ );
268
+ } except FileNotFoundError {
269
+ console.warning(
270
+ "npm command not found. This may require reloading your shell."
271
+ );
272
+ console.print(
273
+ " 💡 You can install packages later with: jac add --cl\n",
274
+ style="muted"
275
+ );
276
+ } finally {
277
+ # Clean up temporary package.json
278
+ if build_package_json.exists() {
279
+ build_package_json.unlink();
280
+ }
281
+ }
282
+ } except Exception as e {
283
+ console.warning(f"Could not install default packages: {e}");
284
+ console.print(
285
+ " 💡 You can install packages later with: jac add --cl\n", style="muted"
286
+ );
287
+ }
288
+
289
+ # If Node.js was just installed, offer to restart terminal for full integration
290
+ if was_just_installed {
291
+ console.print();
292
+ console.info("Node.js was just installed via NVM");
293
+ console.print(
294
+ "\n For Node.js to be available in your current shell:", style="muted"
295
+ );
296
+ console.print(" 1. Run: source ~/.nvm/nvm.sh", style="muted");
297
+ console.print(" 2. Or restart your terminal", style="muted");
298
+ console.print("\n 💡 npm commands from jac work immediately", style="info");
299
+ console.print();
300
+ }
89
301
  }
90
302
 
303
+ # ===============================================================================
304
+ # NPM Dependency Handlers
305
+ # ===============================================================================
91
306
  """Install an npm package."""
92
307
  def _npm_install_handler(
93
308
  config: JacConfig,
@@ -101,15 +316,13 @@ def _npm_install_handler(
101
316
  raise RuntimeError("No project root found") ;
102
317
  }
103
318
 
104
- project_dir = config.project_root;
105
-
106
319
  # Add to config (core JacConfig handles this)
107
- package_version = version or "latest";
320
+ package_version: str = version or "latest";
108
321
  config.add_dependency(package_name, package_version, dev=is_dev, dep_type="npm");
109
322
  config.save();
110
323
 
111
324
  # Generate package.json and run npm install
112
- _regenerate_and_install(project_dir);
325
+ _regenerate_and_install(Path(str(config.project_root)));
113
326
  }
114
327
 
115
328
  """Install all npm packages from jac.toml."""
@@ -118,7 +331,7 @@ def _npm_install_all_handler(config: JacConfig) -> None {
118
331
  raise RuntimeError("No project root found") ;
119
332
  }
120
333
 
121
- _regenerate_and_install(config.project_root);
334
+ _regenerate_and_install(Path(str(config.project_root)));
122
335
  }
123
336
 
124
337
  """Remove an npm package."""
@@ -129,7 +342,7 @@ def _npm_remove_handler(
129
342
  raise RuntimeError("No project root found") ;
130
343
  }
131
344
 
132
- project_dir = config.project_root;
345
+ project_dir: Path = Path(str(config.project_root));
133
346
 
134
347
  # Remove from config (core JacConfig handles this)
135
348
  result = config.remove_dependency(package_name, dev=is_dev, dep_type="npm");
@@ -147,8 +360,28 @@ def _npm_remove_handler(
147
360
  """Regenerate package.json from jac.toml and run npm install."""
148
361
  def _regenerate_and_install(project_dir: Path) -> None {
149
362
  import from jac_client.plugin.src.vite_bundler { ViteBundler }
363
+ import from jac_client.plugin.utils.node_installer { NodeInstaller }
150
364
  import shutil;
151
365
 
366
+ # Ensure Node.js is installed before proceeding
367
+ node_result = NodeInstaller.ensure_node_installed(interactive=True);
368
+ node_installed = node_result[0];
369
+ message = node_result[1];
370
+ was_just_installed = node_result[2];
371
+
372
+ if not node_installed {
373
+ raise RuntimeError(
374
+ f"Node.js installation required:\n{message}\n" + "Please install Node.js and try again."
375
+ ) ;
376
+ }
377
+
378
+ # Inform user if Node.js was just installed
379
+ if was_just_installed {
380
+ print(
381
+ "\nNote: Node.js was just installed. npm commands will work via NVM sourcing."
382
+ );
383
+ }
384
+
152
385
  bundler = ViteBundler(project_dir);
153
386
  bundler.create_package_json();
154
387
 
@@ -164,18 +397,13 @@ def _regenerate_and_install(project_dir: Path) -> None {
164
397
  }
165
398
 
166
399
  try {
167
- subprocess.run(
168
- ["npm", "install"],
169
- cwd=client_dir,
170
- check=True,
171
- capture_output=True,
172
- text=True
173
- );
400
+ # Use NodeInstaller.run_npm_with_nvm to handle NVM environment
401
+ NodeInstaller.run_npm_with_nvm(["install"], cwd=client_dir, timeout=300);
174
402
  } except subprocess.CalledProcessError as e {
175
403
  raise RuntimeError(f"Failed to install npm packages: {e.stderr}") from e ;
176
404
  } except FileNotFoundError {
177
405
  raise RuntimeError(
178
- "npm command not found. Ensure Node.js and npm are installed."
406
+ "npm command not found. This may require reloading your shell after Node.js installation."
179
407
  ) from None ;
180
408
  } finally {
181
409
  # Clean up temporary package.json
@@ -21,6 +21,7 @@ class JacClientConfig(PluginConfigBase) {
21
21
  def save(self: JacClientConfig) -> None;
22
22
  def get_vite_config(self: JacClientConfig) -> dict[str, Any];
23
23
  def get_ts_config(self: JacClientConfig) -> dict[str, Any];
24
+ def get_configs(self: JacClientConfig) -> dict[str, Any];
24
25
  def get_package_config(self: JacClientConfig) -> dict[str, Any];
25
26
  def add_dependency(
26
27
  self: JacClientConfig, name: str, version: str, is_dev: bool = False
@@ -0,0 +1,31 @@
1
+ """Configuration loader for Desktop target (Tauri).
2
+
3
+ This module provides configuration access for the desktop target.
4
+ Configuration is loaded from jac.toml under [desktop] section.
5
+
6
+ Similar to JacClientConfig but loads [desktop] directly (not under [plugins]).
7
+ """
8
+ import from pathlib { Path }
9
+ import from typing { Any }
10
+ import from jaclang.project.config { JacConfig, get_config }
11
+
12
+ """Desktop target configuration loader.
13
+
14
+ Provides access to desktop/Tauri configuration
15
+ from the [desktop] section of jac.toml.
16
+ """
17
+ class DesktopConfig {
18
+ has project_dir: Path | None = None,
19
+ _config: dict[str, Any] | None = None,
20
+ _jac_config: JacConfig | None = None;
21
+
22
+ def init(self: DesktopConfig, project_dir: Path | None = None) -> None;
23
+ def load(self: DesktopConfig) -> dict[str, Any];
24
+ def get_desktop_config(self: DesktopConfig) -> dict[str, Any];
25
+ def get_window_config(self: DesktopConfig) -> dict[str, Any];
26
+ def get_platforms_config(self: DesktopConfig) -> dict[str, Any];
27
+ def get_features_config(self: DesktopConfig) -> dict[str, Any];
28
+ def validate(self: DesktopConfig) -> None;
29
+ def get_default_config(self: DesktopConfig) -> dict[str, Any];
30
+ # def _get_jac_config(self: DesktopConfig) -> JacConfig;
31
+ }
@@ -49,7 +49,7 @@ impl ViteCompiler.create_entry_file(self: ViteCompiler, module_path: Path) -> No
49
49
  entry_file = self.compiled_dir / '_entry.js';
50
50
  # Derive the app module filename from the entry point (e.g., main.jac -> main.js, app.jac -> app.js)
51
51
  app_module_name = module_path.stem;
52
- entry_content = f'import React from "react";\nimport {{ createRoot }} from "react-dom/client";\nimport {{ app as App }} from "./{app_module_name}.js";\n\nconst root = createRoot(document.getElementById("root"));\nroot.render(React.createElement(App, null));\n';
52
+ entry_content = f'import React from "react";\nimport {{ createRoot }} from "react-dom/client";\nimport {{ app as App }} from "./{app_module_name}.js";\nimport {{ JacClientErrorBoundary, ErrorFallback }} from "@jac-client/utils";\n\nconst root = createRoot(document.getElementById("root"));\nroot.render(\n\tReact.createElement(\n\t\tJacClientErrorBoundary,{{ FallbackComponent: ErrorFallback }},\n\t\tReact.createElement(App, null)\n\t)\n);\n';
53
53
  entry_file.write_text(entry_content, encoding='utf-8');
54
54
  }
55
55
 
@@ -27,6 +27,7 @@ impl JacClientConfig.get_default_config(self: JacClientConfig) -> dict[str, Any]
27
27
  'resolve': {}
28
28
  },
29
29
  'ts': {'compilerOptions': {}, 'include': [], 'exclude': []},
30
+ 'configs': {}, # Generic config file generation: { "postcss": {...}, "tailwind": {...} }
30
31
  'package': {
31
32
  'name': '',
32
33
  'version': '1.0.0',
@@ -61,6 +62,7 @@ impl JacClientConfig.load(self: JacClientConfig) -> dict[str, Any] {
61
62
  user_config: dict[str, Any] = {
62
63
  'vite': client_config.get('vite', {}),
63
64
  'ts': client_config.get('ts', {}),
65
+ 'configs': client_config.get('configs', {}),
64
66
  'package': {
65
67
  'name': jac_config.project.name,
66
68
  'version': jac_config.project.version,
@@ -91,6 +93,12 @@ impl JacClientConfig.get_ts_config(self: JacClientConfig) -> dict[str, Any] {
91
93
  return config.get('ts', {});
92
94
  }
93
95
 
96
+ """Get generic config files to generate (postcss, tailwind, etc.)."""
97
+ impl JacClientConfig.get_configs(self: JacClientConfig) -> dict[str, Any] {
98
+ config = self.load();
99
+ return config.get('configs', {});
100
+ }
101
+
94
102
  """Save configuration back to jac.toml using core JacConfig."""
95
103
  impl JacClientConfig.save(self: JacClientConfig) -> None {
96
104
  jac_config = self.get_jac_config();
@@ -0,0 +1,191 @@
1
+ """Implementation of Desktop target configuration loader."""
2
+ import from pathlib { Path }
3
+ import from typing { Any }
4
+ import from jaclang.project.config { JacConfig, get_config }
5
+ import from jaclang.project.plugin_config { deep_merge }
6
+ import from jaclang.cli.console { console }
7
+
8
+ """Initialize DesktopConfig with project directory."""
9
+ impl DesktopConfig.init(self: DesktopConfig, project_dir: Path | None = None) -> None {
10
+ if project_dir is None {
11
+ self.project_dir = Path.cwd();
12
+ } else {
13
+ self.project_dir = project_dir;
14
+ }
15
+ self._config = None;
16
+ self._jac_config = None;
17
+ }
18
+
19
+ """Get default configuration structure for desktop target."""
20
+ impl DesktopConfig.get_default_config(self: DesktopConfig) -> dict[str, Any] {
21
+ # Try to get project name/version from JacConfig for defaults
22
+ # If config is not available, use fallback defaults
23
+ project_name = "my-jac-app";
24
+ project_version = "1.0.0";
25
+ try {
26
+ jac_config = self._get_jac_config();
27
+ if jac_config and jac_config.project {
28
+ project_name = jac_config.project.name or project_name;
29
+ project_version = jac_config.project.version or project_version;
30
+ }
31
+ } except Exception {
32
+ # If config loading fails, use defaults
33
+ console.warning("Failed to load JacConfig, using fallback defaults");
34
+ }
35
+ # Generate identifier from project name
36
+ identifier = _generate_identifier(project_name);
37
+ return {
38
+ 'name': project_name,
39
+ 'identifier': identifier,
40
+ 'version': project_version,
41
+ 'window': {
42
+ 'title': project_name,
43
+ 'width': 1200,
44
+ 'height': 800,
45
+ 'min_width': 800,
46
+ 'min_height': 600,
47
+ 'resizable': True,
48
+ 'fullscreen': False
49
+ },
50
+ 'platforms': {'windows': True, 'macos': True, 'linux': True},
51
+ 'features': {
52
+ 'system_tray': False,
53
+ 'auto_update': False,
54
+ 'notifications': False
55
+ }
56
+ };
57
+ }
58
+
59
+ """Get or load the core JacConfig instance."""
60
+ impl DesktopConfig._get_jac_config(self: DesktopConfig) -> JacConfig {
61
+ if self._jac_config is None {
62
+ self._jac_config = get_config();
63
+ if self._jac_config is None {
64
+ raise RuntimeError(
65
+ "No jac.toml found. Run 'jac create' to create a project."
66
+ ) ;
67
+ }
68
+ }
69
+ return self._jac_config;
70
+ }
71
+
72
+ """Load configuration from jac.toml, merging with defaults."""
73
+ impl DesktopConfig.load(self: DesktopConfig) -> dict[str, Any] {
74
+ if self._config is not None {
75
+ return self._config;
76
+ }
77
+ default_config = self.get_default_config();
78
+ # Try to get [desktop] section from jac.toml
79
+ desktop_config = {};
80
+ try {
81
+ jac_config = self._get_jac_config();
82
+ # Get [desktop] section from raw TOML data
83
+ # The [desktop] section is not under [plugins], so we access it directly
84
+ if jac_config and jac_config._raw_data {
85
+ raw_data = jac_config._raw_data;
86
+ desktop_config = raw_data.get('desktop', {});
87
+ }
88
+ } except Exception {
89
+ # If config loading fails, use defaults only
90
+ console.warning("Failed to load JacConfig, using fallback defaults");
91
+ }
92
+ # Deep merge defaults with user configuration
93
+ if desktop_config {
94
+ self._config = deep_merge(default_config, desktop_config);
95
+ } else {
96
+ self._config = default_config;
97
+ }
98
+ return self._config;
99
+ }
100
+
101
+ """Get desktop configuration (name, identifier, version)."""
102
+ impl DesktopConfig.get_desktop_config(self: DesktopConfig) -> dict[str, Any] {
103
+ config = self.load();
104
+ return {
105
+ 'name': config.get('name', ''),
106
+ 'identifier': config.get('identifier', ''),
107
+ 'version': config.get('version', '1.0.0')
108
+ };
109
+ }
110
+
111
+ """Get window configuration."""
112
+ impl DesktopConfig.get_window_config(self: DesktopConfig) -> dict[str, Any] {
113
+ config = self.load();
114
+ return config.get('window', {});
115
+ }
116
+
117
+ """Get platforms configuration."""
118
+ impl DesktopConfig.get_platforms_config(self: DesktopConfig) -> dict[str, Any] {
119
+ config = self.load();
120
+ return config.get('platforms', {});
121
+ }
122
+
123
+ """Get features configuration."""
124
+ impl DesktopConfig.get_features_config(self: DesktopConfig) -> dict[str, Any] {
125
+ config = self.load();
126
+ return config.get('features', {});
127
+ }
128
+
129
+ """Validate desktop configuration."""
130
+ impl DesktopConfig.validate(self: DesktopConfig) -> None {
131
+ config = self.load();
132
+ # Required fields
133
+ name = config.get('name', '');
134
+ if not name {
135
+ raise ValueError(
136
+ "Desktop configuration error: 'name' is required in [desktop] section"
137
+ ) ;
138
+ }
139
+ identifier = config.get('identifier', '');
140
+ if not identifier {
141
+ raise ValueError(
142
+ "Desktop configuration error: 'identifier' is required in [desktop] section"
143
+ ) ;
144
+ }
145
+ # Validate identifier format (should be reverse domain notation)
146
+ if not _is_valid_identifier(identifier) {
147
+ console.warning(
148
+ f"Desktop identifier '{identifier}' may not be valid. Use reverse domain notation (e.g., 'com.example.myapp')"
149
+ );
150
+ }
151
+ # Validate window dimensions
152
+ window = config.get('window', {});
153
+ width = window.get('width', 1200);
154
+ height = window.get('height', 800);
155
+ min_width = window.get('min_width', 800);
156
+ min_height = window.get('min_height', 600);
157
+ if min_width > width {
158
+ raise ValueError(
159
+ f"Desktop configuration error: window.min_width ({min_width}) cannot be greater than window.width ({width})"
160
+ ) ;
161
+ }
162
+ if min_height > height {
163
+ raise ValueError(
164
+ f"Desktop configuration error: window.min_height ({min_height}) cannot be greater than window.height ({height})"
165
+ ) ;
166
+ }
167
+ }
168
+
169
+ """Generate identifier from project name."""
170
+ def _generate_identifier(name: str) -> str {
171
+ # Convert to lowercase, replace spaces/special chars with dots
172
+ import re;
173
+ # Remove special characters, keep alphanumeric, dots, hyphens
174
+ cleaned = re.sub(r'[^a-zA-Z0-9.\-]', '', name.lower());
175
+ # Replace multiple dots/hyphens with single dot
176
+ cleaned = re.sub(r'[.\-]+', '.', cleaned);
177
+ # Remove leading/trailing dots
178
+ cleaned = cleaned.strip('.');
179
+ # If empty or doesn't look like reverse domain, prefix with 'com.'
180
+ if not cleaned or not '.' in cleaned {
181
+ cleaned = f"com.{cleaned}" if cleaned else "com.myapp";
182
+ }
183
+ return cleaned;
184
+ }
185
+
186
+ """Check if identifier is valid (reverse domain notation)."""
187
+ def _is_valid_identifier(identifier: str) -> bool {
188
+ import re;
189
+ # Should be like: com.example.myapp (at least one dot, alphanumeric + dots)
190
+ return bool(re.match(r'^[a-z0-9]+(\.[a-z0-9]+)+$', identifier.lower()));
191
+ }