Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vscode debug configuration #2

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "0.2.0",
"compounds": [
{
"name": "Main + renderer",
"configurations": ["Main", "Renderer"],
"stopAll": true
}
],
"configurations": [
{
"name": "Renderer",
"port": 9222,
"request": "attach",
"type": "chrome",
"webRoot": "${workspaceFolder}"
},
{
"name": "Main",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args": [".", "--remote-debugging-port=9222"],
"outputCapture": "std",
"console": "integratedTerminal"
}
]
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ To build:
npm install
npm run make
```

Debugging in vscode:

Debugging with vscode is possible as documented on [electron documentation](https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app#optional-debugging-from-vs-code)
```
The "Main + renderer" option will appear when you select "Run and Debug" from the sidebar, allowing you to set breakpoints and inspect all the variables among other things in both the main and renderer processes.
```
69 changes: 69 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const createWindow = () => {
const win = new BrowserWindow({
width: 1024,
height: 786,
title: "Simply Code",
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
Expand All @@ -22,6 +23,21 @@ const createWindow = () => {
win.loadURL('simplycode://index.html')
}

const createSecondWindow = (dataDir) => {
const win2 = new BrowserWindow({
width: 1024,
height: 786,
title: "My App",
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
})

win2.loadURL('simplyapp://generated.html')
}

function readRecursive(componentPath) {
if(componentPath.endsWith('\/')){
componentPath = componentPath.substring(0, (componentPath.length - 1))
Expand Down Expand Up @@ -87,6 +103,17 @@ protocol.registerSchemesAsPrivileged([
}
])

protocol.registerSchemesAsPrivileged([
{
scheme: 'simplyapp',
privileges: {
standard: true,
secure: true,
supportFetchAPI: true
}
}
])

async function createComponentDirectory(componentPath){
fs.mkdirSync((dataDir + componentPath), { recursive: true }, (err) => {
if (err) throw err
Expand Down Expand Up @@ -184,6 +211,46 @@ app.whenReady().then(() => {
break
}
}


})

protocol.handle('simplyapp', (request) => {
let componentPath = new URL(request.url).pathname
console.log('simplyapp:' + componentPath)
if(componentPath.endsWith('\/')){
componentPath = componentPath.substring(0, (componentPath.length - 1))
}

let pathicles = componentPath.split('\/');
let componentName = pathicles.pop();
let componentDirectory = pathicles.join('/');
pathicles.shift();


switch (request.method){
default:
if(componentPath.endsWith('\/')){
componentPath = componentPath.substring(0, (componentPath.length - 1))
}

if (!componentPath || componentPath === "/") {
const filestuff = fs.readFileSync(dataDir + '/generated.html')
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
} else {
const filestuff = fs.readFileSync(dataDir + componentDirectory + '\/' + componentName)
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
}
break
}




})

dataDir = dialog.showOpenDialogSync({properties: ['openDirectory']})[0];
Expand All @@ -192,6 +259,7 @@ app.whenReady().then(() => {
dataDir += "/";
}
createWindow()
createSecondWindow(dataDir)

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
Expand All @@ -200,6 +268,7 @@ app.whenReady().then(() => {
dataDir += "/";
}
createWindow()
createSecondWindow(dataDir)
}
})

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "echo \"test not implemented yet\" && exit 1",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
"make": "electron-forge make",
"postinstall": "scripts/post-install.sh"
},
"keywords": [
"javascript",
Expand All @@ -28,6 +29,7 @@
"electron": "^30.0.2"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.1"
"electron-squirrel-startup": "^1.0.1",
"simplycode": "github:simplyedit/simplycode"
}
}
17 changes: 17 additions & 0 deletions scripts/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

installSimplyCode() {
local sSourceDir sTargetDir

readonly sSourceDir="${npm_config_local_prefix}/node_modules/simplycode/www"
readonly sTargetDir="${npm_config_local_prefix}/simplycode"

cp -fR "${sSourceDir}" "${sTargetDir}"
}

if [[ ${BASH_SOURCE[0]} != "${0}" ]]; then
export -f installSimplyCode
else
installSimplyCode
exit $?
fi