Skip to content

Commit 7901e9e

Browse files
authored
Merge pull request #6 from ridvanaltun/next
Next
2 parents 0acd51e + 8cfdc29 commit 7901e9e

File tree

7 files changed

+226
-20
lines changed

7 files changed

+226
-20
lines changed

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,60 @@
1-
# Turkish Deasciifier
1+
<div align="center">
2+
<img
3+
src="./assets/images/logo.png"
4+
alt="Turkish Deasciifier Logo"
5+
height="128"
6+
/>
7+
<p>
8+
<h3>
9+
<b>
10+
Turkish Deasciifier
11+
</b>
12+
</h3>
13+
</p>
14+
<p>
15+
<b>
16+
Tray application for Turkish Deasciifier
17+
</b>
18+
</p>
19+
<br/>
20+
<img
21+
src="./docs/preview.png"
22+
alt="Preview Image"
23+
width="600"
24+
/>
25+
<br/>
26+
<br/>
27+
<p>
228

329
[![Build Status](https://github.com/ridvanaltun/turkish-deasciifier/actions/workflows/publish.yml/badge.svg)](https://github.com/ridvanaltun/turkish-deasciifier/actions/workflows/publish.yml)
430
[![Github Release](https://img.shields.io/github/v/release/ridvanaltun/turkish-deasciifier?include_prereleases)](https://github.com/ridvanaltun/turkish-deasciifier/releases)
531
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
632
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
33+
</p>
34+
</div>
35+
36+
### **Features**
37+
38+
**Deasciifier:** Adapt your texts to Turkish with one click.
39+
40+
**Asciifier:** Also, set your Turkish texts to ASCII with one click.
41+
42+
**Offline:** It works offline, no internet required.
43+
44+
**Tray Application:** It runs as a tray application, not bothering you with dummy screens.
45+
46+
**Multiplatform:** Every platform are supported; macOS, Windows, and even Linux.
47+
48+
**Auto Update:** It comes with an updater, you can easily update the app.
49+
50+
## **Authors**
51+
52+
This project exists thanks to all the people who contribute.
53+
54+
<a href = "https://github.com/ridvanaltun/turkish-deasciifier/graphs/contributors">
55+
<img src = "https://contrib.rocks/image?repo=ridvanaltun/turkish-deasciifier"/>
56+
</a>
57+
58+
## **License**
59+
60+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [`LICENSE`](LICENSE) file for details.

docs/preview.png

107 KB
Loading

src/client/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@
252252
ipcRenderer.on("SET_EDITOR_LINE_WRAPPING", (_, enabled) => {
253253
editor.setOption("lineWrapping", enabled);
254254
});
255+
256+
ipcRenderer.on("SET_ARROW_VISIBILITY", (_, enabled) => {
257+
if (enabled) document.getElementById('arrow').style.display = "block"
258+
else document.getElementById('arrow').style.display = "table"
259+
});
255260
</script>
256261
</body>
257262
</html>

src/client/static/css/deasciifier.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
.background-content {
1616
height: 100%;
1717
overflow: auto;
18-
margin-top: -5px;
18+
margin-top: -6px;
1919
border-bottom-left-radius: 10px;
2020
border-bottom-right-radius: 10px;
2121
}

src/lib/getWindowPosition.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Utilities to get taskbar position and consequently menubar's position
3+
* https://github.com/maxogden/menubar/blob/master/src/util/getWindowPosition.ts
4+
*/
5+
6+
const { screen: electronScreen } = require("electron");
7+
8+
const isLinux = process.platform === "linux";
9+
10+
const trayToScreenRects = (tray) => {
11+
// There may be more than one screen, so we need to figure out on which screen our tray icon lives.
12+
const { workArea, bounds: screenBounds } = electronScreen.getDisplayMatching(
13+
tray.getBounds()
14+
);
15+
16+
workArea.x -= screenBounds.x;
17+
workArea.y -= screenBounds.y;
18+
19+
return [screenBounds, workArea];
20+
};
21+
22+
// type TaskbarLocation = "top" | "bottom" | "left" | "right";
23+
24+
/**
25+
* Determine taskbard location: "top", "bottom", "left" or "right".
26+
*
27+
* Only tested on Windows for now, and only used in Windows.
28+
*
29+
* @param tray - The Electron Tray instance.
30+
*/
31+
const taskbarLocation = (tray) => {
32+
const [screenBounds, workArea] = trayToScreenRects(tray);
33+
34+
// TASKBAR LEFT
35+
if (workArea.x > 0) {
36+
// Most likely Ubuntu hence assuming the window should be on top
37+
if (isLinux && workArea.y > 0) return "top";
38+
// The workspace starts more on the right
39+
return "left";
40+
}
41+
42+
// TASKBAR TOP
43+
if (workArea.y > 0) {
44+
return "top";
45+
}
46+
47+
// TASKBAR RIGHT
48+
// Here both workArea.y and workArea.x are 0 so we can no longer leverage them.
49+
// We can use the workarea and display width though.
50+
// Determine taskbar location
51+
if (workArea.width < screenBounds.width) {
52+
// The taskbar is either on the left or right, but since the LEFT case was handled above,
53+
// we can be sure we're dealing with a right taskbar
54+
return "right";
55+
}
56+
57+
// TASKBAR BOTTOM
58+
// Since all the other cases were handled, we can be sure we're dealing with a bottom taskbar
59+
return "bottom";
60+
};
61+
62+
// type WindowPosition =
63+
// | "trayCenter"
64+
// | "topRight"
65+
// | "trayBottomCenter"
66+
// | "bottomLeft"
67+
// | "bottomRight";
68+
69+
/**
70+
* Depending on where the taskbar is, determine where the window should be
71+
* positioned.
72+
*
73+
* @param tray - The Electron Tray instance.
74+
*/
75+
exports.getWindowPosition = (tray) => {
76+
switch (process.platform) {
77+
// macOS
78+
// Supports top taskbars
79+
case "darwin":
80+
return "trayCenter";
81+
// Linux
82+
// Windows
83+
// Supports top/bottom/left/right taskbar
84+
case "linux":
85+
case "win32": {
86+
const traySide = taskbarLocation(tray);
87+
88+
// Assign position for menubar
89+
if (traySide === "top") {
90+
return isLinux ? "topRight" : "trayCenter";
91+
}
92+
if (traySide === "bottom") {
93+
return isLinux ? "bottomRight" : "trayBottomCenter";
94+
}
95+
if (traySide === "left") {
96+
return "bottomLeft";
97+
}
98+
if (traySide === "right") {
99+
return "bottomRight";
100+
}
101+
}
102+
}
103+
104+
// When we really don't know, we just show the menubar on the top-right
105+
return "topRight";
106+
};

src/server/TrayGenerator.js

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { Tray, Menu, globalShortcut, nativeImage } = require("electron");
22
const path = require("path");
33
const { autoUpdater } = require("electron-updater");
4+
const { getWindowPosition } = require("../lib/getWindowPosition");
45

56
class TrayGenerator {
67
constructor(window, store) {
@@ -9,28 +10,69 @@ class TrayGenerator {
910
this.store = store;
1011
}
1112

12-
getWindowPosition = () => {
13-
const windowBounds = this.window.getBounds();
14-
const trayBounds = this.tray.getBounds();
15-
16-
// center window horizontally below the tray icon
17-
const x = Math.round(
18-
trayBounds.x + trayBounds.width / 2 - windowBounds.width / 2
19-
);
13+
setArrowVisibility = () => {
14+
const whereIsTray = getWindowPosition(this.tray);
2015

21-
// position window vertically below the tray icon
22-
const y = Math.round(trayBounds.y + trayBounds.height);
16+
switch (whereIsTray) {
17+
case "trayCenter":
18+
this.window.webContents.send("SET_ARROW_VISIBILITY", true);
19+
break;
2320

24-
return { x, y };
21+
case "topRight":
22+
case "trayBottomCenter":
23+
case "bottomLeft":
24+
case "bottomRight":
25+
this.window.webContents.send("SET_ARROW_VISIBILITY", false);
26+
break;
27+
}
2528
};
2629

2730
setWinPosition = () => {
28-
const position = this.getWindowPosition();
29-
this.window.setPosition(position.x, position.y, false);
31+
const whereIsTray = getWindowPosition(this.tray);
32+
33+
let x = null;
34+
let y = null;
35+
36+
const windowBounds = this.window.getBounds();
37+
const trayBounds = this.tray.getBounds();
38+
39+
switch (whereIsTray) {
40+
case "trayCenter":
41+
x = Math.round(
42+
trayBounds.x + trayBounds.width / 2 - windowBounds.width / 2
43+
);
44+
y = Math.round(trayBounds.y + trayBounds.height);
45+
break;
46+
47+
case "topRight":
48+
x = Math.round(trayBounds.x + trayBounds.width / 2);
49+
y = Math.round(trayBounds.y + trayBounds.height);
50+
break;
51+
52+
case "trayBottomCenter":
53+
x = Math.round(
54+
trayBounds.x + trayBounds.width / 2 - windowBounds.width / 2
55+
);
56+
y = Math.round(trayBounds.y - windowBounds.height);
57+
break;
58+
59+
case "bottomLeft":
60+
x = Math.round(trayBounds.x + trayBounds.width);
61+
y = Math.round(trayBounds.y + trayBounds.height - windowBounds.height);
62+
break;
63+
64+
case "bottomRight":
65+
x = Math.round(trayBounds.x - windowBounds.width);
66+
y = Math.round(trayBounds.y + trayBounds.height - windowBounds.height);
67+
break;
68+
}
69+
70+
this.window.setPosition(x, y, false);
3071
};
3172

3273
showWindow = () => {
3374
this.setWinPosition();
75+
this.setArrowVisibility();
3476
this.window.setVisibleOnAllWorkspaces(true, {
3577
skipTransformProcessType: true,
3678
});
@@ -65,10 +107,7 @@ class TrayGenerator {
65107
label: "Always on top",
66108
type: "checkbox",
67109
checked: this.store.get("alwaysOnTop"),
68-
click: (event) => {
69-
this.window.setAlwaysOnTop(event.checked);
70-
this.store.set("alwaysOnTop", event.checked);
71-
},
110+
click: (event) => this.store.set("alwaysOnTop", event.checked),
72111
},
73112
{
74113
type: "separator",

src/server/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const createMainWindow = () => {
7272
frame: false,
7373
fullscreenable: false,
7474
resizable: is.development,
75+
skipTaskbar: true,
7576
webPreferences: {
7677
devTools: is.development,
7778
webviewTag: true,
@@ -137,7 +138,6 @@ const applyPreferences = () => {
137138
"SET_CORRECTION_MENU",
138139
store.get("showCorrectionBubble")
139140
);
140-
mainWindow.setAlwaysOnTop(store.get("alwaysOnTop"));
141141
};
142142

143143
store.onDidChange("translateWhileTyping", () => {
@@ -196,6 +196,8 @@ app.on("ready", () => {
196196
createTray();
197197
createUpdater();
198198

199+
mainWindow.setAlwaysOnTop(true);
200+
199201
mainWindow.webContents.on("dom-ready", applyPreferences);
200202

201203
mainWindow.webContents.on("did-fail-load", () => console.log("fail"));

0 commit comments

Comments
 (0)