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

Build with obfuscated bundle #155

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
44473fe
Check for bundle and build if exists
simonhamp Sep 5, 2024
42ce4b6
Fix app name setting in the package.json
simonhamp Sep 5, 2024
2646655
Copy the installer icon
simonhamp Sep 5, 2024
a48d16a
Fix styling
simonhamp Sep 5, 2024
1f429ea
Update to latest binaries
simonhamp Sep 5, 2024
7daf9fd
Fix bundle copy
simonhamp Sep 11, 2024
9a02339
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp Nov 12, 2024
8b0e43d
Restore changes from other PR
simonhamp Dec 9, 2024
aeee3fe
Merge branch 'main' into feature/build-with-obfuscated-bundle
simonhamp Dec 18, 2024
0938806
Move trait
simonhamp Dec 10, 2024
ecde43e
Add env file processing in build step
simonhamp Dec 19, 2024
461acb3
Fix styling
simonhamp Dec 19, 2024
bd9419e
Don't copy builds, logs or caches
simonhamp Dec 19, 2024
9c98c4c
Merge branch 'refs/heads/main' into srwiez/build-with-obfuscated-bundle
SRWieZ Jan 14, 2025
625c976
fix: php.js recompiled
SRWieZ Jan 14, 2025
35a8589
chore: dependencies
SRWieZ Jan 14, 2025
e888004
fix: moved CleansEnvFile to nativephp/laravel
SRWieZ Jan 14, 2025
0397834
fix: missing existsSync() and missing directories
SRWieZ Jan 14, 2025
c00500f
feat: more logs to know which step is hanging
SRWieZ Jan 14, 2025
b36b737
fix: menubar context menu
SRWieZ Jan 14, 2025
7e69b6b
fix: PHP errors not showing
SRWieZ Jan 15, 2025
d834656
fix: menubar context menu
SRWieZ Jan 16, 2025
a6d6d69
Revert "fix: menubar context menu"
SRWieZ Jan 21, 2025
ba1756b
Revert "fix: menubar context menu"
SRWieZ Jan 21, 2025
c0f5745
Merge branch 'main' into srwiez/build-with-obfuscated-bundle
SRWieZ Jan 21, 2025
0f45f7b
wip
SRWieZ Jan 29, 2025
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
"larastan/larastan": "^2.9",
"laravel/pint": "^1.0",
"nunomaduro/collision": "^7.9",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^8.18",
"pestphp/pest": "^2.7",
"pestphp/pest-plugin-arch": "^2.0",
Expand Down
4 changes: 1 addition & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ parameters:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true


138 changes: 84 additions & 54 deletions resources/js/electron-builder.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from 'os';
import { join } from 'path';
import { mkdtempSync } from 'fs';
import path, { join } from 'path';
import {existsSync, mkdtempSync} from 'fs';

// Workaround for CommonJS module
import fs_extra from 'fs-extra';
const { copySync, removeSync, writeJsonSync } = fs_extra;
const { copySync, removeSync, writeJsonSync, mkdirpSync } = fs_extra;

const isBuilding = process.env.NATIVEPHP_BUILDING;
const appId = process.env.NATIVEPHP_APP_ID;
Expand Down Expand Up @@ -33,12 +33,8 @@ if (isDarwin) {
targetOs = 'mac';
}


let updaterConfig = {};

