Sync color between Blockbench instances

This commit is contained in:
JannisX11 2020-08-31 21:40:37 +02:00
parent e2ebf7ad61
commit af6a3495e1
4 changed files with 24 additions and 4 deletions

View File

@ -154,6 +154,7 @@ const Settings = {
new Setting('animation_snap',{category: 'snapping', value: 25, type: 'number'});
//Paint
new Setting('sync_color', {category: 'paint', value: false});
new Setting('paint_side_restrict', {category: 'paint', value: true});
new Setting('brush_opacity_modifier', {category: 'paint', value: 'pressure', type: 'select', options: {
'pressure': tl('settings.brush_modifier.pressure'),

View File

@ -172,9 +172,12 @@ onVueSetup(() => {
var value = new tinycolor(color)
ColorPanel.vue._data.main_color = value.toHexString();
}
ColorPanel.set = function(color) {
ColorPanel.set = function(color, no_sync) {
ColorPanel.change(color)
ColorPanel.addToHistory(ColorPanel.vue._data.main_color)
if (!no_sync && isApp && settings.sync_color.value) {
ipcRenderer.send('change-main-color', ColorPanel.vue._data.main_color);
}
}
ColorPanel.get = function() {
ColorPanel.addToHistory(ColorPanel.vue._data.main_color);
@ -198,6 +201,12 @@ onVueSetup(() => {
//$(this).animate({scrollLeft: current + delta}, 200)
})
if (isApp) {
ipcRenderer.on('set-main-color', (event, arg) => {
ColorPanel.set(arg, true);
})
}
ColorPanel.importPalette = function(file) {
let extension = pathToExtension(file.path);

View File

@ -511,6 +511,8 @@
"settings.animation_snap": "Animation Snap",
"settings.animation_snap.desc": "Snap interval for keyframes in the animation timeline in steps per second",
"settings.sync_color": "Sync Color",
"settings.sync_color.desc": "Synchronize the color between different Blockbench instances",
"settings.paint_side_restrict": "Restrict Brush to Side",
"settings.paint_side_restrict.desc": "Restrict brushes to only paint on the current side",
"settings.image_editor": "Image Editor",

14
main.js
View File

@ -4,6 +4,7 @@ const url = require('url')
const { autoUpdater } = require('electron-updater');
let orig_win;
let all_wins = [];
function createWindow(second_instance) {
if (app.requestSingleInstanceLock && !app.requestSingleInstanceLock()) {
@ -25,6 +26,7 @@ function createWindow(second_instance) {
}
})
if (!orig_win) orig_win = win;
all_wins.push(win);
var index_path = path.join(__dirname, 'index.html')
if (process.platform === 'darwin') {
@ -106,10 +108,11 @@ function createWindow(second_instance) {
slashes: true
}))
win.on('closed', () => {
win = null
win = null;
all_wins.splice(all_wins.indexOf(win), 1);
})
if (second_instance === true) {
win.webContents.second_instance = true
win.webContents.second_instance = true;
}
}
@ -122,7 +125,12 @@ app.on('second-instance', function (event, argv, cwd) {
app.commandLine.appendSwitch('ignore-gpu-blacklist')
app.commandLine.appendSwitch('enable-accelerated-video')
ipcMain.on('change-main-color', (event, arg) => {
all_wins.forEach(win => {
if (win.isDestroyed() || win.webContents == event.sender.webContents) return;
win.webContents.send('set-main-color', arg)
})
})
app.on('ready', () => {