mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 11:15:24 +03:00
Merge pull request #545 from pulsar-edit/change-window-theme
Change Window Theme with Pulsar Theme
This commit is contained in:
commit
5c193276a6
@ -27,6 +27,10 @@ module.exports = class ApplicationDelegate {
|
|||||||
return ipcRenderer.send('open', params);
|
return ipcRenderer.send('open', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setWindowTheme(params) {
|
||||||
|
return ipcRenderer.send('setWindowTheme', params);
|
||||||
|
}
|
||||||
|
|
||||||
pickFolder(callback) {
|
pickFolder(callback) {
|
||||||
const responseChannel = 'atom-pick-folder-response';
|
const responseChannel = 'atom-pick-folder-response';
|
||||||
ipcRenderer.on(responseChannel, function(event, path) {
|
ipcRenderer.on(responseChannel, function(event, path) {
|
||||||
|
@ -145,7 +145,8 @@ class AtomEnvironment {
|
|||||||
config: this.config,
|
config: this.config,
|
||||||
styleManager: this.styles,
|
styleManager: this.styles,
|
||||||
notificationManager: this.notifications,
|
notificationManager: this.notifications,
|
||||||
viewRegistry: this.views
|
viewRegistry: this.views,
|
||||||
|
applicationDelegate: this.applicationDelegate
|
||||||
});
|
});
|
||||||
|
|
||||||
/** @type {MenuManager} */
|
/** @type {MenuManager} */
|
||||||
|
@ -399,6 +399,11 @@ const configSchema = {
|
|||||||
description: 'Add the current tab title to the Pulsar Window title.',
|
description: 'Add the current tab title to the Pulsar Window title.',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: true
|
default: true
|
||||||
|
},
|
||||||
|
syncWindowThemeWithPulsarTheme: {
|
||||||
|
description: 'When changing the theme within Pulsar also change the theme of the window on the operating system.',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,8 @@ const {
|
|||||||
dialog,
|
dialog,
|
||||||
ipcMain,
|
ipcMain,
|
||||||
shell,
|
shell,
|
||||||
screen
|
screen,
|
||||||
|
nativeTheme
|
||||||
} = require('electron');
|
} = require('electron');
|
||||||
const { CompositeDisposable, Disposable } = require('event-kit');
|
const { CompositeDisposable, Disposable } = require('event-kit');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
@ -803,6 +804,14 @@ module.exports = class AtomApplication extends EventEmitter {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.disposable.add(
|
||||||
|
ipcHelpers.on(ipcMain, 'setWindowTheme', (event, options) => {
|
||||||
|
if (options && typeof options === 'string') {
|
||||||
|
nativeTheme.themeSource = options;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// A request from the associated render process to open a set of paths using the standard window location logic.
|
// A request from the associated render process to open a set of paths using the standard window location logic.
|
||||||
// Used for application:reopen-project.
|
// Used for application:reopen-project.
|
||||||
this.disposable.add(
|
this.disposable.add(
|
||||||
|
@ -6,6 +6,7 @@ const { Emitter, CompositeDisposable } = require('event-kit');
|
|||||||
const { File } = require('pathwatcher');
|
const { File } = require('pathwatcher');
|
||||||
const fs = require('fs-plus');
|
const fs = require('fs-plus');
|
||||||
const LessCompileCache = require('./less-compile-cache');
|
const LessCompileCache = require('./less-compile-cache');
|
||||||
|
const Color = require('./color');
|
||||||
|
|
||||||
// Extended: Handles loading and activating available themes.
|
// Extended: Handles loading and activating available themes.
|
||||||
//
|
//
|
||||||
@ -16,8 +17,10 @@ module.exports = class ThemeManager {
|
|||||||
config,
|
config,
|
||||||
styleManager,
|
styleManager,
|
||||||
notificationManager,
|
notificationManager,
|
||||||
viewRegistry
|
viewRegistry,
|
||||||
|
applicationDelegate
|
||||||
}) {
|
}) {
|
||||||
|
this.applicationDelegate = applicationDelegate;
|
||||||
this.packageManager = packageManager;
|
this.packageManager = packageManager;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.styleManager = styleManager;
|
this.styleManager = styleManager;
|
||||||
@ -372,6 +375,20 @@ On linux there are currently problems with watch sizes. See
|
|||||||
return this.styleSheetDisposablesBySourcePath[path];
|
return this.styleSheetDisposablesBySourcePath[path];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshWindowTheme() {
|
||||||
|
let bgColor = Color.parse(getComputedStyle(document.documentElement).backgroundColor);
|
||||||
|
|
||||||
|
let luminosity = 0.2126 * bgColor.red + 0.7152 * bgColor.green + 0.0722 * bgColor.blue;
|
||||||
|
// ^^ Luminosity per ITU-R BT.709
|
||||||
|
if (luminosity < 40) {
|
||||||
|
// Considered Dark
|
||||||
|
this.applicationDelegate.setWindowTheme("dark");
|
||||||
|
} else {
|
||||||
|
// Considered Bright
|
||||||
|
this.applicationDelegate.setWindowTheme("light");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activateThemes() {
|
activateThemes() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
// @config.observe runs the callback once, then on subsequent changes.
|
// @config.observe runs the callback once, then on subsequent changes.
|
||||||
@ -396,6 +413,9 @@ On linux there are currently problems with watch sizes. See
|
|||||||
this.refreshLessCache(); // Update cache again now that @getActiveThemes() is populated
|
this.refreshLessCache(); // Update cache again now that @getActiveThemes() is populated
|
||||||
this.loadUserStylesheet();
|
this.loadUserStylesheet();
|
||||||
this.reloadBaseStylesheets();
|
this.reloadBaseStylesheets();
|
||||||
|
if (this.config.get("editor.syncWindowThemeWithPulsarTheme")) {
|
||||||
|
this.refreshWindowTheme();
|
||||||
|
}
|
||||||
this.initialLoadComplete = true;
|
this.initialLoadComplete = true;
|
||||||
this.emitter.emit('did-change-active-themes');
|
this.emitter.emit('did-change-active-themes');
|
||||||
resolve();
|
resolve();
|
||||||
|
Loading…
Reference in New Issue
Block a user