Skip to content

Commit

Permalink
Merge branch 'v.0.36'
Browse files Browse the repository at this point in the history
  • Loading branch information
dziudek committed May 22, 2020
2 parents 57e35b8 + 268a490 commit f75b25e
Show file tree
Hide file tree
Showing 398 changed files with 31,836 additions and 17,579 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"presets": [
["env", { "modules": false }],
"stage-3"
],
"plugins": [
"syntax-dynamic-import"
]
}
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ npm-debug.log
/node_modules/
/app/node_modules/
/coverage
/app/dist/css
/app/dist/vendor
/app/dist/*.js
/app/dist/*.js.map
/app/dist/*.png
/app/dist/*.svg
/app/dist/*.node
!/app/dist/index.html
!/app/dist/editor-webview-preload.js
/dist
/app/dist/
/cache/
/StaticBlog-darwin-x64/
/StaticBlog-win32-x64/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[Publii](https://getpublii.com/) is a desktop-based CMS for Windows, Mac and Linux that makes creating static websites fast
and hassle-free, even for beginners.

**Current version: 0.35.3 (build 12100)**
**Current version: 0.36.0 (build 13210)**

## Why Publii?
Unlike static-site generators that are often unwieldy and difficult to use, Publii provides an
Expand Down
8 changes: 8 additions & 0 deletions app/back-end/app-preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ContextMenuBuilder = require('./helpers/context-menu-builder.js');
const ContextMenuListener = require('./helpers/context-menu-listener.js');

let contextMenuBuilder = new ContextMenuBuilder();
let contextMenuListener = new ContextMenuListener((info) => {
contextMenuBuilder.showPopupMenu(info);
});

169 changes: 76 additions & 93 deletions app/back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
// Necessary packages
const fs = require('fs-extra');
const path = require('path');
const passwordSafeStorage = require('keytar');
const fileExists = require('file-exists');
const sqlite = require('better-sqlite3');
const compare = require('node-version-compare');
const normalizePath = require('normalize-path');
// Electron classes
const electron = require('electron');
const shell = electron.shell;
const Menu = electron.Menu;
const dialog = electron.dialog;
const BrowserWindow = electron.BrowserWindow;
Expand Down Expand Up @@ -69,12 +69,12 @@ class App {
return;
}

this.loadAdditionalConfig();
this.checkThemes();
this.loadSites().then(() => {
this.loadThemes();
this.initWindow();
this.initWindowEvents();
});
this.loadSites();
this.loadThemes();
this.initWindow();
this.initWindowEvents();
}

/**
Expand All @@ -88,7 +88,6 @@ class App {
fs.mkdirSync(path.join(this.appDir, 'sites'));
fs.mkdirSync(path.join(this.appDir, 'config'));
fs.mkdirSync(path.join(this.appDir, 'themes'));
fs.mkdirSync(path.join(this.appDir, 'logs'));
fs.copySync(
path.join(__dirname, '..', 'default-files', 'default-themes').replace('app.asar', 'app.asar.unpacked'),
path.join(this.appDir, 'themes'),
Expand All @@ -99,8 +98,8 @@ class App {
);
}

if (!fs.existsSync(path.join(this.appDir, 'logs'))) {
fs.mkdirSync(path.join(this.appDir, 'logs'));
if (!fs.existsSync(path.join(this.appDir, 'backups'))) {
fs.mkdirSync(path.join(this.appDir, 'backups'));
}
}

Expand Down Expand Up @@ -134,7 +133,7 @@ class App {
}
);
} catch (err) {
fs.appendFile(this.appDir + '/logs/themes-copy-errors.txt', JSON.stringify(err));
fs.appendFile(this.app.getPath('logs') + '/themes-copy-errors.txt', JSON.stringify(err));
}
} else {
// For existing themes - compare versions
Expand Down Expand Up @@ -173,9 +172,9 @@ class App {
*
* @returns {object}
*/
async reloadSite(siteName) {
reloadSite(siteName) {
let siteData = this.switchSite(siteName);
let siteConfig = await this.loadSite(siteName);
let siteConfig = this.loadSite(siteName);

return {
data: siteData,
Expand Down Expand Up @@ -254,19 +253,19 @@ class App {
* @param storeInConfig
* @returns {object}
*/
async loadSite(siteName) {
loadSite(siteName) {
let dirPath = path.join(this.sitesDir, siteName);
let fileStat = fs.statSync(dirPath);

// check directories only
if(!fileStat.isDirectory()) {
if (!fileStat.isDirectory()) {
return;
}

// check if the config file exists
let configFilePath = path.join(dirPath, 'input', 'config', 'site.config.json');

if(!fileExists(configFilePath)) {
if (!fileExists(configFilePath)) {
return;
}

Expand All @@ -288,16 +287,15 @@ class App {
// Migrate old author data if necessary
siteConfig = SiteConfigMigrator.moveOldAuthorData(this, siteConfig);

// Load passwords
siteConfig = await this.loadPasswords(siteConfig);
// set site data
this.sites[siteConfig.name] = JSON.parse(JSON.stringify(siteConfig));

if(this.sites[siteConfig.name].logo.icon.indexOf('#') > -1) {
if (this.sites[siteConfig.name].logo.icon.indexOf('#') > -1) {
this.sites[siteConfig.name].logo.icon = this.sites[siteConfig.name].logo.icon.split('#')[1];
}

// Fill displayName fields for old websites without it
if(!this.sites[siteConfig.name].displayName) {
if (!this.sites[siteConfig.name].displayName) {
this.sites[siteConfig.name].displayName = siteConfig.name;
}

Expand All @@ -307,74 +305,13 @@ class App {
/**
* Load websites
*/
async loadSites() {
loadSites() {
let files = fs.readdirSync(this.sitesDir);
this.sites = {};

for(let siteName of files) {
await this.loadSite(siteName);
}
}

/**
* Load password from Keytar
*/
async loadPassword(type, passwordKey) {
if(passwordKey.indexOf(type) === 0) {
let passwordData = passwordKey.split(' ');
let service = passwordData[0];
let account = passwordData[1];
let retrievedPassword = '';

if (passwordSafeStorage) {
try {
retrievedPassword = await passwordSafeStorage.getPassword(service, account);
} catch (e) {
console.log('(!) Cannot retrieve password via keytar');
}
}

if (retrievedPassword === null || retrievedPassword === true || retrievedPassword === false) {
retrievedPassword = '';
}

return retrievedPassword;
}

return '';
}

/**
* Load passwords if its are stored in the keychain
*/
async loadPasswords(siteConfig) {
if(siteConfig.deployment) {
siteConfig.deployment.password = await this.loadPassword('publii', siteConfig.deployment.password);

if(siteConfig.deployment.passphrase) {
siteConfig.deployment.passphrase = await this.loadPassword('publii-passphrase', siteConfig.deployment.passphrase);
}

if(siteConfig.deployment.s3) {
siteConfig.deployment.s3.id = await this.loadPassword('publii-s3-id', siteConfig.deployment.s3.id);
siteConfig.deployment.s3.key = await this.loadPassword('publii-s3-key', siteConfig.deployment.s3.key);
}

if(siteConfig.deployment.netlify) {
siteConfig.deployment.netlify.id = await this.loadPassword('publii-netlify-id', siteConfig.deployment.netlify.id);
siteConfig.deployment.netlify.token = await this.loadPassword('publii-netlify-token', siteConfig.deployment.netlify.token);
}

if(siteConfig.deployment.github) {
siteConfig.deployment.github.token = await this.loadPassword('publii-gh-token', siteConfig.deployment.github.token);
}

if(siteConfig.deployment.gitlab) {
siteConfig.deployment.gitlab.token = await this.loadPassword('publii-gl-token', siteConfig.deployment.gitlab.token);
}
for (let siteName of files) {
this.loadSite(siteName);
}

return siteConfig;
}

/**
Expand All @@ -388,7 +325,7 @@ class App {
this.dirPaths = {
sites: normalizePath(path.join(this.appDir, 'sites')),
temp: normalizePath(path.join(this.appDir, 'temp')),
logs: normalizePath(path.join(this.appDir, 'logs'))
logs: normalizePath(this.app.getPath('logs'))
};
}

Expand Down Expand Up @@ -451,23 +388,28 @@ class App {
return true;
}

return true;
}

/**
* Load additional config data
*/
loadAdditionalConfig () {
/*
* Try to get TinyMCE overrided config
*/
try {
this.tinymceOverridedConfig = JSON.parse(fs.readFileSync(this.tinymceOverridedConfigPath, 'utf8'));
} catch (e) {}

if(this.appConfig.sitesLocation) {
if (this.appConfig.sitesLocation) {
this.sitesDir = this.appConfig.sitesLocation;
this.app.sitesDir = this.appConfig.sitesLocation;
} else {
this.appConfig.sitesLocation = path.join(this.appDir, 'sites');
this.sitesDir = path.join(this.appDir, 'sites');
this.app.sitesDir = path.join(this.appDir, 'sites');
}

return true;
}

/**
Expand All @@ -493,12 +435,20 @@ class App {
initWindow() {
let self = this;
let windowParams = this.windowBounds;

windowParams.minWidth = 1200;
windowParams.minHeight = 700;
windowParams.webPreferences = {
nodeIntegration: true
nodeIntegration: true,
webviewTag: true,
spellcheck: true,
preload: path.join(__dirname, 'app-preload.js')
};

if (this.appConfig.appTheme === 'dark') {
windowParams.backgroundColor = '#202128';
}

let displays = electron.screen.getAllDisplays();
let externalDisplay = displays.find((display) => {
return display.bounds.x !== 0 || display.bounds.y !== 0;
Expand All @@ -524,15 +474,48 @@ class App {
windowParams.frame = false;
}

if (process.platform === 'linux') {
windowParams.icon = path.join(__dirname, '..', 'src', 'assets', 'installation', '1024x1024.png');
}

Menu.setApplicationMenu(null);
this.mainWindow = new BrowserWindow(windowParams);
this.mainWindow.setMenu(null);
this.mainWindow.loadURL('file://' + this.basedir + '/dist/index.html');
this.mainWindow.removeMenu();
this.mainWindow.loadURL('file://' + this.basedir + '/index.html');

// Register search shortcut listener
this.mainWindow.webContents.on('before-input-event', (e, input) => {
if (input.key === 'f' && (input.meta || input.control)) {
this.mainWindow.webContents.send('app-show-search-form');
}
});

// Prevent from creating new windows in the Electron context
this.mainWindow.webContents.on('new-window', function(event, urlToOpen) {
event.preventDefault();

if (typeof urlToOpen !== 'string') {
return false;
}

let url;
let allowedProtocols = ['http:', 'https:', 'file:', 'dat:', 'ipfs:'];

try {
url = new URL(urlToOpen);
} catch (e) {
return false;
}

if (allowedProtocols.indexOf(url.protocol) > -1) {
url = url.href.replace(/\s/gmi, '');
shell.openExternal(url);
}
});

this.mainWindow.webContents.on('app-command', (e, cmd) => {
// disable back/forward mouse buttons
if (cmd === 'browser-backward' || cmd === 'browser-forward') {
e.preventDefault();
}
});

this.mainWindow.webContents.on('did-finish-load', function() {
let appVersionInfo = {
Expand Down
Loading

0 comments on commit f75b25e

Please sign in to comment.