// We wouldn't need these since its not representing the target platform
console.log("Arch: ", process.arch)
console.log("Platform: ", process.platform)
try {
updaterConfig = process.env.NATIVEPHP_UPDATER_CONFIG;
updaterConfig = JSON.parse(updaterConfig);
Expand All @@ -47,6 +43,8 @@ try {
}

if (isBuilding) {
console.log("Current platform: ", process.platform)
console.log("Current arch: ", process.arch)

console.log();
console.log('===================================================================');
Expand All @@ -61,60 +59,92 @@ if (isBuilding) {

removeSync(appPath);

// As we can't copy into a subdirectory of ourself we need to copy to a temp directory
let tmpDir = mkdtempSync(join(os.tmpdir(), 'nativephp'));

copySync(process.env.APP_PATH, tmpDir, {
overwrite: true,
dereference: true,
filter: (src, dest) => {
let skip = [
// Skip .git and Dev directories
join(process.env.APP_PATH, '.git'),
join(process.env.APP_PATH, 'docker'),
join(process.env.APP_PATH, 'packages'),

// Only needed for local testing
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'vendor'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'laravel', 'vendor'),

join(process.env.APP_PATH, 'vendor', 'nativephp', 'php-bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'resources'),
join(process.env.APP_PATH, 'node_modules'),
join(process.env.APP_PATH, 'dist'),
];

let shouldSkip = false;
skip.forEach((path) => {
if (src.indexOf(path) === 0) {
shouldSkip = true;
}
});

return !shouldSkip;
}
});

copySync(tmpDir, appPath);

// Electron build removes empty folders, so we have to create dummy files
// dotfiles unfortunately don't work.
writeJsonSync(join(appPath, 'storage', 'framework', 'cache', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'sessions', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'testing', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'framework', 'views', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'app', 'public', '_native.json'), {})
writeJsonSync(join(appPath, 'storage', 'logs', '_native.json'), {})

removeSync(tmpDir);
let bundle = join(process.env.APP_PATH, 'build', '__nativephp_app_bundle');

if (existsSync(bundle)) {
copySync(bundle, join(appPath, 'bundle', '__nativephp_app_bundle'));
} else {
// As we can't copy into a subdirectory of ourself we need to copy to a temp directory
let tmpDir = mkdtempSync(join(os.tmpdir(), 'nativephp'));

console.warn('===================================================================');
console.warn(' * * * INSECURE BUILD * * *');
console.warn('===================================================================');
console.warn('Secure app bundle not found! Building with exposed source files.');
console.warn('See https://nativephp.com/docs/publishing/building#security');
console.warn('===================================================================');

console.log('Copying app to temporary directory for build');
copySync(process.env.APP_PATH, tmpDir, {
overwrite: true,
dereference: true,
filter: (src) => {
let skip = [
// Skip .git and Dev directories
join(process.env.APP_PATH, '.git'),
join(process.env.APP_PATH, 'docker'),
join(process.env.APP_PATH, 'packages'),

// Only needed for local testing
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'vendor'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'laravel', 'vendor'),

join(process.env.APP_PATH, 'vendor', 'nativephp', 'php-bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'bin'),
join(process.env.APP_PATH, 'vendor', 'nativephp', 'electron', 'resources'),
join(process.env.APP_PATH, 'node_modules'),
join(process.env.APP_PATH, 'dist'),
join(process.env.APP_PATH, 'build'),

join(process.env.APP_PATH, 'storage', 'framework'),
join(process.env.APP_PATH, 'storage', 'logs'),
];

let shouldSkip = false;
skip.forEach((path) => {
if (src.indexOf(path) === 0) {
shouldSkip = true;
}
});

return !shouldSkip;
}
});

copySync(tmpDir, appPath);

console.log('Preparing directories for electron build');
// Electron build removes empty folders, so we have to create dummy files
// dotfiles unfortunately don't work.
const emptyPaths = [
join(appPath, 'storage', 'framework', 'cache', '_native.json'),
join(appPath, 'storage', 'framework', 'sessions', '_native.json'),
join(appPath, 'storage', 'framework', 'testing', '_native.json'),
join(appPath, 'storage', 'framework', 'views', '_native.json'),
join(appPath, 'storage', 'app', 'public', '_native.json'),
join(appPath, 'storage', 'logs', '_native.json'),
];

emptyPaths.forEach((emptyPath) => {
// Create directory if it doesn't exist
let dir = path.dirname(emptyPath);
if (!existsSync(dir)) {
mkdirpSync(dir);
}

writeJsonSync(emptyPath, {});
});

removeSync(tmpDir);
}

console.log();
console.log('Copied app to resources');
console.log(join(process.env.APP_PATH, 'dist'));
console.log();
console.log('===================================================================');
console.log(' Starting build...');
console.log('===================================================================');
console.log();
} catch (e) {
console.error();
Expand Down
17 changes: 17 additions & 0 deletions resources/js/electron-plugin/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class NativePHP {
constructor() {
this.processes = [];
this.schedulerInterval = undefined;
this.mainWindow = null;
}
bootstrap(app, icon, phpBinary, cert) {
initialize();
Expand Down Expand Up @@ -66,6 +67,15 @@ class NativePHP {
}
event.preventDefault();
});
if (process.platform === 'win32') {
app.on('second-instance', (event, commandLine, workingDirectory) => {
if (this.mainWindow) {
if (this.mainWindow.isMinimized())
this.mainWindow.restore();
this.mainWindow.focus();
}
});
}
}
bootstrapApp(app) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -124,6 +134,13 @@ class NativePHP {
else {
app.setAsDefaultProtocolClient(deepLinkProtocol);
}
if (process.platform === 'win32') {
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
return;
}
}
}
}
startAutoUpdater(config) {
Expand Down
Loading
Loading