Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #44

Merged
merged 18 commits into from
Jan 20, 2024
Merged

Dev #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67,195 changes: 33,620 additions & 33,575 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react-scripts": "^5.0.1",
"redux": "^4.2.1",
"sass": "^1.68.0",
"tiny-pinyin": "^1.3.2",
"translation-check": "^1.0.3"
},
"scripts": {
Expand Down Expand Up @@ -74,4 +75,4 @@
"vite": "3.0.4",
"vite-plugin-pwa": "^0.12.8"
}
}
}
4 changes: 4 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,7 @@ export const handleFileOpen = (id) => {
}
}
};

export const flightMode = () => {
store.dispatch({ type: "TOGGAIRPLNMD", payload: "" });
};
47 changes: 42 additions & 5 deletions src/components/start/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,29 @@ export const BandPane = () => {
style={{ "--prefix": "BAND" }}
>
<div className="bandContainer">
<Icon className="hvlight" src="defender" width={17} />
<Icon className="hvlight" src="spotify" width={17} />
<Icon className="hvlight" src="teams" width={17} />
<Icon
className="hvlight"
width={17}
click="CALCUAPP"
payload="togg"
open="true"
src="calculator"
/>
<Icon
className="hvlight"
width={17}
click="SPOTIFY"
payload="togg"
open="true"
src="spotify"
/>
<Icon
className="hvlight"
width={17}
click="NOTEPAD"
payload="togg"
src="notepad"
/>
</div>
</div>
);
Expand All @@ -109,6 +129,8 @@ export const SidePane = () => {
Actions[action.type](action.payload);
} else dispatch(action);
}
// For battery saver
if (action.payload === "system.power.saver.state") setBrightness();
};

