Skip to content

Commit 42f925c

Browse files
committed
Merge branch 'v.0.47.0'
2 parents d19c96b + 7ba49aa commit 42f925c

File tree

114 files changed

+181878
-75789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+181878
-75789
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.15.1
1+
v22.18.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[Publii](https://getpublii.com/) is a desktop-based CMS for Windows, Mac and Linux that makes creating static websites fast
1010
and hassle-free, even for beginners.
1111

12-
**Current version: 0.46.5 (build 17089)**
12+
**Current version: 0.47.0 (build 17290)**
1313

1414
## Why Publii?
1515
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an

app/back-end/app-preload.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { contextBridge, ipcRenderer } = require('electron');
1+
const { contextBridge, ipcRenderer, webUtils } = require('electron');
22

33
contextBridge.exposeInMainWorld('mainProcessAPI', {
44
shellShowItemInFolder: (url) => ipcRenderer.invoke('publii-shell-show-item-in-folder', url),
@@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
77
existsSync: (pathToCheck) => ipcRenderer.invoke('publii-native-exists-sync', pathToCheck),
88
normalizePath: (pathToNormalize) => ipcRenderer.invoke('publii-native-normalize-path', pathToNormalize),
99
createMD5: (value) => ipcRenderer.invoke('publii-native-md5', value),
10+
getPathForFile: (value) => webUtils.getPathForFile(value),
1011
getEnv: () => ({
1112
name: process.env.NODE_ENV,
1213
nodeVersion: process.versions.node,
@@ -99,7 +100,9 @@ contextBridge.exposeInMainWorld('mainProcessAPI', {
99100
'app-site-get-plugin-config',
100101
'app-site-save-plugin-config',
101102
'app-close',
102-
'app-set-ui-zoom-level'
103+
'app-set-ui-zoom-level',
104+
'app-set-notifications-center-state',
105+
'app-get-notifications-file'
103106
];
104107

105108
if (validChannels.includes(channel)) {

app/back-end/app.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Plugins = require('./plugins.js');
2424
const DBUtils = require('./helpers/db.utils.js');
2525
const Site = require('./site.js');
2626
const Utils = require('./helpers/utils.js');
27+
const FileHelper = require('./helpers/file.js');
2728
// List of the Event classes
2829
const EventClasses = require('./events/_modules.js');
2930
// Migration classes
@@ -52,7 +53,8 @@ class App {
5253
this.initPath = path.join(this.appDir, 'config', 'window-config.json');
5354
this.appConfigPath = path.join(this.appDir, 'config', 'app-config.json');
5455
this.tinymceOverridedConfigPath = path.join(this.appDir, 'config', 'tinymce.override.json');
55-
this.versionData = JSON.parse(fs.readFileSync(__dirname + '/builddata.json', 'utf8'));
56+
this.versionData = JSON.parse(FileHelper.readFileSync(__dirname + '/builddata.json', 'utf8'));
57+
this.versionData.os = os.platform() === 'darwin' ? 'mac' : os.platform() === 'linux' ? 'linux' : 'win';
5658
this.windowBounds = null;
5759
this.appConfig = null;
5860
this.tinymceOverridedConfig = {};
@@ -165,8 +167,8 @@ class App {
165167

166168
// Check if both config.json files exists
167169
if (fs.existsSync(appThemeConfig) && fs.existsSync(userThemeConfig)) {
168-
let appThemeData = JSON.parse(fs.readFileSync(appThemeConfig, 'utf8'));
169-
let userThemeData = JSON.parse(fs.readFileSync(userThemeConfig, 'utf8'));
170+
let appThemeData = JSON.parse(FileHelper.readFileSync(appThemeConfig, 'utf8'));
171+
let userThemeData = JSON.parse(FileHelper.readFileSync(userThemeConfig, 'utf8'));
170172

171173
// If app theme is newer version than the existing one
172174
if(compare(appThemeData.version, userThemeData.version) === 1) {
@@ -231,7 +233,7 @@ class App {
231233
let themeDir = path.join(siteDir, 'input', 'themes', themes.currentTheme(true));
232234
let themeOverridesDir = path.join(siteDir, 'input', 'themes', themes.currentTheme(true) + '-override');
233235
let themeConfig = Themes.loadThemeConfig(themeConfigPath, themeDir);
234-
let menuStructure = fs.readFileSync(menuConfigPath, 'utf8');
236+
let menuStructure = FileHelper.readFileSync(menuConfigPath, 'utf8');
235237
let parsedMenuStructure = {};
236238

237239
try {
@@ -283,8 +285,14 @@ class App {
283285

284286
// Load the config
285287
let defaultSiteConfig = JSON.parse(JSON.stringify(defaultAstCurrentSiteConfig));
286-
let siteConfig = fs.readFileSync(configFilePath);
287-
siteConfig = JSON.parse(siteConfig);
288+
let siteConfig = FileHelper.readFileSync(configFilePath);
289+
290+
try {
291+
siteConfig = JSON.parse(siteConfig);
292+
} catch (e) {
293+
dialog.showErrorBox('Publii cannot read site config', 'There is an issue with file: ' + configFilePath + "\n\nError details: " + e.message);
294+
return;
295+
}
288296

289297
if (siteConfig.name !== siteName) {
290298
siteConfig.name = siteName;
@@ -437,7 +445,7 @@ class App {
437445
loadConfig () {
438446
// Try to get window bounds
439447
try {
440-
this.windowBounds = JSON.parse(fs.readFileSync(this.initPath, 'utf8'));
448+
this.windowBounds = JSON.parse(FileHelper.readFileSync(this.initPath, 'utf8'));
441449
} catch (e) {
442450
console.log('The window-config.json file will be created');
443451
}
@@ -490,7 +498,7 @@ class App {
490498

491499
// Try to get application config
492500
try {
493-
this.appConfig = JSON.parse(fs.readFileSync(this.appConfigPath, 'utf8'));
501+
this.appConfig = JSON.parse(FileHelper.readFileSync(this.appConfigPath, 'utf8'));
494502
this.appConfig = Utils.mergeObjects(JSON.parse(JSON.stringify(defaultAstAppConfig)), this.appConfig);
495503
} catch (e) {
496504
if (this.hasPermissionsErrors(e)) {
@@ -518,7 +526,7 @@ class App {
518526
loadAdditionalConfig () {
519527
// Try to get TinyMCE overrided config
520528
try {
521-
this.tinymceOverridedConfig = JSON.parse(fs.readFileSync(this.tinymceOverridedConfigPath, 'utf8'));
529+
this.tinymceOverridedConfig = JSON.parse(FileHelper.readFileSync(this.tinymceOverridedConfigPath, 'utf8'));
522530
} catch (e) {}
523531

524532
if (this.appConfig.sitesLocation) {

app/back-end/author.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const slug = require('./helpers/slug');
88
const ImageHelper = require('./helpers/image.helper.js');
99
const Themes = require('./themes.js');
1010
const Utils = require('./helpers/utils.js');
11+
const FileHelper = require('./helpers/file.js');
1112

1213
/**
1314
* Author Model - used for operations connected with author management
@@ -93,11 +94,9 @@ class Author extends Model {
9394
}
9495

9596
if (this.id !== 0) {
96-
this.checkAndCleanImages();
9797
return this.updateAuthor();
9898
}
9999

100-
this.checkAndCleanImages();
101100
return this.addAuthor();
102101
}
103102

@@ -136,6 +135,8 @@ class Author extends Model {
136135
}
137136
}
138137

138+
this.checkAndCleanImages();
139+
139140
return {
140141
status: true,
141142
message: 'author-added',
@@ -169,6 +170,8 @@ class Author extends Model {
169170
id: this.id
170171
});
171172

173+
this.checkAndCleanImages();
174+
172175
return {
173176
status: true,
174177
message: 'author-updated',
@@ -366,7 +369,7 @@ class Author extends Model {
366369
let themeConfigPath = path.join(this.application.sitesDir, this.site, 'input', 'config', 'theme.config.json');
367370

368371
if (fs.existsSync(themeConfigPath)) {
369-
let themeConfigString = fs.readFileSync(themeConfigPath, 'utf8');
372+
let themeConfigString = FileHelper.readFileSync(themeConfigPath, 'utf8');
370373
themesHelper.checkAndCleanImages(themeConfigString);
371374
}
372375
}

app/back-end/builddata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "0.46.5",
3-
"build": 17089
2+
"version": "0.47.0",
3+
"build": 17290
44
}

app/back-end/events/_modules.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ module.exports = {
1515
MenuEvents: require('./menu.js'),
1616
PreviewEvents: require('./preview.js'),
1717
NotificationsEvents: require('./notifications.js'),
18-
ThemeUpdatesEvents: require('./theme-updates.js'),
1918
BackupEvents: require('./backup.js'),
2019
AuthorEvents: require('./author.js'),
2120
AuthorsEvents: require('./authors.js'),

app/back-end/events/app.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs-extra');
22
const path = require('path');
3+
const FileHelper = require('../helpers/file.js');
34
const ipcMain = require('electron').ipcMain;
45
const Themes = require('../themes.js');
56
const Languages = require('../languages.js');
@@ -97,7 +98,7 @@ class AppEvents {
9798
* Save app color theme config
9899
*/
99100
ipcMain.on('app-save-color-theme', function (event, theme) {
100-
let appConfig = fs.readFileSync(appInstance.appConfigPath, 'utf8');
101+
let appConfig = FileHelper.readFileSync(appInstance.appConfigPath, 'utf8');
101102

102103
try {
103104
appConfig = JSON.parse(appConfig);
@@ -440,7 +441,7 @@ class AppEvents {
440441
}
441442

442443
let filePath = path.join(appInstance.app.getPath('logs'), filename);
443-
let fileContent = fs.readFileSync(filePath, 'utf8');
444+
let fileContent = FileHelper.readFileSync(filePath, 'utf8');
444445

445446
event.sender.send('app-log-file-loaded', {
446447
fileContent: fileContent
@@ -458,7 +459,7 @@ class AppEvents {
458459
return;
459460
}
460461

461-
let appConfig = fs.readFileSync(appInstance.appConfigPath, 'utf8');
462+
let appConfig = FileHelper.readFileSync(appInstance.appConfigPath, 'utf8');
462463

463464
try {
464465
appConfig = JSON.parse(appConfig);
@@ -470,6 +471,21 @@ class AppEvents {
470471

471472
appInstance.mainWindow.webContents.setZoomFactor(zoomLevel);
472473
});
474+
475+
/**
476+
* Set notifications center state
477+
*/
478+
ipcMain.on('app-set-notifications-center-state', function(event, state) {
479+
let appConfig = fs.readFileSync(appInstance.appConfigPath, 'utf8');
480+
481+
try {
482+
appConfig = JSON.parse(appConfig);
483+
appConfig.notificationsStatus = state;
484+
fs.writeFileSync(appInstance.appConfigPath, JSON.stringify(appConfig, null, 4));
485+
} catch (e) {
486+
console.log('(!) App was unable to save the notifications center state');
487+
}
488+
});
473489
}
474490
}
475491

app/back-end/events/credits.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs-extra');
22
const path = require('path');
33
const ipcMain = require('electron').ipcMain;
4+
const FileHelper = require('../helpers/file.js');
45

56
/*
67
* Events for the IPC communication regarding credits
@@ -18,7 +19,7 @@ class CreditsEvents {
1819
}
1920

2021
if(fs.existsSync(filePath)) {
21-
licenseText = fs.readFileSync(filePath, 'utf-8');
22+
licenseText = FileHelper.readFileSync(filePath, 'utf-8');
2223
}
2324

2425
event.sender.send('app-license-loaded', licenseText);

app/back-end/events/notifications.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,38 @@ class NotificationsEvents {
1010
constructor(appInstance) {
1111
// Save
1212
ipcMain.on('app-notifications-retrieve', function(event, downloadNotifications) {
13+
let platform;
14+
15+
if (process.platform === 'darwin') {
16+
platform = process.arch === 'arm64' ? 'mac-arm64' : 'mac-x86';
17+
} else if (process.platform === 'win32') {
18+
platform = 'win';
19+
} else {
20+
platform = 'linux';
21+
}
22+
1323
let updatesHelper = new UpdatesHelper({
1424
event: event,
15-
filePath: path.join(appInstance.app.getPath('logs'), 'notifications.json'),
16-
namespace: 'notifications',
17-
url: 'https://getpublii.com/notifications.json',
18-
contentField: 'text',
25+
filePath: path.join(appInstance.app.getPath('logs'), 'updates.json'),
26+
url: 'https://notifications.getpublii.com/updates-' + platform + '.json',
1927
forceDownload: downloadNotifications
2028
});
2129

2230
updatesHelper.retrieve();
2331
});
32+
33+
// Get notifications file
34+
ipcMain.handle('app-get-notifications-file', async (event, fileName) => {
35+
let filePath = path.join(appInstance.app.getPath('logs'), fileName);
36+
37+
try {
38+
let data = await appInstance.app.readFile(filePath, 'utf8');
39+
return JSON.parse(data);
40+
} catch (error) {
41+
console.error(`Error reading notifications file: ${error.message}`);
42+
return false;
43+
}
44+
});
2445
}
2546
}
2647

0 commit comments

Comments
 (0)