Skip to content

Commit d0e4c0b

Browse files
Add installed/portable detection
1 parent 27771e8 commit d0e4c0b

File tree

5 files changed

+113
-16
lines changed

5 files changed

+113
-16
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ jobs:
6262
restore-keys: |
6363
${{ runner.os }}-electron-
6464
65-
- name: Run build script
65+
- name: Run build script for installers
6666
run: npx yarn dist -- --url ${{ secrets.SITE_URL }}
6767

68-
- name: Zip portable builds
68+
- name: Run build script for portable
6969
if: runner.os == 'Windows'
70-
run: Compress-Archive -Path .\dist\win-unpacked\* -DestinationPath .\dist\Sploder-Portable-x64.zip && Compress-Archive -Path .\dist\win-ia32-unpacked\* -DestinationPath .\dist\Sploder-Portable-ia32.zip
70+
run: npx yarn dist -- --url ${{ secrets.SITE_URL }} --portable
7171

7272
- name: Upload .exe files
7373
if: runner.os == 'Windows'

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
"yarn": "1.22.22"
2626
},
2727
"build": {
28-
"asar": true, "files": [ "./dist/main/*" ], "win": {},
28+
"asar": true,
29+
"files": [ "./dist/main/*" ],
30+
"win": {
31+
"target": [
32+
{
33+
"target": "nsis",
34+
"arch": ["x64", "ia32"]
35+
}
36+
]
37+
},
2938
"publish": null,
3039
"appId": "com.sploder",
3140
"productName": "Sploder",

scripts/build.js

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ const path = require('path');
1010
// Parse command line arguments
1111
const args = process.argv.slice(2);
1212
const urlArgIndex = args.indexOf('--url');
13+
const portableArgIndex = args.indexOf('--portable');
1314
let customUrl = null;
15+
let isPortable = false;
1416

1517
if (urlArgIndex !== -1 && args[urlArgIndex + 1]) {
1618
customUrl = args[urlArgIndex + 1];
1719
console.log(`\x1b[36mCustom URL detected: ${customUrl}\x1b[0m`);
1820
}
1921

22+
if (portableArgIndex !== -1) {
23+
isPortable = true;
24+
console.log(`\x1b[36mBuilding portable version\x1b[0m`);
25+
} else {
26+
console.log(`\x1b[36mBuilding installed version\x1b[0m`);
27+
}
28+
2029
// Update config if URL is provided
2130
if (customUrl) {
2231
try {
@@ -41,7 +50,42 @@ if (customUrl) {
4150
}
4251
}
4352

44-
// Run the compilation step
53+
// Inject build configuration into the main process file
54+
try {
55+
const mainPath = path.join(__dirname, '..', 'src', 'main', 'index.js');
56+
console.log(`\x1b[36mInjecting build configuration into: ${mainPath}\x1b[0m`);
57+
58+
// Read the main file
59+
let mainContent = fs.readFileSync(mainPath, 'utf8');
60+
61+
// Remove any existing injected build configuration
62+
mainContent = mainContent.replace(
63+
/\/\/ Injected build configuration\nconst BUILD_CONFIG = .*?;\n\n/g,
64+
''
65+
);
66+
67+
// Define build configuration
68+
const buildConfig = {
69+
packagingMethod: isPortable ? 'portable' : 'installed'
70+
};
71+
72+
// Inject BUILD_CONFIG before the main logic
73+
const buildConfigInjection = `// Injected build configuration
74+
const BUILD_CONFIG = ${JSON.stringify(buildConfig)};
75+
76+
`;
77+
78+
// Add it at the beginning of the file (after requires)
79+
const requiresEndPattern = /const isDev = !app\.isPackaged;/;
80+
mainContent = mainContent.replace(requiresEndPattern, `${buildConfigInjection}const isDev = !app.isPackaged;`);
81+
82+
// Write the updated main file back
83+
fs.writeFileSync(mainPath, mainContent, 'utf8');
84+
console.log(`\x1b[32mBuild configuration injected: ${JSON.stringify(buildConfig)}\x1b[0m`);
85+
} catch (error) {
86+
console.error(`\x1b[31mError injecting build configuration: ${error.message}\x1b[0m`);
87+
process.exit(1);
88+
}// Run the compilation step
4589
console.log('\x1b[36mCompiling the application...\x1b[0m');
4690
try {
4791
execSync('yarn compile', { stdio: 'inherit' });
@@ -53,17 +97,30 @@ try {
5397
// Run the appropriate electron-builder command based on the platform
5498
console.log('\x1b[36mBuilding distributable packages...\x1b[0m');
5599
try {
56-
// Pass all original arguments (except --url and the URL) to electron-builder
100+
// Pass all original arguments (except --url, --portable and their values) to electron-builder
57101
const filteredArgs = args.filter((arg, index) => {
58-
return index !== urlArgIndex && index !== urlArgIndex + 1;
102+
return index !== urlArgIndex && index !== urlArgIndex + 1 && index !== portableArgIndex;
59103
}).join(' ');
60104

61-
if (process.platform === 'win32') {
62-
execSync(`npx yarn electron-builder --ia32 --x64 ${filteredArgs}`, { stdio: 'inherit' });
63-
} else if (process.platform === 'darwin') {
64-
execSync(`electron-builder --mac --x64 ${filteredArgs}`, { stdio: 'inherit' });
105+
if (isPortable) {
106+
// Build only portable versions
107+
if (process.platform === 'win32') {
108+
execSync(`npx yarn electron-builder --win zip --ia32 --x64 -c.win.artifactName="Sploder-Portable-\${arch}.\${ext}" ${filteredArgs}`, { stdio: 'inherit' });
109+
} else if (process.platform === 'darwin') {
110+
execSync(`electron-builder --mac zip --x64 -c.mac.artifactName="Sploder-Portable-\${arch}.\${ext}" ${filteredArgs}`, { stdio: 'inherit' });
111+
} else {
112+
// For Linux, we'll use the unpacked directory as "portable"
113+
execSync(`electron-builder --linux dir ${filteredArgs}`, { stdio: 'inherit' });
114+
}
65115
} else {
66-
execSync(`electron-builder --linux appimage snap deb rpm pacman ${filteredArgs}`, { stdio: 'inherit' });
116+
// Build installer versions (default)
117+
if (process.platform === 'win32') {
118+
execSync(`npx yarn electron-builder --win nsis --ia32 --x64 ${filteredArgs}`, { stdio: 'inherit' });
119+
} else if (process.platform === 'darwin') {
120+
execSync(`electron-builder --mac --x64 ${filteredArgs}`, { stdio: 'inherit' });
121+
} else {
122+
execSync(`electron-builder --linux appimage snap deb rpm pacman ${filteredArgs}`, { stdio: 'inherit' });
123+
}
67124
}
68125

69126
console.log('\x1b[32mBuild completed successfully!\x1b[0m');

src/config.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
*/
55

66
// Create configuration factory function
7-
function createConfig(isDev = false) {
7+
function createConfig(isDev = false, buildConfig = {}) {
88
return {
99
// Base URL for the application
1010
baseUrl: "https://www.sploder.net",
1111

12+
// Build-time configuration
13+
build: {
14+
packagingMethod: buildConfig.packagingMethod || 'portable', // 'portable' or 'installed'
15+
...buildConfig
16+
},
17+
1218
// Specific endpoints
1319
endpoints: {
1420
update: isDev ? "/" : "/update",
@@ -17,7 +23,27 @@ function createConfig(isDev = false) {
1723

1824
// Generate a full URL for an endpoint
1925
getUrl: function(endpoint) {
20-
return this.baseUrl + (this.endpoints[endpoint] || endpoint);
26+
const baseUrl = this.baseUrl + (this.endpoints[endpoint] || endpoint);
27+
28+
// Add parameters for update endpoint
29+
if (endpoint === 'update') {
30+
const params = new URLSearchParams();
31+
32+
// Add OS information
33+
params.append('os', process.platform);
34+
35+
// Add architecture information
36+
params.append('arch', process.arch);
37+
38+
// Add packaging method from build configuration (Windows only)
39+
if (process.platform === 'win32') {
40+
params.append('method', this.build.packagingMethod);
41+
}
42+
43+
return `${baseUrl}?${params.toString()}`;
44+
}
45+
46+
return baseUrl;
2147
}
2248
};
2349
}

src/main/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ if (process.platform == "win32") {
1818
}
1919
let win;
2020
let pluginName;
21+
// Injected build configuration
22+
const BUILD_CONFIG = {"packagingMethod":"installed"};
23+
2124
const isDev = !app.isPackaged;
2225

23-
// Create configuration with proper isDev detection
24-
const config = createConfig(isDev);
26+
// Create configuration with proper isDev detection and build config
27+
// BUILD_CONFIG will be replaced during build process
28+
const buildConfig = typeof BUILD_CONFIG !== 'undefined' ? BUILD_CONFIG : {};
29+
const config = createConfig(isDev, buildConfig);
2530

2631
let rendererPath, preloadPath;
2732
if(isDev) {

0 commit comments

Comments
 (0)