-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48ed38f
Showing
10 changed files
with
13,962 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
node_modules | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// main.js | ||
const { | ||
app, | ||
BrowserWindow, | ||
Menu, | ||
ipcMain | ||
} = require('electron'); | ||
const path = require('path'); | ||
const { | ||
exec | ||
} = require('child_process'); | ||
const sudo = require('sudo-prompt'); | ||
|
||
const NODE_ENV = process.env.NODE_ENV | ||
|
||
function createWindow() { | ||
const win = new BrowserWindow({ | ||
width: 300, | ||
height: 300, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
preload: path.join(__dirname, 'preload.js') | ||
} | ||
}); | ||
|
||
win.loadFile('index.html'); | ||
// 关闭菜单 | ||
Menu.setApplicationMenu(null); | ||
// 打开开发工具 | ||
if (NODE_ENV === "development") { | ||
win.webContents.openDevTools(); | ||
} | ||
} | ||
|
||
|
||
function executeCommand(command) { | ||
return new Promise((resolve, reject) => { | ||
sudo.exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`exec error: ${error}`); | ||
reject(error); | ||
} | ||
resolve(stdout); | ||
console.log(`stdout: ${stdout}`); | ||
console.error(`stderr: ${stderr}`); | ||
}); | ||
}); | ||
} | ||
|
||
function startTimeService() { | ||
const command = 'net start w32time'; | ||
return executeCommand(command); | ||
} | ||
|
||
app.whenReady().then(() => { | ||
ipcMain.handle('set-time', async (event, time) => { | ||
try { | ||
let command; | ||
if (time === 'now') { | ||
command = 'w32tm /resync'; | ||
} else { | ||
command = `date ${time}`; | ||
} | ||
return await executeCommand(command); | ||
} catch (error) { | ||
if (time === 'now') { | ||
try { | ||
await startTimeService(); | ||
return await executeCommand('w32tm /resync'); | ||
} catch (e) { | ||
throw e; | ||
} | ||
} else { | ||
throw error; | ||
} | ||
} | ||
}); | ||
|
||
createWindow(); | ||
|
||
app.on('activate', function () { | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow(); | ||
}); | ||
}); | ||
|
||
app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') app.quit(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { | ||
contextBridge, | ||
ipcRenderer | ||
} = require('electron') | ||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
const replaceText = (selector, text) => { | ||
const element = document.getElementById(selector) | ||
if (element) element.innerText = text | ||
} | ||
|
||
for (const dependency of ['chrome', 'node', 'electron']) { | ||
replaceText(`${dependency}-version`, process.versions[dependency]) | ||
} | ||
}) | ||
|
||
contextBridge.exposeInMainWorld('electronAPI', { | ||
setTime: (time) => { | ||
return ipcRenderer.invoke('set-time', time) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
packagerConfig: { | ||
asar: true, | ||
}, | ||
rebuildConfig: {}, | ||
makers: [ | ||
{ | ||
name: '@electron-forge/maker-squirrel', | ||
config: {}, | ||
}, | ||
{ | ||
name: '@electron-forge/maker-zip', | ||
platforms: ['darwin'], | ||
}, | ||
{ | ||
name: '@electron-forge/maker-deb', | ||
config: {}, | ||
}, | ||
{ | ||
name: '@electron-forge/maker-rpm', | ||
config: {}, | ||
}, | ||
], | ||
plugins: [ | ||
{ | ||
name: '@electron-forge/plugin-auto-unpack-natives', | ||
config: {}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- index.html --> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Set System Time</title> | ||
<style> | ||
body { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
margin: 0; | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.input_div { | ||
margin-bottom: 20px; | ||
} | ||
|
||
.btn_div { | ||
margin-bottom: 20px; | ||
text-align: center; | ||
} | ||
|
||
input[type="date"] { | ||
width: 100%; | ||
padding: 5px; | ||
font-size: 16px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>设置系统时间</h1> | ||
<div> | ||
<div class="input_div"><input type="date" value="2020-10-29" id="timeInput" /></div> | ||
<div class="btn_div"> | ||
<button id="setTimeBtn">设置</button> | ||
<button id="resetTimeBtn">恢复</button></div> | ||
</div> | ||
<script src="./renderer.js"></script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.