Skip to content

Commit

Permalink
fix #24
Browse files Browse the repository at this point in the history
  • Loading branch information
kumakichi committed Feb 4, 2025
1 parent 6edd4e2 commit 6c0c28d
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 110 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"devDependencies": {
"electron": "^32.2.0",
"electron-builder": "^25.1.8",
"electron-webpack": "^2.8.2",
"electron-builder-squirrel-windows": "^25.1.8",
"electron-webpack": "^2.8.2",
"webpack": "^4.47.0"
},
"name": "Deepl-Linux-Electron",
"version": "1.5.0",
"version": "1.6.0",
"scripts": {
"dev": "electron-webpack dev",
"compile": "electron-webpack",
Expand All @@ -21,6 +21,7 @@
},
"license": "MIT",
"dependencies": {
"@electron/remote": "^2.1.2",
"electron-store": "^8.2.0",
"source-map-support": "^0.5.19"
}
Expand Down
20 changes: 14 additions & 6 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
Tray,
clipboard
} = require('electron');
require('@electron/remote/main').initialize();
var win = null;
var appQuitting = false;
const appName = 'Deepl-Linux-Electron';
Expand All @@ -39,6 +40,7 @@ app.setAboutPanelOptions({

app.on('ready', function() {
let Menu = require('electron').Menu;
//console.log(app.getPath('userData'));
isRemoveLineBreaks = store.get('remove_line_breaks');
isHiddenOnStartup = store.get('hidden_on_startup');
windowWidth = store.get('window_width');
Expand All @@ -54,10 +56,12 @@ app.on('ready', function() {
width: 280,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true // https://github.com/electron/electron/issues/16558#issuecomment-703143446
enableRemoteModule: true,
preload: path.join(__static, 'hotkey.js')
}
})
// hotkeySettingsWindow.webContents.openDevTools();
// hotkeySettingsWindow.webContents.openDevTools();
require('@electron/remote/main').enable(hotkeySettingsWindow.webContents)

hotkeySettingsWindow.loadFile(path.join(__static, 'hotkey.html'))
}
Expand All @@ -70,9 +74,11 @@ app.on('ready', function() {
width: 200,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
enableRemoteModule: true,
preload: path.join(__static, 'window-size.js')
}
})
require('@electron/remote/main').enable(settingsWindowSize.webContents)
settingsWindowSize.loadFile(path.join(__static, 'window-size.html'))
}
}, {
Expand Down Expand Up @@ -143,9 +149,11 @@ app.on('ready', function() {
title: "Deepl-Linux-Electron",
width: 800,
height: 600,
//webPreferences: {
// preload: path.join(__static, 'preload.js')
//},
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
//preload: path.join(__static, 'preload.js')
},
show: !isHiddenOnStartup
});

Expand Down
52 changes: 2 additions & 50 deletions static/hotkey.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,9 @@

<body>
<div>
<input id="hotkey" onkeyup="keyUp(event)" />
<input type="button" id="save" onclick="saveHotkey()" value="save" />
<input id="hotkey"/>
<input type="button" id="save" value="save" />
</div>
<script>
const {
ipcRenderer
} = require('electron');
const remote = require('electron').remote;

window.addEventListener('load', (event) => {
ipcRenderer.on('set-hotkey-reply', (event, isOk, arg) => {
if (isOk) {
window.localStorage.setItem('shortKey', arg);
console.log('=============== saved :', arg);
}
var w = remote.getCurrentWindow();
w.close();
});

loadHotkey();
});

async function loadHotkey() {
let shortKey = window.localStorage.shortKey;
console.log("========load hotkey:", shortKey);
if (!shortKey) shortKey = 'Control+Alt+D';
document.getElementById("hotkey").value = shortKey;
}

function saveHotkey() {
const hotkey = document.getElementById("hotkey").value;
ipcRenderer.send('set-hotkey', hotkey);
//console.log(hotkey, "key pressed");
}

function keyUp(event) {
const keyCode = event.keyCode;
const key = event.key;
const charCode = event.code;

if ((keyCode >= 16 && keyCode <= 18) || keyCode === 91) return;

const value = [];
event.ctrlKey ? value.push("Control") : null;
event.shiftKey ? value.push("Shift") : null;
event.isAlt ? value.push("Alt") : null;
value.push(key.toUpperCase());

document.getElementById("hotkey").value = value.join("+");
}
</script>
</body>

</html>
55 changes: 55 additions & 0 deletions static/hotkey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const {
ipcRenderer
} = require('electron')
const remote = require('@electron/remote')

window.addEventListener('load', (event) => {
ipcRenderer.on('set-hotkey-reply', (event, isOk, arg) => {
if (isOk) {
window.localStorage.setItem('shortKey', arg);
console.log('=============== saved :', arg);
}
var w = remote.getCurrentWindow();
console.log("wwww:", w);
w.close();
});

loadHotkey();
});

async function loadHotkey() {
let shortKey = window.localStorage.shortKey;
console.log("========load hotkey:", shortKey);
if (!shortKey) shortKey = 'Control+Alt+D';
document.getElementById("hotkey").value = shortKey;
}

