Skip to content

Commit

Permalink
make win maximize and custom color
Browse files Browse the repository at this point in the history
  • Loading branch information
RoderickQiu committed Jan 11, 2023
1 parent 1a1c241 commit 3a744e2
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 99 deletions.
1 change: 1 addition & 0 deletions floating.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
}
</script>
<script src="renderer.js"></script>
<script src="theme.js"></script>
</body>

</html>
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
<a href="javascript:call('window-hide')" class="small rest" id="win-hider"><i
class="iconfont icon-dockpanel" id="window-hide"></i></a><span
id="no-use-space">&nbsp;&nbsp;</span>
<a href="javascript:call('window-maximize')" class="small rest" id="win-max"><i
class="iconfont icon-maximize" id="window-max"></i></a><span
id="no-use-space-2">&nbsp;&nbsp;</span>
<a href="javascript:call('window-minimize')" class="small rest"><i class="iconfont icon-minus"
id="window-minimize"></i></a><span
class="should-lock">&nbsp;&nbsp;</span>
Expand All @@ -145,6 +148,7 @@
<script>
$('#logo-bar').attr('title', i18n.__('info'));
$('#window-hide').attr('title', i18n.__('window-hide'));
$('#window-max').attr('title', i18n.__('window-max'));
$('#window-minimize').attr('title', i18n.__('window-minimize'));
$('#exit').attr('title', i18n.__('exit'));
$('#back-onlyrest').attr('title', i18n.__('back'));
Expand Down Expand Up @@ -703,6 +707,7 @@ <h6 id="new-feature-title" class="rest"></h6>
}, 500);
</script>
<script src="renderer.js"></script>
<script src="theme.js"></script>
</body>

</html>
8 changes: 7 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"settings" : "Settings",
"info" : "About wnr",
"window-hide" : "Hide the window to system tray",
"window-max" : "Maximize this window",
"window-minimize" : "Minimize to taskbar",
"title" : "please enter a title",
"work-time" : "work for ...",
Expand Down Expand Up @@ -372,5 +373,10 @@
"dropdown-every3" : "Every 3",
"dropdown-every4" : "Every 4",
"dropdown-every5" : "Every 5",
"dropdown-every6" : "Every 6"
"dropdown-every6" : "Every 6",
"theme-color" : "Custom theme colors",
"theme-color-work" : "Working (default red): ",
"theme-color-rest" : "Resting (default blue): ",
"theme-color-onlyrest" : "Simple Ctdn. (default purple): ",
"theme-color-positive" : "Stopwatch (default green): "
}
8 changes: 7 additions & 1 deletion locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"settings" : "设置",
"info" : "关于 wnr",
"window-hide" : "隐藏至托盘菜单",
"window-max" : "最大化窗口",
"window-minimize" : "最小化至任务栏",
"title" : "任务名称是什么?",
"work-time" : "先工作多少时间?",
Expand Down Expand Up @@ -367,5 +368,10 @@
"dropdown-every3" : "每三次",
"dropdown-every4" : "每四次",
"dropdown-every5" : "每五次",
"dropdown-every6" : "每六次"
"dropdown-every6" : "每六次",
"theme-color" : "自定义主题颜色",
"theme-color-work" : "工作(默认红色):",
"theme-color-rest" : "休息(默认蓝色):",
"theme-color-onlyrest" : "单纯计时(默认紫色):",
"theme-color-positive" : "正计时(默认绿色):"
}
8 changes: 7 additions & 1 deletion locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"settings" : "設置",
"info" : "關於 wnr",
"window-hide" : "隱藏至托盤菜單",
"window-max" : "最大化窗口",
"window-minimize" : "最小化至任務欄",
"title" : "任務名稱是什麼?",
"work-time" : "先工作多少時間?",
Expand Down Expand Up @@ -367,5 +368,10 @@
"dropdown-every3" : "每三次",
"dropdown-every4" : "每四次",
"dropdown-every5" : "每五次",
"dropdown-every6" : "每六次"
"dropdown-every6" : "每六次",
"theme-color" : "自定義主題顏色",
"theme-color-work" : "工作(默認紅色):",
"theme-color-rest" : "休息(默認藍色):",
"theme-color-onlyrest" : "單純計時(默認紫色):",
"theme-color-positive" : "正計時(默認綠色):"
}
71 changes: 58 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let win = null, settingsWin = null, aboutWin = null, tourWin = null, floatingWin
dockHide = false,
newWindows = [], displays = null, hasMultiDisplays = null,
isLoose = false, isForceScreenLock = false, isScreenLocked = false,
isAlarmDialogClosed = true, isShadowless = false, isAlarmTipOn = false,
isAlarmDialogClosed = true, isShadowless = false, isAlarmTipOn = false, isMaximized = false,
hasFloating = false, hasExternalTitle = false, hasGotSingleInstanceLock = false,
kioskInterval = null,
recorderDate = null, tempDate = null, yearAndMon = null, yearMonDay = null, year = null,
Expand Down Expand Up @@ -56,7 +56,7 @@ function createWindow() {
frame: false,
backgroundColor: "#fefefe",
resizable: true,
maximizable: false,
maximizable: true,
show: false,
hasShadow: true,
webPreferences: {
Expand Down Expand Up @@ -120,6 +120,22 @@ function createWindow() {
}
});

