Skip to content

Commit 76af9d1

Browse files
committed
feat: add dev server API for dynamic src-node path resolution
- Add /api/getPhoenixPath endpoint to serve-proxy.js for Tauri dev mode - Refactor node-loader.js to fetch src-node path from dev server when running on localhost, enabling dynamic node source without recompiling - Update serve scripts to run npm install in src-node before starting
1 parent 02cfb53 commit 76af9d1

5 files changed

Lines changed: 86 additions & 10 deletions

File tree

docs/API-Reference/project/SidebarView.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ Returns the visibility state of the sidebar.
4343

4444
**Kind**: global function
4545
**Returns**: <code>boolean</code> - true if element is visible, false if it is not visible
46+
<a name="resize"></a>
47+
48+
## resize(width)
49+
Programmatically resize the sidebar to the given width. Persists
50+
the new size so it is restored on reload, resyncs the drag handle,
51+
and fires `panelResizeEnd`.
52+
53+
**Kind**: global function
54+
55+
| Param | Type | Description |
56+
| --- | --- | --- |
57+
| width | <code>number</code> | Desired sidebar width in pixels |
58+
59+
<a name="getWidth"></a>
60+
61+
## getWidth() ⇒ <code>number</code>
62+
Get the current sidebar width in pixels. Returns the CSS width
63+
even if the sidebar is hidden (so the value can be restored later).
64+
65+
**Kind**: global function

docs/API-Reference/view/SidebarTabs.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cached jQuery/DOM references held by extensions remain valid.
2222