function saveHotkey() {
const hotkey = document.getElementById("hotkey").value;
ipcRenderer.send('set-hotkey', hotkey);
//console.log(hotkey, "key pressed");
}

function keyUp(event) {
const keyCode = event.keyCode;
const key = event.key;
const charCode = event.code;

if ((keyCode >= 16 && keyCode <= 18) || keyCode === 91) return;

const value = [];
event.ctrlKey ? value.push("Control") : null;
event.shiftKey ? value.push("Shift") : null;
event.isAlt ? value.push("Alt") : null;
value.push(key.toUpperCase());

document.getElementById("hotkey").value = value.join("+");
}

document.addEventListener('DOMContentLoaded', function() {
const hotkeyInput = document.getElementById('hotkey');
hotkeyInput.addEventListener('keyup', keyUp);

const hotkeySave = document.getElementById('save');
hotkeySave.addEventListener('click', saveHotkey);
});
53 changes: 1 addition & 52 deletions static/window-size.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,7 @@
<label for="windowHeight">Height:</label>
<input type="number" id="windowHeight" min="480" max="2160"/>
</p>
<input type="button" id="save" onclick="saveWindowsSize()" value="save" />
<input type="button" id="save" value="save" />
</div>
<script>
const {
ipcRenderer
} = require('electron');
const remote = require('electron').remote;

window.addEventListener('load', (event) => {
ipcRenderer.on('set-window-size-reply', (event, isOk, argWidth, argHeight) => {
if (isOk) {
window.localStorage.setItem('window_width', argWidth);
window.localStorage.setItem('window_height', argHeight);
console.log('=============== saved :', argWidth, 'x', 'argHeight');
}
var w = remote.getCurrentWindow();
w.close();
window.setSize(argWidth,argHeight,true)
});

loadWindowsSize();
});

async function loadWindowsSize() {
let windowWidth = window.localStorage.window_width;
let windowHeight = window.localStorage.window_height;
document.getElementById("windowWidth").value = windowWidth;
document.getElementById("windowHeight").value = windowHeight;
console.log("========load window size:", windowWidth, 'x', windowHeight);
}

function saveWindowsSize() {
console.log('=============== start :');
const windowWidth = document.getElementById("windowWidth").value;
const windowHeight = document.getElementById("windowHeight").value;
ipcRenderer.send('set-window-size', windowWidth, windowHeight);
}

var inputWindowWidth = document.getElementById('windowWidth')
inputWindowWidth.addEventListener('change', validateMax);
inputWindowWidth.addEventListener('change', validateMin);

var inputWindowHeight = document.getElementById('windowHeight')
inputWindowHeight.addEventListener('change', validateMax);
inputWindowHeight.addEventListener('change', validateMin);

function validateMax() {
if (this.max) this.value = Math.min(parseInt(this.max), parseInt(this.value) || 0);
}
function validateMin() {
if (this.min) this.value = Math.max(parseInt(this.min), parseInt(this.value) || 0);
}
</script>
</body>
</html>
55 changes: 55 additions & 0 deletions static/window-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const {
ipcRenderer
} = require('electron');
const remote = require('@electron/remote');

window.addEventListener('load', (event) => {
ipcRenderer.on('set-window-size-reply', (event, isOk, argWidth, argHeight) => {
if (isOk) {
window.localStorage.setItem('window_width', argWidth);
window.localStorage.setItem('window_height', argHeight);
console.log('=============== saved :', argWidth, 'x', 'argHeight');
}
var w = remote.getCurrentWindow();
w.close();
window.setSize(argWidth, argHeight, true)
});

loadWindowsSize();
});

async function loadWindowsSize() {
let windowWidth = window.localStorage.window_width;
let windowHeight = window.localStorage.window_height;
document.getElementById("windowWidth").value = windowWidth;
document.getElementById("windowHeight").value = windowHeight;
console.log("========load window size:", windowWidth, 'x', windowHeight);
}

function saveWindowsSize() {
console.log('=============== start :');
const windowWidth = document.getElementById("windowWidth").value;
const windowHeight = document.getElementById("windowHeight").value;
ipcRenderer.send('set-window-size', windowWidth, windowHeight);
}

function validateMax() {
if (this.max) this.value = Math.min(parseInt(this.max), parseInt(this.value) || 0);
}

function validateMin() {
if (this.min) this.value = Math.max(parseInt(this.min), parseInt(this.value) || 0);
}

document.addEventListener('DOMContentLoaded', function() {
const wsSave = document.getElementById('save');
wsSave.addEventListener('click', saveWindowsSize);

const inputWindowWidth = document.getElementById('windowWidth')
inputWindowWidth.addEventListener('change', validateMax);
inputWindowWidth.addEventListener('change', validateMin);

const inputWindowHeight = document.getElementById('windowHeight')
inputWindowHeight.addEventListener('change', validateMax);
inputWindowHeight.addEventListener('change', validateMin);
});

0 comments on commit 6c0c28d

Please sign in to comment.