const vSlider = document.querySelector(".vSlider");
Expand All @@ -128,12 +150,26 @@ export const SidePane = () => {
function sliderBackground(elem, e) {
elem.style.setProperty(
"--track-color",
`linear-gradient(90deg, var(--clrPrm) ${e - 3}%, #888888 ${e}%)`,
`linear-gradient(90deg, var(--clrPrm) ${e - 3}%, #888888 ${e}%)`
);
}

const setBrightness = (e) => {
var brgt = e.target.value;
var brgt = document.getElementById("brightnessSlider").value;
if (!e) {
// Battery saver
const state = setting.system.power.saver.state;
const factor = state ? 0.7 : 100 / 70;
const newBrgt = brgt * factor;
setBrightnessValue(newBrgt);
document.getElementById("brightnessSlider").value = newBrgt;
} else {
// Brightness slider
setBrightnessValue(brgt);
}
};

function setBrightnessValue(brgt) {
document.getElementById("brightoverlay").style.opacity = (100 - brgt) / 100;
dispatch({
type: "STNGSETV",
Expand Down Expand Up @@ -200,6 +236,7 @@ export const SidePane = () => {
<div className="sliderCont">
<Icon className="mx-2" src="brightness" ui width={20} />
<input
id="brightnessSlider"
className="sliders bSlider"
onChange={setBrightness}
type="range"
Expand Down
73 changes: 41 additions & 32 deletions src/components/start/start.jsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
import React, { useState, useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { Icon } from "../../utils/general";
import pinyin from "tiny-pinyin";


// 辅助函数:将中文字符串转换为拼音并提取首字母
function getFirstLetter(str) {
const pinyinName = pinyin.convertToPinyin(str, '', false);
const firstLetter = pinyinName.charAt(0).toUpperCase();
return firstLetter >= 'A' && firstLetter <= 'Z' ? firstLetter : '#';
}

export const StartMenu = () => {
const { align } = useSelector((state) => state.taskbar);
const start = useSelector((state) => {
var arr = state.startmenu,
ln = (6 - (arr.pnApps.length % 6)) % 6;
const arr = state.startmenu;
let ln = (6 - (arr.pnApps.length % 6)) % 6;

for (var i = 0; i < ln; i++) {
for (let i = 0; i < ln; i++) {
arr.pnApps.push({
empty: true,
});
}

for (i = 0; i < arr.rcApps.length; i++) {
if (arr.rcApps[i].lastUsed < 0) {
arr.rcApps[i].lastUsed = "Recently Added";
} else if (arr.rcApps[i].lastUsed < 10) {
arr.rcApps[i].lastUsed = "Just Now";
} else if (arr.rcApps[i].lastUsed < 60) {
arr.rcApps[i].lastUsed += "m ago";
} else if (arr.rcApps[i].lastUsed < 360) {
arr.rcApps[i].lastUsed =
Math.floor(arr.rcApps[i].lastUsed / 60) + "h ago";
arr.rcApps.forEach((app) => {
if (app.lastUsed < 0) {
app.lastUsed = "Recently Added";
} else if (app.lastUsed < 10) {
app.lastUsed = "Just Now";
} else if (app.lastUsed < 60) {
app.lastUsed += "m ago";
} else if (app.lastUsed < 360) {
app.lastUsed = Math.floor(app.lastUsed / 60) + "h ago";
}
}
});

var allApps = [],
tmpApps = Object.keys(state.apps)
.filter((x) => x != "hz")
.map((key) => {
return state.apps[key];
});
const allApps = {};
const tmpApps = Object.keys(state.apps)
.filter((x) => x !== "hz")
.map((key) => {
const app = state.apps[key];
app.pinyinName = pinyin.convertToPinyin(app.name, '', false);
return app;
});

tmpApps.sort((a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0));

for (i = 0; i < 27; i++) {
allApps[i] = [];
}
tmpApps.sort((a, b) => a.pinyinName.localeCompare(b.pinyinName));

for (i = 0; i < tmpApps.length; i++) {
var t1 = tmpApps[i].name.trim().toUpperCase().charCodeAt(0);
if (t1 > 64 && t1 < 91) {
allApps[t1 - 64].push(tmpApps[i]);
} else {
allApps[0].push(tmpApps[i]);
tmpApps.forEach((app) => {
const firstLetter = getFirstLetter(app.name);
if (!allApps[firstLetter]) {
allApps[firstLetter] = [];
}
}
allApps[firstLetter].push(app);
});

// 确保contApps被正确初始化为一个数组
arr.contApps = Object.values(allApps);

arr.contApps = allApps;
arr.allApps = tmpApps;
Expand Down Expand Up @@ -474,3 +482,4 @@ export const StartMenu = () => {
</div>
);
};

12 changes: 12 additions & 0 deletions src/reducers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ const settReducer = (state = defState, action) => {
tmpState = changeVal(tmpState, action.payload.path, action.payload.value);
break;
case "SETTLOAD":
changed = true;
tmpState = { ...action.payload };
break;
case "TOGGAIRPLNMD":
changed = true;
const airPlaneModeStatus = tmpState.network.airplane;
if (tmpState.network.wifi.state === true && !airPlaneModeStatus) {
tmpState = changeVal(tmpState, "network.wifi.state");
}
if (tmpState.devices.bluetooth === true && !airPlaneModeStatus) {
tmpState = changeVal(tmpState, "devices.bluetooth");
}
tmpState = changeVal(tmpState, "network.airplane");
}

if (changed) localStorage.setItem("setting", JSON.stringify(tmpState));
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/sidepane.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const defState = {
src: "airplane",
name: "飞行模式",
state: "network.airplane",
action: "STNGTOGG",
action: "flightMode",
},
{
ui: true,
Expand Down
9 changes: 7 additions & 2 deletions src/reducers/taskbar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { taskApps } from "../utils";

const alignment = localStorage.getItem("taskbar-align") || "center";

const defState = {
apps: taskApps,
prev: false,
prevApp: "",
prevPos: 0,
align: "center",
align: alignment,
search: true,
widgets: true,
audio: 3,
Expand All @@ -23,14 +25,17 @@ const taskReducer = (state = defState, action) => {
align: "center",
};
case "TASKLEF":
localStorage.setItem("taskbar-align", "left");
return {
...state,
align: "left",
};
case "TASKTOG":
const alignment = state.align == "left" ? "center" : "left";
localStorage.setItem("taskbar-align", alignment);
return {
...state,
align: state.align == "left" ? "center" : "left",
align: alignment,
};
case "TASKPSHOW":
return {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const apps = [
{
name: "此电脑",
icon: "win/user",
type: "short",
type: "app",
action: "EXPLORER",
},
{
name: "闹钟和时钟",
Expand Down
4 changes: 4 additions & 0 deletions src/utils/general.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ String.prototype.count = function (c) {
};

export const Icon = (props) => {
const sidepane = useSelector((state) => state.sidepane);

const dispatch = useDispatch();
var src = `img/icon/${props.ui != null ? "ui/" : ""}${props.src}.png`;
if (props.ext != null || (props.src && props.src.includes("http"))) {
Expand All @@ -38,6 +40,8 @@ export const Icon = (props) => {
}

const clickDispatch = (event) => {
if (!sidepane.banhide) dispatch({ type: "BANDHIDE" });

var action = {
type: event.currentTarget.dataset.action,
payload: event.currentTarget.dataset.payload,
Expand Down