Skip to content

Commit 4f0f47a

Browse files
committed
feat: electron support initial scaffolding for linux
1 parent 3b047a4 commit 4f0f47a

3 files changed

Lines changed: 78 additions & 34 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "@phcode/fs",
3-
"description": "Phoenix virtual file system over filer/ browser fs access/ tauri / phoenix web socket APIs",
4-
"version": "3.0.1",
3+
"description": "Phoenix virtual file system over filer/ browser fs access/ tauri / electron/ phoenix web socket APIs",
4+
"version": "4.0.1",
55
"keywords": [
66
"phoenix",
77
"browser",
8-
"file stsyem",
8+
"file system",
99
"fs"
1010
],
1111
"author": "arun@core.ai",
1212
"homepage": "https://github.com/phcode-dev/phoenix-fs",
1313
"license": "GNU-AGPL3.0",
1414
"scripts": {
15-
"postinstall": "cd ./src-tauri/node-src/ && npm install && cd ../../",
15+
"postinstall": "cd ./src-tauri/node-src/ && npm install && cd ../../src-electron && npm install && cd ..",
1616
"prepublishOnly": "echo make sure to run `npm run remove-postinstall` before you run npm publish!!!",
1717
"remove-postinstall": "node src-build/remove-postinstall.js",
1818
"tauri": "tauri",
@@ -29,6 +29,7 @@
2929
"build": "npm run eslint && npm run _copy-node-src-dist && npm run _build-nonopt && npm run _make-debug-dist && npm run _build-optimized && npm run _copy-dist-to-test",
3030
"serve": "http-server . -p 8080 -c-1",
3131
"_serve-tauri": "http-server . -p 8081 -c-1",
32+
"test-electron": "npm run _serve-tauri & sleep 2 && ./src-electron/node_modules/.bin/electron src-electron/main.js",
3233
"bumpPatchVersion": "npm --no-git-tag-version version patch",
3334
"bumpPatchVersionWithGitTag": "npm version patch",
3435
"release": "npm run build && npm run bumpPatchVersionWithGitTag"

test/index.html

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@
99
<!-- Comment above line and Uncomment below line if you want to get more debug symbols in web inspector.-->
1010
<!-- <script src="virtualfs-debug.js"></script>-->
1111
<script>
12+
// Electron detection and setup
13+
if(window.electronAPI) {
14+
window.__ELECTRON__ = true;
15+
}
1216
window.addEventListener('keydown', function(event) {
1317
if (event.key === 'F5') {
1418
location.reload();
1519
}
1620
});
17-
if(window.showOpenFilePicker && !window.__TAURI__){
21+
if(window.showOpenFilePicker){
1822
window.supportsFsAccessAPIs = true;
1923
}
24+
if(window.__TAURI__ || window.__ELECTRON__) {
25+
window.supportsFsAccessAPIs = false; // use native fs apis directly
26+
}
2027
const TEST_TYPE_FS_ACCESS = "fs access";
2128
const TEST_TYPE_FILER = "filer";
22-
const TEST_TYPE_TAURI = "tauri";
23-
const TEST_TYPE_TAURI_WS = "tauriWs";
29+
const TEST_TYPE_TAURI = "tauri"; // electron will reuse this. tauri is our native edge name(which includes electron)
30+
const TEST_TYPE_TAURI_WS = "tauriWs"; // electron will reuse this
2431
window.IS_WINDOWS = navigator.userAgent.includes('Windows');
2532
</script>
2633
<script>
@@ -76,6 +83,18 @@
7683
},10000);
7784
}). catch(console.error);
7885
}
86+
// Electron detection and setup
87+
if(window.electronAPI){
88+
window.electronAPI.getNodeWSPort().then(port => {
89+
window.nodeWSEndpoint = `ws://localhost:${port}/phoenixFS`;
90+
fs.setNodeWSEndpoint(`ws://localhost:${port}/phoenixFS`);
91+
window.isNodeSetup = true;
92+
});
93+
// Heartbeat to keep Node server alive
94+
setInterval(() => {
95+
// Heartbeat is handled by main process in Electron
96+
}, 10000);
97+
}
7998
</script>
8099
<script src="thirdparty/chai@4.2.0.js"></script>
81100
<script src="thirdparty/mocha@10.3.0.js"></script>
@@ -98,29 +117,45 @@
98117
window.virtualTestPath = '/test-phoenix-fs';
99118