win.on('maximize', () => {
isMaximized = true;
});

win.on('enter-full-screen', () => {
isMaximized = true;
})

win.on('leave-full-screen', () => {
isMaximized = false;
})

win.on('unmaximize', () => {
isMaximized = false;
});

//prevent app-killers for lock mode / focus mode
win.webContents.on('crashed', () => {
if (store.get('islocked') || (fullScreenProtection && isTimerWin && (process.env.NODE_ENV !== "development") && (!isLoose))) relaunchSolution();
Expand Down Expand Up @@ -399,7 +415,8 @@ app.on('ready', () => {

if (win != null) {
if (styleCache.has("win-size")) {
win.setSize(styleCache.get("win-size").width, styleCache.get("win-size").height);
if (styleCache.get("win-size").width < 1000 && styleCache.get("win-size").height < 900)
win.setSize(styleCache.get("win-size").width, styleCache.get("win-size").height);
}
win.on('resized', () => {
styleCache.set("win-size", { "width": win.getSize()[0], "height": win.getSize()[1] });
Expand Down Expand Up @@ -433,6 +450,7 @@ app.on('ready', () => {
statisticsInitializer();

hotkeyInit();
themeColorInit();

if (store.has("zoom-ratio"))
ratio = ratioList[store.get("zoom-ratio")];
Expand Down Expand Up @@ -713,6 +731,14 @@ function getCustomDialogModeType(mode) {
}

function customDialog(mode, title, msg, executeAfter) {
if (isMaximized) {
win.webContents.send("fullscreen-custom-dialog", {
title: title,
message: msg,
executeAfter: executeAfter
})
return;
}
if (executeAfter == null) executeAfter = "";
if (mode === "on" || mode === "select_on" || mode === "update_on") {
customDialogWin.webContents.send("dialog-init", {
Expand Down Expand Up @@ -777,6 +803,18 @@ function theThemeHasChanged() {
}
}

function themeColorInit() {
const defaultColors = [
"#5490ea",
"#ea5454",
"#17a2b8",
"#a26ae5"
];
if (!store.has("theme-color")) {
store.set("theme-color", defaultColors);
}
}

function hotkeyInit() {
function isTagNude(tag) {
return tag.indexOf('Control') === -1 && tag.indexOf('Shift') === -1
Expand Down Expand Up @@ -1554,7 +1592,7 @@ function noCheckTimeSolution(mode) {
}
if (dockHide) app.dock.hide();
}
win.maximizable = false;
//win.maximizable = false;
}

function timeEndDialogDispose(mode) {
Expand Down Expand Up @@ -1596,7 +1634,7 @@ ipcMain.on('warning-giver-workend', function () {

fullScreenProtection = false;
if (win != null) {
win.maximizable = false;
//win.maximizable = false;
isWorkMode = false;
if (restTimeFocused === true) {
focusSolution();
Expand All @@ -1612,7 +1650,7 @@ ipcMain.on('warning-giver-workend', function () {
if (store.get("no-check-work-time-end")) {
noCheckTimeSolution("work");
setTimeout(() => win.webContents.send("alter-start-stop", "start"), 1000);
} else if (!restTimeFocused) {
} else if (!restTimeFocused && !isMaximized) {
win.setAlwaysOnTop(false);
setTimeout(function () {
customDialog("on", personal[0], personal[1]
Expand All @@ -1635,7 +1673,7 @@ ipcMain.on('warning-giver-restend', function () {

fullScreenProtection = false;
if (win != null) {
win.maximizable = false;
//win.maximizable = false;
isWorkMode = true;
if (workTimeFocused === true) {
focusSolution();
Expand All @@ -1650,7 +1688,7 @@ ipcMain.on('warning-giver-restend', function () {
if (store.get("no-check-rest-time-end")) {
noCheckTimeSolution("rest");
setTimeout(() => win.webContents.send("alter-start-stop", "start"), 1000);
} else if (!workTimeFocused) {
} else if (!workTimeFocused && !isMaximized) {
win.setAlwaysOnTop(false);
setTimeout(function () {
customDialog("on", personal[0], personal[1]
Expand All @@ -1673,7 +1711,7 @@ ipcMain.on('warning-giver-all-task-end', function () {

fullScreenProtection = false;
if (win != null) {
win.maximizable = false;
//win.maximizable = false;
isWorkMode = false;
win.show();
win.center();
Expand All @@ -1695,7 +1733,7 @@ ipcMain.on('warning-giver-all-task-end', function () {
personal[1], "normal");
}
if (store.get("no-check-time-end")) {
win.maximizable = false;
//win.maximizable = false;
if (store.get("top") !== true) {
win.setAlwaysOnTop(false);//cancel unnecessary always-on-top
win.moveTop();
Expand All @@ -1711,7 +1749,7 @@ ipcMain.on('warning-giver-all-task-end', function () {
customDialog("on", personal[0], personal[1],
"win.loadFile('index.html');\n" +
"setFullScreenMode(false);\n" +
"win.maximizable = false;\n" +
//"win.maximizable = false;\n" +
"if (store.get(\"top\") !== true) {\n" +
" win.setAlwaysOnTop(false);//cancel unnecessary always-on-top\n" +
" win.moveTop(); }\n" +
Expand Down Expand Up @@ -1817,6 +1855,13 @@ ipcMain.on('window-minimize', function () {
if (win != null) win.minimize()
})

ipcMain.on('window-maximize', function () {
if (win != null) {
if (isMaximized) win.unmaximize();
else win.maximize();
}
})

ipcMain.on('enter-only-rest', function () {
isOnlyRest = true;
})
Expand Down Expand Up @@ -2221,7 +2266,7 @@ ipcMain.on("tray-time-set", function (event, message) {
if (process.platform === "darwin") {
if (timeLeftOnBar != null) timeLeftOnBar.label = trayTimeMsg;
if (tray != null) tray.setTitle(" " + trayTimeMsg);
if (win != null) win.maximizable = false;
//if (win != null) win.maximizable = false;
}
} else tray.setTitle("");
});
Expand All @@ -2239,7 +2284,7 @@ ipcMain.on("logger", function (event, message) {
})

ipcMain.on("timer-win", function (event, message) {
if (win != null) win.maximizable = false;
//if (win != null) win.maximizable = false;

if (message) {
isDarkMode();
Expand Down
93 changes: 47 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
{
"name" : "wnr",
"version" : "1.27.0",
"description" : "Work and rest, with wnr now!",
"main" : "main.js",
"scripts" : {
"dep-update" : "yarn",
"start" : "cross-env NODE_ENV=development electron .",
"nsis" : "cross-env NODE_ENV=production node ./res/builder/nsis.js",
"7zip" : "cross-env NODE_ENV=portable node ./res/builder/win-zip.js",
"mac" : "cross-env NODE_ENV=production node ./res/builder/mac.js",
"linux" : "cross-env NODE_ENV=production node ./res/builder/linux.js",
"appimage" : "cross-env NODE_ENV=production node ./res/builder/appimage.js",
"dir" : "cross-env NODE_ENV=production node ./res/builder/dir_test.js",
"ms-store" : "cross-env NODE_ENV=msstore node ./res/builder/dir_test.js"
"name": "wnr",
"version": "1.27.0",
"description": "Work and rest, with wnr now!",
"main": "main.js",
"scripts": {
"dep-update": "yarn",
"start": "cross-env NODE_ENV=development electron .",
"nsis": "cross-env NODE_ENV=production node ./res/builder/nsis.js",
"7zip": "cross-env NODE_ENV=portable node ./res/builder/win-zip.js",
"mac": "cross-env NODE_ENV=production node ./res/builder/mac.js",
"linux": "cross-env NODE_ENV=production node ./res/builder/linux.js",
"appimage": "cross-env NODE_ENV=production node ./res/builder/appimage.js",
"dir": "cross-env NODE_ENV=production node ./res/builder/dir_test.js",
"ms-store": "cross-env NODE_ENV=msstore node ./res/builder/dir_test.js"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/RoderickQiu/wnr.git"
"repository": {
"type": "git",
"url": "https://github.com/RoderickQiu/wnr.git"
},
"author" : "RoderickQiu",
"license" : "MPL-2.0",
"homepage" : "https://getwnr.com",
"appId" : "com.scrisstudio.wnr",
"build" : {
"appId" : "com.scrisstudio.wnr"
"author": "RoderickQiu",
"license": "MPL-2.0",
"homepage": "https://getwnr.com",
"appId": "com.scrisstudio.wnr",
"build": {
"appId": "com.scrisstudio.wnr"
},
"copyright" : "(c) Roderick Qiu",
"productName" : "wnr",
"dependencies" : {
"@electron/remote" : "2.0.8",
"bootstrap" : "4.6.1",
"cmd-or-ctrl" : "0.3.1",
"compare-version" : "0.1.2",
"copy-to-clipboard" : "3.3.1",
"crypto-js" : "4.1.1",
"electron-debug" : "3.2.0",
"electron-store" : "8.0.2",
"i18n" : "0.15.0",
"jquery" : "3.6.0",
"node-fetch" : "2.6.7",
"node-notifier" : "10.0.1",
"node-shi" : "0.4.2",
"popper.js" : "1.16.1",
"schart.js" : "3.0.0",
"win-release-id" : "1.0.6"
"copyright": "(c) Roderick Qiu",
"productName": "wnr",
"dependencies": {
"@eastdesire/jscolor": "^2.5.1",
"@electron/remote": "2.0.8",
"bootstrap": "4.6.1",
"cmd-or-ctrl": "0.3.1",
"compare-version": "0.1.2",
"copy-to-clipboard": "3.3.1",
"crypto-js": "4.1.1",
"electron-debug": "3.2.0",
"electron-store": "8.0.2",
"i18n": "0.15.0",
"jquery": "3.6.0",
"node-fetch": "2.6.7",
"node-notifier": "10.0.1",
"node-shi": "0.4.2",
"popper.js": "1.16.1",
"schart.js": "3.0.0",
"win-release-id": "1.0.6"
},
"devDependencies" : {
"cross-env" : "7.0.3",
"electron" : "18.3.5",
"electron-builder" : "23.0.3"
"devDependencies": {
"cross-env": "7.0.3",
"electron": "18.3.5",
"electron-builder": "23.0.3"
}
}
Loading

0 comments on commit 3a744e2

Please sign in to comment.