Skip to content

Commit

Permalink
feat: add auto dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZer000 committed Oct 30, 2024
1 parent dde3c60 commit 802d0ed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ node_modules/
#Windows
Thumbs.db
Desktop.ini

#dev-log
updateLog.md
36 changes: 31 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
require('dotenv').config();
const win = nw.Window.get();
win.show(false);
require('dotenv').config();
const fs = require('fs');
const notifier = require("node-notifier");
const path = require("path");
let settings = {};
const body = document.querySelector("body");
const menu = new nw.Menu();
const close = document.querySelector("#close");
const info = document.querySelector('#info');
const body = document.querySelector('body');
let isBody = false;
let isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
let media = window.matchMedia('(prefers-color-scheme: dark)');

//打开窗口:
win.blur();//取消焦点
//设置主题
setDarkMode(isDark);
function setDarkMode (e) {
isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
console.log(isDark);
if (e.matches || isDark) {
console.log('暗模式已启用');
info.style.backgroundColor = "black";
close.style.backgroundColor = "black";
info.style.color = "white";
close.style.color = "white";
} else {
console.log('暗模式未启用');
info.style.backgroundColor = "white";
close.style.backgroundColor = "white";
info.style.color = "black";
close.style.color = "black";
}
}
media.addEventListener('change', setDarkMode);
//设置托盘
let tray = new nw.Tray({
title: 'MomoUpup', //在MacOS上生效
// tooltip: 'MomoUpup',
icon: './img/icon.png'
});
tray.tooltip = 'MomoUpup';
const menu = new nw.Menu();
menu.append(new nw.MenuItem({
label: 'MomoUpup',
icon: './img/icon.png',
Expand Down Expand Up @@ -101,7 +126,6 @@ function closeApp() {
}
win.onclose = closeApp;
//html内置按钮关闭窗口
const close = document.querySelector("#close");
close.onclick = closeApp;

//窗口运行中:
Expand Down Expand Up @@ -156,4 +180,6 @@ body.addEventListener('mouseup', function(e) {
startX = e.x - startX;
startY = Math.floor(1.5*(e.y - startY));
win.moveBy(startX, startY);
});
});

win.show(true);

0 comments on commit 802d0ed

Please sign in to comment.