100119
function observeRunStatus(runner) {
101-
if(!window.__TAURI__){
120+
if(!window.__TAURI__ && !window.__ELECTRON__){
102121
return;
103122
}
104-
console.log("setting up tauri test reporters to log to system console.")
105-
function consoleLogToShell(message) {
106-
return __TAURI__.invoke("console_log", {message});
107-
}
108123

109-
async function quitIfNeeded(exitStatus) {
110-
if(!window.__TAURI__){
111-
return;
112-
}
113-
if(!location.href.startsWith("http://localhost:8081/test/")) {
114-
// during development, we dont switch off node at end of tests for ease of development and debug
115-
fs.stopNodeWSEndpoint();
116-
window.execNode(NODE_COMMANDS.TERMINATE);
117-
await waitForTrue(()=>{return window.isNodeTerminated;},1000);
118-
}
119-
__TAURI__.cli.getMatches().then(matches=>{
120-
if(matches?.args["quit-when-done"]?.occurrences) {
121-
__TAURI__.process.exit(exitStatus)
124+
let consoleLogToShell;
125+
let quitIfNeeded;
126+
127+
if(window.__TAURI__) {
128+
console.log("setting up tauri test reporters to log to system console.");
129+
consoleLogToShell = function(message) {
130+
return window.__TAURI__.invoke("console_log", {message});
131+
};
132+
quitIfNeeded = async function(exitStatus) {
133+
if(!location.href.startsWith("http://localhost:8081/test/")) {
134+
// during development, we dont switch off node at end of tests for ease of development and debug
135+
fs.stopNodeWSEndpoint();
136+
window.execNode(NODE_COMMANDS.TERMINATE);
137+
await waitForTrue(()=>{return window.isNodeTerminated;},1000);
122138
}
123-
});
139+
window.__TAURI__.cli.getMatches().then(matches=>{
140+
if(matches?.args["quit-when-done"]?.occurrences) {
141+
window.__TAURI__.process.exit(exitStatus)
142+
}
143+
});
144+
};
145+
} else if(window.__ELECTRON__) {
146+
console.log("setting up electron test reporters to log to system console.");
147+
consoleLogToShell = function(message) {
148+
window.electronAPI.consoleLog(message);
149+
return Promise.resolve();
150+
};
151+
quitIfNeeded = async function(exitStatus) {
152+
if(!location.href.startsWith("http://localhost:8081/test/")) {
153+
// during development, we dont quit at end of tests for ease of development and debug
154+
fs.stopNodeWSEndpoint();
155+
}
156+
// Always quit in Electron since there's no CLI arg parsing
157+
window.electronAPI.quitApp(exitStatus);
158+
};
124159
}
125160

126161
runner.on('end', function() {
@@ -180,17 +215,25 @@
180215
observeRunStatus(mocha.run());
181216
});
182217
}
183-
function runTauriTests() {
184-
if(window.__TAURI__){
185-
window.tauriTests = true;
186-
console.log("Tauri env detected. running tauri specific tests.");
218+
function runNativeAppTests() {
219+
if(window.__TAURI__ || window.__ELECTRON__){
220+
window.tauriTests = true; // reuse tauriTests flag for both
221+
console.log("Native app env detected. Running native app tests.");
187222
document.getElementById('openFolderButton').style = "display:none";
188-
observeRunStatus(mocha.run());
223+
// Wait for Node WebSocket setup before running tests
224+
function waitAndRun() {
225+
if(window.isNodeSetup) {
226+
observeRunStatus(mocha.run());
227+
} else {
228+
setTimeout(waitAndRun, 100);
229+
}
230+
}
231+
waitAndRun();
189232
}
190233
}
191234
</script>
192235
</head>
193-
<body onload="runTauriTests()">
236+
<body onload="runNativeAppTests()">
194237
<div id="mocha"></div>
195238
<button id="openFolderButton" onclick="openFolderAndRunTests()">Open any blank folder to start tests. Warning - folder contents will be deleted!!!!</button>
196239
</body>

0 commit comments

Comments
 (0)