update nextui > heroui, tailwind, vite, onboard, comments, fixes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
export function formatBytes(bytes: number) {
|
||||
// format bytes in to a readable format like (MB, GB, etc), depending on how big the number is
|
||||
if (bytes < 1024) {
|
||||
return `${bytes} B`
|
||||
}
|
||||
|
||||
+18
-4
@@ -3,16 +3,20 @@ import { fetch } from '@tauri-apps/plugin-http'
|
||||
import { usePersistedStore } from './store'
|
||||
|
||||
export async function validateLicense(licenseKey: string) {
|
||||
console.log('[validateLicense]')
|
||||
|
||||
let id
|
||||
|
||||
try {
|
||||
id = await invoke('get_uid')
|
||||
} catch (e) {
|
||||
console.error('[validateLicense] failed to build unique identifier')
|
||||
console.error(JSON.stringify(e))
|
||||
throw new Error('Failed to build unique identifier. Please try again later.')
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
console.error('[validateLicense] missing unique identifier')
|
||||
throw new Error('Failed to build unique identifier. Please try again later.')
|
||||
}
|
||||
|
||||
@@ -25,34 +29,41 @@ export async function validateLicense(licenseKey: string) {
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => {
|
||||
console.error('[validateLicense] failed to validate license')
|
||||
console.error(JSON.stringify(e))
|
||||
throw new Error('Failed to validate license. Are you connected to the internet?')
|
||||
})
|
||||
|
||||
// console.log(JSON.stringify(validationResponse))
|
||||
|
||||
if (validationResponse.error) {
|
||||
console.error('[validateLicense] failed to validate license')
|
||||
throw new Error(validationResponse.error)
|
||||
}
|
||||
|
||||
if (!validationResponse.valid) {
|
||||
console.error('[validateLicense] invalid license key')
|
||||
throw new Error('Invalid license key. Please check your license key and try again.')
|
||||
}
|
||||
|
||||
usePersistedStore.setState({ licenseKey, licenseValid: true })
|
||||
|
||||
console.log('[validateLicense] license validated')
|
||||
}
|
||||
|
||||
export async function revokeLicense(licenseKey: string) {
|
||||
console.log('[revokeLicense]')
|
||||
|
||||
let id
|
||||
|
||||
try {
|
||||
id = await invoke('get_uid')
|
||||
} catch (e) {
|
||||
console.error('[revokeLicense] failed to build unique identifier')
|
||||
console.error(JSON.stringify(e))
|
||||
throw new Error('Failed to build unique identifier. Please try again later.')
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
console.error('[revokeLicense] missing unique identifier')
|
||||
throw new Error('Failed to build unique identifier. Please try again later.')
|
||||
}
|
||||
|
||||
@@ -65,19 +76,22 @@ export async function revokeLicense(licenseKey: string) {
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.catch((e) => {
|
||||
console.error('[revokeLicense] failed to revoke license, fetch failed')
|
||||
console.error(JSON.stringify(e))
|
||||
throw new Error('Failed to revoke license. Are you connected to the internet?')
|
||||
})
|
||||
|
||||
// console.log(JSON.stringify(revocationResponse))
|
||||
|
||||
if (revocationResponse.error) {
|
||||
console.error('[revokeLicense] failed to revoke license, has error response')
|
||||
throw new Error(revocationResponse.error)
|
||||
}
|
||||
|
||||
if (!revocationResponse.revoked) {
|
||||
console.error('[revokeLicense] failed to revoke license, missing revoked response')
|
||||
throw new Error('Failed to revoke license. Please check your license key and try again.')
|
||||
}
|
||||
|
||||
usePersistedStore.setState({ licenseKey: undefined, licenseValid: false })
|
||||
|
||||
console.log('[revokeLicense] license revoked')
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import { usePersistedStore, useStore } from './store'
|
||||
import { getLoadingTray, getMainTray, rebuildTrayMenu } from './tray'
|
||||
import { lockWindows, openFullWindow, openWindow, unlockWindows } from './window'
|
||||
|
||||
// Function to rebuild and update the menu
|
||||
export async function buildMenu() {
|
||||
const storeState = useStore.getState()
|
||||
|
||||
|
||||
+43
-18
@@ -24,14 +24,17 @@ function getAuthHeader() {
|
||||
|
||||
/* DATA */
|
||||
export async function listRemotes() {
|
||||
console.log('[listRemotes] CALLED')
|
||||
|
||||
const r = await fetch('http://localhost:5572/config/listremotes', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
}).then((res) => res.json() as Promise<{ remotes: string[] }>)
|
||||
// .catch((e) => {
|
||||
// console.log("error", e);
|
||||
// throw e;
|
||||
// });
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log('error', e)
|
||||
throw e
|
||||
})
|
||||
.then((res) => res.json() as Promise<{ remotes: string[] }>)
|
||||
|
||||
if (typeof r?.remotes === 'undefined') {
|
||||
throw new Error('Failed to fetch remotes')
|
||||
@@ -41,16 +44,14 @@ export async function listRemotes() {
|
||||
}
|
||||
|
||||
export async function getRemote(remote: string) {
|
||||
console.log('[getRemote]', remote)
|
||||
|
||||
const r = await fetch(`http://localhost:5572/config/get?name=${remote}`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
}).then(
|
||||
(res) => res.json() as Promise<{ type: string } & Record<string, string | number | boolean>>
|
||||
)
|
||||
// .catch((e) => {
|
||||
// console.log("error", e);
|
||||
// throw e;
|
||||
// });
|
||||
|
||||
// console.log(JSON.stringify(r, null, 2))
|
||||
|
||||
@@ -61,7 +62,7 @@ export async function updateRemote(
|
||||
remote: string,
|
||||
parameters: Record<string, string | number | boolean>
|
||||
) {
|
||||
console.log('updateRemote', remote, parameters)
|
||||
console.log('[updateRemote]', remote, parameters)
|
||||
|
||||
const options = new URLSearchParams()
|
||||
options.set('name', remote)
|
||||
@@ -80,7 +81,7 @@ export async function createRemote(
|
||||
type: string,
|
||||
parameters: Record<string, string | number | boolean>
|
||||
) {
|
||||
console.log('createRemote', name, type, parameters)
|
||||
console.log('[createRemote]', name, type, parameters)
|
||||
|
||||
const options = new URLSearchParams()
|
||||
options.set('name', name)
|
||||
@@ -96,6 +97,8 @@ export async function createRemote(
|
||||
}
|
||||
|
||||
export async function deleteRemote(remote: string) {
|
||||
console.log('[deleteRemote]', remote)
|
||||
|
||||
await fetch(`http://localhost:5572/config/delete?name=${remote}`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -105,6 +108,8 @@ export async function deleteRemote(remote: string) {
|
||||
}
|
||||
|
||||
export async function getMountPoints() {
|
||||
console.log('[getMountPoints]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/mount/listmounts', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -115,8 +120,6 @@ export async function getMountPoints() {
|
||||
}>
|
||||
)
|
||||
|
||||
// console.log('Mount points:', r)
|
||||
|
||||
if (!Array.isArray(r?.mountPoints)) {
|
||||
throw new Error('Failed to get mount points')
|
||||
}
|
||||
@@ -125,6 +128,8 @@ export async function getMountPoints() {
|
||||
}
|
||||
|
||||
export async function getBackends() {
|
||||
console.log('[getBackends]')
|
||||
|
||||
const providers = await fetch('http://localhost:5572/config/providers', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -149,6 +154,8 @@ export interface ListOptions {
|
||||
}
|
||||
|
||||
export async function listPath(remote: string, path: string = '', options: ListOptions = {}) {
|
||||
console.log('[listPath]', remote, path, options)
|
||||
|
||||
const params = new URLSearchParams()
|
||||
params.set('fs', `${remote}:`)
|
||||
params.set('remote', path)
|
||||
@@ -190,9 +197,11 @@ export async function listPath(remote: string, path: string = '', options: ListO
|
||||
|
||||
return response?.list || []
|
||||
}
|
||||
/* JOBS */
|
||||
|
||||
/* JOBS */
|
||||
export async function listJobs() {
|
||||
console.log('[listJobs]')
|
||||
|
||||
const allStats = await fetch('http://localhost:5572/core/stats', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -273,6 +282,8 @@ export async function listJobs() {
|
||||
}
|
||||
|
||||
export async function stopJob(jobId: number) {
|
||||
console.log('[stopJob]', jobId)
|
||||
|
||||
await fetch(`http://localhost:5572/job/stopgroup?group=job/${jobId}`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -291,6 +302,8 @@ export async function mountRemote({
|
||||
mountOptions?: Record<string, string | number | boolean>
|
||||
vfsOptions?: Record<string, string | number | boolean>
|
||||
}) {
|
||||
console.log('[mountRemote]', remotePath, mountPoint)
|
||||
|
||||
const options = new URLSearchParams()
|
||||
options.set('fs', remotePath)
|
||||
options.set('mountPoint', mountPoint)
|
||||
@@ -325,6 +338,8 @@ export async function unmountRemote({
|
||||
}: {
|
||||
mountPoint: string
|
||||
}) {
|
||||
console.log('[unmountRemote]', mountPoint)
|
||||
|
||||
const options = new URLSearchParams()
|
||||
options.set('mountPoint', mountPoint)
|
||||
|
||||
@@ -338,8 +353,6 @@ export async function unmountRemote({
|
||||
throw e
|
||||
})
|
||||
|
||||
// console.log('unmountRemote', JSON.stringify(r, null, 2))
|
||||
|
||||
if ('error' in r) {
|
||||
throw new Error(r.error)
|
||||
}
|
||||
@@ -348,6 +361,8 @@ export async function unmountRemote({
|
||||
}
|
||||
|
||||
export async function unmountAllRemotes() {
|
||||
console.log('[unmountAllRemotes]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/mount/unmountall', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -358,8 +373,6 @@ export async function unmountAllRemotes() {
|
||||
throw e
|
||||
})
|
||||
|
||||
console.log('unmountAllRemotes', r)
|
||||
|
||||
if ('error' in r) {
|
||||
throw new Error(r.error)
|
||||
}
|
||||
@@ -452,6 +465,8 @@ export async function startSync({
|
||||
/* FLAGS */
|
||||
|
||||
export async function getGlobalFlags() {
|
||||
console.log('[getGlobalFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/get', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -461,6 +476,8 @@ export async function getGlobalFlags() {
|
||||
}
|
||||
|
||||
export async function getCopyFlags() {
|
||||
console.log('[getCopyFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/info', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -476,6 +493,8 @@ export async function getCopyFlags() {
|
||||
}
|
||||
|
||||
export async function getSyncFlags() {
|
||||
console.log('[getSyncFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/info', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -494,6 +513,8 @@ export async function getSyncFlags() {
|
||||
}
|
||||
|
||||
export async function getFilterFlags() {
|
||||
console.log('[getFilterFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/info', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -508,6 +529,8 @@ export async function getFilterFlags() {
|
||||
}
|
||||
|
||||
export async function getVfsFlags() {
|
||||
console.log('[getVfsFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/info', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
@@ -523,6 +546,8 @@ export async function getVfsFlags() {
|
||||
}
|
||||
|
||||
export async function getMountFlags() {
|
||||
console.log('[getMountFlags]')
|
||||
|
||||
const r = await fetch('http://localhost:5572/options/info', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeader(),
|
||||
|
||||
+39
-30
@@ -39,9 +39,10 @@ export async function initRclone() {
|
||||
* @returns {Promise<boolean>} True if rclone is installed and working
|
||||
*/
|
||||
export async function isSystemRcloneInstalled() {
|
||||
console.log('[isSystemRcloneInstalled]')
|
||||
|
||||
try {
|
||||
const output = await Command.create('rclone-system').execute()
|
||||
// console.log('[isSystemRcloneInstalled] output', output)
|
||||
return (
|
||||
output.stdout.includes('Available commands') ||
|
||||
output.stderr.includes('Available commands')
|
||||
@@ -56,6 +57,8 @@ export async function isSystemRcloneInstalled() {
|
||||
* @returns {Promise<boolean>} True if downloaded rclone is present and working
|
||||
*/
|
||||
export async function isInternalRcloneInstalled() {
|
||||
console.log('[isInternalRcloneInstalled]')
|
||||
|
||||
try {
|
||||
const output = await Command.create('rclone-internal').execute()
|
||||
// console.log('[isInternalRcloneInstalled] output', output)
|
||||
@@ -74,18 +77,21 @@ export async function isInternalRcloneInstalled() {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function provisionRclone() {
|
||||
console.log('[provisionRclone]')
|
||||
|
||||
const currentVersionString = await fetch('https://downloads.rclone.org/version.txt').then(
|
||||
(res) => res.text()
|
||||
)
|
||||
console.log('currentVersionString', currentVersionString)
|
||||
console.log('[provisionRclone] currentVersionString', currentVersionString)
|
||||
|
||||
const currentVersion = currentVersionString.split('v')?.[1]?.trim()
|
||||
|
||||
if (!currentVersion) {
|
||||
console.error('Failed to get latest version')
|
||||
console.error('[provisionRclone] failed to get latest version')
|
||||
await message('Failed to get latest rclone version, please try again later.')
|
||||
return
|
||||
}
|
||||
console.log('currentVersion', currentVersion)
|
||||
console.log('[provisionRclone] currentVersion', currentVersion)
|
||||
|
||||
const currentPlatform = platform()
|
||||
console.log('currentPlatform', currentPlatform)
|
||||
@@ -97,29 +103,31 @@ export async function provisionRclone() {
|
||||
if (tempDirPath.endsWith('/') || tempDirPath.endsWith('\\')) {
|
||||
tempDirPath = tempDirPath.slice(0, -1)
|
||||
}
|
||||
console.log('tempDirPath', tempDirPath)
|
||||
console.log('[provisionRclone] tempDirPath', tempDirPath)
|
||||
|
||||
const arch = (await invoke('get_arch')) as 'arm64' | 'amd64' | '386' | 'unknown'
|
||||
console.log('arch', arch)
|
||||
console.log('[provisionRclone] arch', arch)
|
||||
|
||||
if (arch === 'unknown') {
|
||||
throw new Error('Failed to get architecture, please try again later.')
|
||||
console.error('[provisionRclone] failed to get architecture')
|
||||
await message('Failed to get current arch, please try again later.')
|
||||
return
|
||||
}
|
||||
|
||||
const downloadUrl = `https://downloads.rclone.org/v${currentVersion}/rclone-v${currentVersion}-${currentOs}-${arch}.zip`
|
||||
console.log('downloadUrl', downloadUrl)
|
||||
console.log('[provisionRclone] downloadUrl', downloadUrl)
|
||||
|
||||
const downloadedFile = await fetch(downloadUrl).then((res) => res.arrayBuffer())
|
||||
console.log('downloadedFile')
|
||||
console.log('[provisionRclone] downloadedFile')
|
||||
|
||||
let tempDirExists
|
||||
try {
|
||||
tempDirExists = await exists('rclone', {
|
||||
baseDir: BaseDirectory.Temp,
|
||||
})
|
||||
console.log('tempDirExists', tempDirExists)
|
||||
console.log('[provisionRclone] tempDirExists', tempDirExists)
|
||||
} catch (error) {
|
||||
console.error('Failed to check if rclone temp dir exists', error)
|
||||
console.error('[provisionRclone] failed to check if rclone temp dir exists', error)
|
||||
}
|
||||
|
||||
if (tempDirExists) {
|
||||
@@ -128,9 +136,9 @@ export async function provisionRclone() {
|
||||
recursive: true,
|
||||
baseDir: BaseDirectory.Temp,
|
||||
})
|
||||
console.log('removed rclone temp dir')
|
||||
console.log('[provisionRclone] removed rclone temp dir')
|
||||
} catch (error) {
|
||||
console.error('Failed to remove rclone temp dir', error)
|
||||
console.error('[provisionRclone] failed to remove rclone temp dir', error)
|
||||
await message('Failed to provision rclone.')
|
||||
return
|
||||
}
|
||||
@@ -140,21 +148,21 @@ export async function provisionRclone() {
|
||||
await mkdir('rclone', {
|
||||
baseDir: BaseDirectory.Temp,
|
||||
})
|
||||
console.log('created rclone temp dir')
|
||||
console.log('[provisionRclone] created rclone temp dir')
|
||||
} catch (error) {
|
||||
console.error('Failed to create rclone temp dir', error)
|
||||
console.error('[provisionRclone] failed to create rclone temp dir', error)
|
||||
await message('Failed to provision rclone.')
|
||||
return
|
||||
}
|
||||
|
||||
const zipPath = `${tempDirPath}/rclone/rclone-v${currentVersion}-${currentOs}-${arch}.zip`
|
||||
console.log('zipPath', zipPath)
|
||||
console.log('[provisionRclone] zipPath', zipPath)
|
||||
|
||||
try {
|
||||
await writeFile(zipPath, new Uint8Array(downloadedFile))
|
||||
console.log('wrote zip file')
|
||||
console.log('[provisionRclone] wrote zip file')
|
||||
} catch (error) {
|
||||
console.error('Failed to write zip file', error)
|
||||
console.error('[provisionRclone] failed to write zip file', error)
|
||||
await message('Failed to provision rclone.')
|
||||
return
|
||||
}
|
||||
@@ -164,48 +172,48 @@ export async function provisionRclone() {
|
||||
zipPath,
|
||||
outputFolder: `${tempDirPath}/rclone/rclone-ui`,
|
||||
})
|
||||
console.log('Successfully unzipped file')
|
||||
console.log('[provisionRclone] successfully unzipped file')
|
||||
} catch (error) {
|
||||
console.error('Failed to unzip file', error)
|
||||
console.error('[provisionRclone] failed to unzip file', error)
|
||||
await message('Failed to provision rclone.')
|
||||
return
|
||||
}
|
||||
|
||||
const unarchivedPath = `${tempDirPath}/rclone/rclone-ui/rclone-v${currentVersion}-${currentOs}-${arch}`
|
||||
console.log('unarchivedPath', unarchivedPath)
|
||||
console.log('[provisionRclone] unarchivedPath', unarchivedPath)
|
||||
|
||||
const binaryName = currentPlatform === 'windows' ? 'rclone.exe' : 'rclone'
|
||||
|
||||
// "/" here looks to be working on windows
|
||||
const rcloneBinaryPath = unarchivedPath + '/' + binaryName
|
||||
console.log('rcloneBinaryPath', rcloneBinaryPath)
|
||||
console.log('[provisionRclone] rcloneBinaryPath', rcloneBinaryPath)
|
||||
|
||||
try {
|
||||
const binaryExists = await exists(rcloneBinaryPath)
|
||||
console.log('rcloneBinaryPathExists', binaryExists)
|
||||
console.log('[provisionRclone] rcloneBinaryPathExists', binaryExists)
|
||||
if (!binaryExists) {
|
||||
throw new Error('Could not find rclone binary in zip')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to check if rclone binary exists', error)
|
||||
throw new Error('Could not find rclone binary in zip')
|
||||
console.error('[provisionRclone] failed to check if rclone binary exists', error)
|
||||
await message('Failed to provision rclone.')
|
||||
}
|
||||
|
||||
const appLocalDataDirPath = await appLocalDataDir()
|
||||
console.log('appLocalDataDirPath', appLocalDataDirPath)
|
||||
console.log('[provisionRclone] appLocalDataDirPath', appLocalDataDirPath)
|
||||
|
||||
const appLocalDataDirPathExists = await exists(appLocalDataDirPath)
|
||||
console.log('appLocalDataDirPathExists', appLocalDataDirPathExists)
|
||||
console.log('[provisionRclone] appLocalDataDirPathExists', appLocalDataDirPathExists)
|
||||
|
||||
if (!appLocalDataDirPathExists) {
|
||||
await mkdir(appLocalDataDirPath, {
|
||||
recursive: true,
|
||||
})
|
||||
console.log('appLocalDataDirPath created')
|
||||
console.log('[provisionRclone] appLocalDataDirPath created')
|
||||
}
|
||||
|
||||
await copyFile(rcloneBinaryPath, `${appLocalDataDirPath}/${binaryName}`)
|
||||
console.log('copied rclone binary')
|
||||
console.log('[provisionRclone] copied rclone binary')
|
||||
|
||||
const hasInstalled = await isInternalRcloneInstalled()
|
||||
|
||||
@@ -213,5 +221,6 @@ export async function provisionRclone() {
|
||||
throw new Error('Failed to install rclone')
|
||||
}
|
||||
|
||||
console.log('rclone has been installed')
|
||||
console.log('[provisionRclone] rclone has been installed')
|
||||
|
||||
}
|
||||
|
||||
+11
-6
@@ -8,13 +8,15 @@ import { exit } from '@tauri-apps/plugin-process'
|
||||
import { Command } from '@tauri-apps/plugin-shell'
|
||||
|
||||
export async function needsMountPlugin() {
|
||||
console.log('[needsMountPlugin]')
|
||||
|
||||
const currentPlatform = platform()
|
||||
if (currentPlatform === 'macos') {
|
||||
// check fuse-t or osxfuse
|
||||
const hasFuseT = await exists('/Library/Application Support/fuse-t')
|
||||
console.log('hasFuseT', hasFuseT)
|
||||
console.log('[needsMountPlugin] hasFuseT', hasFuseT)
|
||||
const hasOsxFuse = await exists('/Library/Filesystems/macfuse.fs')
|
||||
console.log('hasOsxFuse', hasOsxFuse)
|
||||
console.log('[needsMountPlugin] hasOsxFuse', hasOsxFuse)
|
||||
return !hasFuseT && !hasOsxFuse
|
||||
}
|
||||
if (currentPlatform === 'windows') {
|
||||
@@ -22,13 +24,15 @@ export async function needsMountPlugin() {
|
||||
const hasWinFsp =
|
||||
(await exists('C:\\Program Files\\WinFsp')) ||
|
||||
(await exists('C:\\Program Files (x86)\\WinFsp'))
|
||||
console.log('hasWinFsp', hasWinFsp)
|
||||
console.log('[needsMountPlugin] hasWinFsp', hasWinFsp)
|
||||
return !hasWinFsp
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function dialogGetMountPlugin() {
|
||||
console.log('[dialogGetMountPlugin]')
|
||||
|
||||
const currentPlatform = platform()
|
||||
if (currentPlatform === 'macos') {
|
||||
// download fuse-t or osxfuse
|
||||
@@ -75,13 +79,12 @@ export async function dialogGetMountPlugin() {
|
||||
}
|
||||
|
||||
export async function unmount(mountPoint: string, force = false) {
|
||||
console.log('[unmount]', mountPoint, force)
|
||||
|
||||
const command = Command.create('umount', [force ? '-f' : '', mountPoint])
|
||||
|
||||
const output = await command.execute()
|
||||
|
||||
// console.log('output')
|
||||
// console.log(JSON.stringify(output, null, 2))
|
||||
|
||||
if (output.code !== 0) {
|
||||
if (output.stderr.toLowerCase().includes('busy')) {
|
||||
const answer = await ask('This resource is busy, do you wish to force unmount?', {
|
||||
@@ -97,9 +100,11 @@ export async function unmount(mountPoint: string, force = false) {
|
||||
}
|
||||
|
||||
if (output.stderr.toLowerCase().includes('not currently mounted')) {
|
||||
console.error('[unmount] not currently mounted')
|
||||
return
|
||||
}
|
||||
|
||||
console.error('[unmount] failed to unmount', output.stderr)
|
||||
throw new Error(output.stderr)
|
||||
}
|
||||
|
||||
|
||||
+17
-8
@@ -24,19 +24,23 @@ export async function triggerTrayRebuild() {
|
||||
})
|
||||
}
|
||||
|
||||
// Function to update the tray menu
|
||||
export async function rebuildTrayMenu() {
|
||||
console.log('[rebuildTrayMenu]')
|
||||
|
||||
const tray = await getMainTray()
|
||||
if (!tray) {
|
||||
console.error('[rebuildTrayMenu] tray not found')
|
||||
return
|
||||
}
|
||||
const newMenu = await buildMenu()
|
||||
await tray.setMenu(newMenu)
|
||||
|
||||
console.log('[rebuildTrayMenu] tray menu rebuilt')
|
||||
}
|
||||
|
||||
async function onTrayAction(event: TrayIconEvent) {
|
||||
if (event.type === 'Click') {
|
||||
console.log('Tray clicked:', event)
|
||||
console.log('[onTrayAction] tray clicked:', event)
|
||||
|
||||
await resetMainWindow()
|
||||
}
|
||||
@@ -45,12 +49,12 @@ async function onTrayAction(event: TrayIconEvent) {
|
||||
// Initialize the tray
|
||||
export async function initTray(): Promise<void> {
|
||||
try {
|
||||
console.log('initTray')
|
||||
console.log('[initTray]')
|
||||
const menu = await buildMenu()
|
||||
console.log('built menu')
|
||||
console.log('[initTray] built menu')
|
||||
|
||||
await TrayIcon.getById('loading-tray').then((t) => t?.setVisible(false))
|
||||
console.log('set loading tray to false')
|
||||
console.log('[initTray] set loading tray to false')
|
||||
|
||||
await TrayIcon.new({
|
||||
id: 'main-tray',
|
||||
@@ -61,13 +65,18 @@ export async function initTray(): Promise<void> {
|
||||
action: onTrayAction,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to create tray')
|
||||
console.error('[initTray] failed to create tray')
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export async function initLoadingTray() {
|
||||
if (platform() === 'linux') return
|
||||
console.log('[initLoadingTray]')
|
||||
|
||||
if (platform() === 'linux') {
|
||||
console.log('[initLoadingTray] platform is linux, skipping')
|
||||
return
|
||||
}
|
||||
|
||||
const globeIconPath = await resolveResource('icons/favicon/frame_00_delay-0.1s.png')
|
||||
|
||||
@@ -104,6 +113,6 @@ export async function initLoadingTray() {
|
||||
`icons/favicon/frame_${currentIcon < 10 ? '0' : ''}${currentIcon}_delay-0.1s.png`
|
||||
)
|
||||
await loadingTray?.setIcon(globeIconPath)
|
||||
currentIcon = currentIcon + 1
|
||||
currentIcon += 1
|
||||
}, 200)
|
||||
}
|
||||
|
||||
+10
-3
@@ -21,6 +21,8 @@ export async function openFullWindow({
|
||||
name: string
|
||||
url: string
|
||||
}) {
|
||||
console.log('[openFullWindow]')
|
||||
|
||||
const w = new WebviewWindow(name, {
|
||||
height: 0,
|
||||
width: 0,
|
||||
@@ -36,7 +38,10 @@ export async function openFullWindow({
|
||||
|
||||
const size = await currentMonitor().then((m) => m?.size)
|
||||
|
||||
if (!size) return
|
||||
if (!size) {
|
||||
console.error('[openFullWindow] no monitor found')
|
||||
throw new Error('No monitor found')
|
||||
}
|
||||
|
||||
if (platform() === 'windows') {
|
||||
// windows merges the space for the taskbar
|
||||
@@ -55,14 +60,16 @@ export async function openFullWindow({
|
||||
export async function openWindow({
|
||||
name,
|
||||
url,
|
||||
width = 740,
|
||||
height = 600,
|
||||
width = 820,
|
||||
height = 700,
|
||||
}: {
|
||||
name: string
|
||||
url: string
|
||||
width?: number
|
||||
height?: number
|
||||
}) {
|
||||
console.log('[openWindow]')
|
||||
|
||||
const isFirstWindow = useStore.getState().firstWindow
|
||||
|
||||
const w = new WebviewWindow(name, {
|
||||
|
||||
Reference in New Issue
Block a user