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

let requests to /js/simply-edit.js resolve #5

Merged
merged 6 commits into from
Jun 12, 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
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# name: Release app
# on:
# workflow_dispatch:
# jobs:
# build:
# strategy:
# matrix:
# os:
# [
# { name: 'linux', image: 'ubuntu-latest' },
# { name: 'windows', image: 'windows-latest' },
# { name: 'macos', image: 'macos-latest' },
# ]
# runs-on: ${{ matrix.os.image }}
# steps:
# - name: Github checkout
# uses: actions/checkout@v4
# - name: Use Node.js
# uses: actions/setup-node@v4
# with:
# node-version: 20
# - run: npm ci
# - name: Publish app
# env:
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# run: npm run publish
41 changes: 34 additions & 7 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,44 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
asar: true,
icon: '/simplycode/camil_512x512.png',
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
}
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
name: '@electron-forge/maker-dmg',
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
},
},
{
name: '@electron-forge/maker-deb',
config: {},
config: {
bin: 'simply-code',
options: {
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
},
}
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
}
}
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
name: '@SimplyEdit/simplycode-electron/tree/electron-forge-github-actions',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
Expand All @@ -41,4 +56,16 @@ module.exports = {
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
publishers: [
{
name: 'simply-code',
config: {
repository: {
owner: 'Govert Combée',
name: 'simply-code'
},
prerelease: true
}
}
]
};
81 changes: 51 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const createWindow = () => {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
},
icon: path.join(__dirname, '/simplycode/camil_512x512.png')

})

win.loadURL('simplycode://index.html')
Expand All @@ -32,7 +34,8 @@ const createSecondWindow = (dataDir) => {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
},
icon: path.join(__dirname,'/simplycode/camil_512x512.png')
})

win2.loadURL('simplyapp://generated.html')
Expand Down Expand Up @@ -100,10 +103,7 @@ protocol.registerSchemesAsPrivileged([
secure: true,
supportFetchAPI: true
}
}
])

protocol.registerSchemesAsPrivileged([
},
{
scheme: 'simplyapp',
privileges: {
Expand Down Expand Up @@ -133,6 +133,8 @@ async function createComponentFile(componentPath, filecontent){
}

app.whenReady().then(() => {
if (require('electron-squirrel-startup') === true) app.quit(); // prevents Squirrel.Windows from launching your app multiple times during the installation/updating/uninstallation.

protocol.handle('simplycode', (request) => {
let componentPath = new URL(request.url).pathname
console.log(componentPath)
Expand Down Expand Up @@ -195,20 +197,23 @@ app.whenReady().then(() => {
})
} else {
var target = __dirname + '/simplycode' + componentDirectory + '\/' + componentName;
if (fs.lstatSync(target).isDirectory()) {
// Do the recursive read thing;
if(fs.existsSync(target)) {

if (fs.lstatSync(target).isDirectory()) {
// Do the recursive read thing;
} else {
const filestuff = fs.readFileSync(__dirname + '/simplycode' + componentDirectory + '\/' + componentName)
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
}
} else {
const filestuff = fs.readFileSync(__dirname + '/simplycode' + componentDirectory + '\/' + componentName)
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
return new Response("Not found", {"status" : 404})
}
}
break
}
}


})

protocol.handle('simplyapp', (request) => {
Expand All @@ -218,35 +223,52 @@ app.whenReady().then(() => {
componentPath = componentPath.substring(0, (componentPath.length - 1))
}

let pathicles = componentPath.split('\/');
let pathicles = componentPath.split('\/'); // also splits on an empty string

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

if (pathicles[0] == ''){
pathicles.shift()
}

let componentDirectory = pathicles.join('/');

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' }
})
var target = dataDir + componentDirectory + '\/' + componentName;
if(fs.existsSync(target)) {
const filestuff = fs.readFileSync(target)

return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
} else {
if (
(componentPath === "/js/simply-edit.js") ||
(componentPath === "/js/simply.everything.js")
) {
const filestuff = fs.readFileSync(__dirname + '/simplycode' + componentDirectory + '\/' + componentName)
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})
}
return new Response("Not found", {"status" : 404})
}
}
break
}




}
}
})

if (process.argv[1]) {
Expand All @@ -257,11 +279,12 @@ app.whenReady().then(() => {
console.log(dataDir);
if (!dataDir.match(/\/$/)) {
dataDir += "/";
console.log(dataDir);
}
createWindow()
createSecondWindow(dataDir)

app.on('activate', () => {
app.on('activate', () => { // needed for macos
if (BrowserWindow.getAllWindows().length === 0) {
if (process.argv[1]) {
dataDir = path.resolve(process.argv[1]);
Expand All @@ -275,8 +298,6 @@ app.whenReady().then(() => {
createSecondWindow(dataDir)
}
})


})

app.on('window-all-closed', () => {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"postinstall": "scripts/post-install.sh"
"postinstall": "scripts/post-install.sh",
"publish": "electron-forge publish"
},
"productName": "simply-code",
"keywords": [
"javascript",
"html",
Expand All @@ -25,8 +27,9 @@
"@electron-forge/maker-zip": "^7.4.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
"@electron-forge/plugin-fuses": "^7.4.0",
"@electron-forge/publisher-github": "^7.4.0",
"@electron/fuses": "^1.8.0",
"electron": "^30.0.2"
"electron": "^30.0.9"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.1",
Expand Down