-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
5 changed files
with
100 additions
and
2 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,28 @@ | ||
/** | ||
* @param {import('../../api/types').Commas} commas | ||
*/ | ||
module.exports = function (commas) { | ||
if (commas.app.isMainProcess()) { | ||
|
||
const path = require('path') | ||
const { ipcMain } = require('electron') | ||
|
||
ipcMain.handle('get-cache-size', event => { | ||
return event.sender.session.getCacheSize() | ||
}) | ||
|
||
ipcMain.handle('clear-cache', event => { | ||
event.sender.session.clearCache() | ||
}) | ||
|
||
commas.i18n.addTranslationDirectory(path.join(__dirname, 'locales')) | ||
|
||
} else { | ||
|
||
commas.context.provide('preference', { | ||
component: commas.bundler.extract('cleaner/renderer/cleaner-link.vue').default, | ||
group: 'about', | ||
}) | ||
|
||
} | ||
} |
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 @@ | ||
{ | ||
"Clear Cache#!cache.1": "清理缓存" | ||
} |
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,9 @@ | ||
{ | ||
"name": "cleaner", | ||
"private": true, | ||
"version": "0.1.0", | ||
"description": "Clean up the application cache", | ||
"main": "index.js", | ||
"author": "commas", | ||
"license": "ISC" | ||
} |
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,58 @@ | ||
<template> | ||
<div class="form-line"> | ||
<span class="link cleaner-link" @click="clear"> | ||
<span v-i18n>Clear Cache#!cache.1</span> | ||
</span> | ||
<span class="cache-size" @click="check">{{ size }}</span> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { ipcRenderer } from 'electron' | ||
import { computed, onMounted, ref, unref } from 'vue' | ||
export default { | ||
name: 'cleaner-link', | ||
setup() { | ||
const cacheSizeRef = ref() | ||
const sizeRef = computed(() => { | ||
let cacheSize = unref(cacheSizeRef) | ||
if (typeof cacheSize !== 'number') return 'N/A' | ||
const group = 1024 | ||
let units = ['B', 'K', 'M', 'G', 'T'] | ||
let currentIndex = 0 | ||
while (cacheSize > group && currentIndex < units.length - 1) { | ||
cacheSize /= group | ||
currentIndex += 1 | ||
} | ||
return `${Math.round(cacheSize * 100) / 100}${units[currentIndex]}` | ||
}) | ||
async function check() { | ||
cacheSizeRef.value = await ipcRenderer.invoke('get-cache-size') | ||
} | ||
async function clear() { | ||
await ipcRenderer.invoke('clear-cache') | ||
check() | ||
} | ||
onMounted(() => { | ||
check() | ||
}) | ||
return { | ||
size: sizeRef, | ||
check, | ||
clear, | ||
} | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.cache-size { | ||
margin-left: 1em; | ||
} | ||
</style> |
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