2323
* [view/SidebarTabs](#module_view/SidebarTabs)
2424
* [.SIDEBAR_TAB_FILES](#module_view/SidebarTabs..SIDEBAR_TAB_FILES) : <code>string</code>
25+
* [.AI_TAB_GOOD_WIDTH](#module_view/SidebarTabs..AI_TAB_GOOD_WIDTH) : <code>number</code>
26+
* [.PREF_AI_WIDTH_SET_INITIAL](#module_view/SidebarTabs..PREF_AI_WIDTH_SET_INITIAL)
2527
* [.EVENT_TAB_ADDED](#module_view/SidebarTabs..EVENT_TAB_ADDED) : <code>string</code>
2628
* [.EVENT_TAB_REMOVED](#module_view/SidebarTabs..EVENT_TAB_REMOVED) : <code>string</code>
2729
* [.EVENT_TAB_CHANGED](#module_view/SidebarTabs..EVENT_TAB_CHANGED) : <code>string</code>
@@ -38,6 +40,19 @@ cached jQuery/DOM references held by extensions remain valid.
3840
### view/SidebarTabs.SIDEBAR\_TAB\_FILES : <code>string</code>
3941
The built-in Files tab id.
4042

43+
**Kind**: inner constant of [<code>view/SidebarTabs</code>](#module_view/SidebarTabs)
44+
<a name="module_view/SidebarTabs..AI_TAB_GOOD_WIDTH"></a>
45+
46+
### view/SidebarTabs.AI\_TAB\_GOOD\_WIDTH : <code>number</code>
47+
Preferred sidebar width (px) when a non-files tab (e.g. AI) is
48+
first activated. Applied once if the current width is narrower.
49+
50+
**Kind**: inner constant of [<code>view/SidebarTabs</code>](#module_view/SidebarTabs)
51+
<a name="module_view/SidebarTabs..PREF_AI_WIDTH_SET_INITIAL"></a>
52+
53+
### view/SidebarTabs.PREF\_AI\_WIDTH\_SET\_INITIAL
54+
Preference key used to track whether the initial width bump has been applied.
55+
4156
**Kind**: inner constant of [<code>view/SidebarTabs</code>](#module_view/SidebarTabs)
4257
<a name="module_view/SidebarTabs..EVENT_TAB_ADDED"></a>
4358

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
"_patchVersionBump": "gulp patchVersionBump",
7676
"_minorVersionBump": "gulp minorVersionBump",
7777
"_majorVersionBump": "gulp majorVersionBump",
78-
"serve": "node serve-proxy.js . -p 8000 -c-1",
79-
"serveLocalAccount": "node serve-proxy.js . -p 8000 -c-1 --localAccount",
80-
"serveStagingAccount": "node serve-proxy.js . -p 8000 -c-1 --stagingAccount",
78+
"serve": "npm install --prefix src-node && node serve-proxy.js . -p 8000 -c-1",
79+
"serveLocalAccount": "npm install --prefix src-node && node serve-proxy.js . -p 8000 -c-1 --localAccount",
80+
"serveStagingAccount": "npm install --prefix src-node && node serve-proxy.js . -p 8000 -c-1 --stagingAccount",
8181
"_serveWithWebCacheHelp": "echo !!!Make sure to npm run release:dev/stageing/prod before testing the cache!!!",
8282
"serveWithWebCache": "npm run _releaseWebCache && npm run _serveWithWebCacheHelp && http-server ./dist -p 8000 -c-1",
83-
"serveExternal": "node serve-proxy.js . -p 8000 -a 0.0.0.0 --log-ip -c-1",
83+
"serveExternal": "npm install --prefix src-node && node serve-proxy.js . -p 8000 -a 0.0.0.0 --log-ip -c-1",
8484
"createJSDocs": "node build/api-docs-generator.js && git add docs",
8585
"_translateStrings": "gulp translateStrings",
8686
"_minify": "r.js -o require.min.config.js && echo this is untested see https://stackoverflow.com/questions/14337970/minifying-requirejs-javascript-codebase-to-a-single-file"

serve-proxy.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,31 @@ const server = http.createServer((req, res) => {
270270
return;
271271
}
272272

273+
// Handle getPhoenixPath API for Tauri dev mode
274+
if (parsedUrl.pathname === '/api/getPhoenixPath') {
275+
const response = {
276+
phoenixPath: config.root
277+
};
278+
279+
if (!config.silent) {
280+
console.log(`[API] ${req.method} ${parsedUrl.pathname} -> ${JSON.stringify(response)}`);
281+
}
282+
283+
const headers = {
284+
'Content-Type': 'application/json'
285+
};
286+
287+
if (config.cors) {
288+
headers['Access-Control-Allow-Origin'] = '*';
289+
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS';
290+
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Cache-Control';
291+
}
292+
293+
res.writeHead(200, headers);
294+
res.end(JSON.stringify(response));
295+
return;
296+
}
297+
273298
// Handle proxy config request
274299
if (parsedUrl.pathname === '/proxy/config') {
275300
const configResponse = {

src/node-loader.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,18 +635,34 @@ function nodeLoader() {
635635
nodeErrorLogCount = 0;
636636
}, NODE_ERROR_LOGS_RESET_INTERVAL);
637637

638-
async function _tauriNodeSetup() {
639-
let nodeSrcPath = await window.__TAURI__.path.resolveResource("src-node/index.js");
638+
async function _resolveSrcNodePath() {
639+
// Check if running from localhost dev server
640+
if (window.location.hostname === 'localhost') {
641+
// Fetch phoenix path from dev server API to use local src-node
642+
const response = await fetch('/api/getPhoenixPath');
643+
const pathInfo = await response.json();
644+
const srcNodePath = `${pathInfo.phoenixPath}/src-node/index.js`;
645+
console.log('PhNode: Using dev server src-node path:', srcNodePath);
646+
return srcNodePath;
647+
}
648+
649+
// Production Tauri path resolution
650+
let srcNodePath = await window.__TAURI__.path.resolveResource("src-node/index.js");
640651
// Strip Windows UNC prefix (\\?\) that Tauri adds on Windows
641652
// Node 24 doesn't handle UNC paths correctly in module resolution
642-
if (Phoenix.platform === "win" && nodeSrcPath.startsWith('\\\\?\\')) {
643-
nodeSrcPath = nodeSrcPath.slice(4);
653+
if (Phoenix.platform === "win" && srcNodePath.startsWith('\\\\?\\')) {
654+
srcNodePath = srcNodePath.slice(4);
644655
}
645-
if(Phoenix.platform === "linux") {
656+
if (Phoenix.platform === "linux") {
646657
// in linux installed distributions, src-node is present in the same dir as the executable.
647658
const cliArgs = await window.__TAURI__.invoke('_get_commandline_args');
648-
nodeSrcPath = `${window.path.dirname(cliArgs[0])}/src-node/index.js`;
659+
srcNodePath = `${window.path.dirname(cliArgs[0])}/src-node/index.js`;
649660
}
661+
return srcNodePath;
662+
}
663+
664+
async function _tauriNodeSetup() {
665+
const nodeSrcPath = await _resolveSrcNodePath();
650666
// node is designed such that it is not required at boot time to lower startup time.
651667
// Keep this so to increase boot speed.
652668
const inspectPort = Phoenix.isTestWindow ? getRandomNumber(5000, 50000) : 9229;

0 commit comments

Comments
 (0)