-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support dragging the floating icon. (#6436)
- Loading branch information
1 parent
c8027cc
commit e9114ce
Showing
5 changed files
with
68 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
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
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
46 changes: 46 additions & 0 deletions
46
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityFloatingIconSettings.ts
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,46 @@ | ||
import { backgroundMethod } from '@onekeyhq/shared/src/background/backgroundDecorators'; | ||
|
||
import { SimpleDbEntityBase } from '../base/SimpleDbEntityBase'; | ||
|
||
export interface IFloatingIconSettings { | ||
position: { | ||
side: 'left' | 'right'; | ||
bottom: string; | ||
}; | ||
} | ||
|
||
const DEFAULT_POSITION: IFloatingIconSettings['position'] = { | ||
side: 'right', | ||
bottom: '30%', | ||
}; | ||
|
||
export class SimpleDbEntityFloatingIconSettings extends SimpleDbEntityBase<IFloatingIconSettings> { | ||
entityName = 'floatingIconSettings'; | ||
|
||
override enableCache = false; | ||
|
||
@backgroundMethod() | ||
async getSettings(): Promise<IFloatingIconSettings> { | ||
const result = | ||
(await this.getRawData()) || ({} as Partial<IFloatingIconSettings>); | ||
const position = result.position || DEFAULT_POSITION; | ||
return { | ||
position, | ||
}; | ||
} | ||
|
||
@backgroundMethod() | ||
async setSettings(settings: Partial<IFloatingIconSettings> | undefined) { | ||
if (!settings) { | ||
return; | ||
} | ||
const dbSettings = await this.getSettings(); | ||
const position = settings.position || dbSettings.position; | ||
await this.setRawData({ | ||
position: { | ||
side: position.side || DEFAULT_POSITION.side, | ||
bottom: position.bottom || DEFAULT_POSITION.bottom, | ||
}, | ||
}); | ||
} | ||
} |
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