As of version 1.1.4, VisiOS has introduced VisiAPI.
VisiAPI can enhance the functionality of your VisiOS apps.
π© General APIs
γπ· ver - Get the current VisiOS version number
γπ· fetch - Fetch from the target URL
γπ· copyToClipboard - Copy text to the clipboard
π© File APIs
γπ· openFile - Open the file path you specified
γπ· openPage - Open URL (or execute HTML/JavaScript) in a new VisiOS window (or in a new actual window or tab)
γπ· closeWindow - Close the selected window
π© Storage APIs
γπ· localStorage_set - Save data to the local storage
γπ· localStorage_get - Get data from the local storage
γπ· memStorage_set - Save data to the memory storage
γπ· memStorage_get - Get data to the memory storage
γπ· appStorage_set - Save data to the app storage
γπ· appStorage_get - Get data to the app storage
Get the current installed VisiOS version number
async function showVersion(){
let text = await VisiAPI('ver')
alert( text ) //for example: 1.1.4
}
showVersion()
You can also use then:
VisiAPI('ver').then(v=>{
alert(`VisiOS Version: ${v}`)
})
Fetch from the target URL
// This will fetch the html of the target URL
async function test(){
let text = await VisiAPI('fetch', {url:'https://google.com'})
alert( text ) //display the html of the target URL
}
test()
// NOTE: β You can also specify "options" just like with fetch in JavaScript
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
VisiAPI('fetch', {url:'https://url...', options: {mode:..., method:..., body:... }})
Copy text to the clipboard
VisiAPI('copyToClipboard', {text:'Text to copy'})
Open the file path you specified
// β You can open folders or files by setting the desktop index number(1-9) and file path to a folder or a file.
VisiAPI('openFile', {desktopId:1, path:'file_path_to_open'})
// for example, if you have a folder named "My Documents" on Desktop 3
VisiAPI('openFile', {desktopId:3, path:'My Documents'})
// If you also want to specify the size (This works only for folders)
VisiAPI('openFile', {desktopId:3, path:'My Documents', w:700, h:400}) //Specify the width and height
// If you have a bookmark named Google on Desktop 1, you can open the bookmark like this:
VisiAPI('openFile', {path:'Google', x:10, y:10, w:700, h:400}) //open in new VisiOS window (NOTE: x, y, w, h are optional)
VisiAPI('openFile', {path:'Google', type:'newTab'}) //open in new tab
VisiAPI('openFile', {path:'Google', type:'newWindow', x:0, y:0, w:700, h:400}) //open in new window
The following technique can be also used with openPage
// If you want to place the app in the top-right corner
// ( xp is the percentage of the X coordinate on the screen. If you specify xp, x will be an offset from the xp position)
VisiAPI('openFile', {path:'file_path_to_open', x:-700, y:0, xp:100, w:700, h:400})
// If you want to place the app in the center
// (Set xp and yp each to 50 (this is a percentage), and set x and y to half of your w and h values, respectively)
VisiAPI('openFile', {path:'file_path_to_open', x:-350, y:-200, xp:50, yp:50, w:700, h:400})
Open URL (or execute HTML/JavaScript) in a new VisiOS window (or in a new actual window or tab)
// Open URL (Open as a VisiOS window)
VisiAPI('openPage', {url:'https://url_to_open'})
// Specify the size and starting coordinates
VisiAPI('openPage', {url:'https://url_to_open', w:700, h:500, x:100, y:10})
// HTML
VisiAPI('openPage', {html:'<h1>Hello!</h1><br><br>This is HTML!'})
// HTML + JS
VisiAPI('openPage', {html:'<h1>Hello!</h1><br><br>This is HTML!', script:'alert("Wow!")'})
// HTML for a new tab (*You cannot use JavaScript for this)
VisiAPI('openPage', {type:'newTab', html:'<h1>Hello!</h1><br><br>This is HTML!'})
// HTML for a new popup window (*You cannot use JavaScript for this)
VisiAPI('openPage', {type:'newWindow', html:'<h1>Hello!</h1><br><br>This is HTML!'})
// You can also specify x, y, w, h
VisiAPI('openPage', {type:'newWindow', html:'<h1>Hello!</h1><br><br>This is HTML!', x:0, y:0, w:700, h:400})
Close the current app
VisiAPI('closeWindow')
Close the selected window
async function test(){
let windowId = await VisiAPI('openFile', {desktopId: 3, path: 'My Documents'})
VisiAPI('closeWindow', { desktopId: 3, windowId: windowId })
}
test()
async function test(){
let windowId = await VisiAPI('openPage', {html: '<h1>Hello!</h1><br><br>This is HTML!'})
VisiAPI('closeWindow', { windowId: windowId })
}
test()
If you pass a key name and value, this will add that key to the local storage, or update that key's value if it already exists.
Note
If it's just temporary, consider using memStorage_set
instead since it's faster and doesn't use up the browser storage.
You shouldn't rely on the local storage too much since the data will be lost when the user clears the browser cache.
To avoid that, use appStorage_set
instead.
VisiAPI('localStorage_set', {n:'test_key', v:'Wow!!'})
If you pass a key name, this will return the key's value from the local storage, or null if the key does not exist
async function test(){
VisiAPI('localStorage_set', {n:'test_key', v:'Wow VisiOS!!'})
let v = await VisiAPI('localStorage_get', {n:'test_key'})
alert( v ) //Wow VisiOS!!
}
test()
If you pass a key name and value, this will add that key to the memory storage, or update that key's value if it already exists. The memory storage is shared across all VisiOS apps and is cleared when the user closes the tab.
Note
Unlike localStorage_set
and appStorage_set
, memStorage_set
simply stores values in a plane variable, so you don't have to serialize the values using something like JSON.stringify
VisiAPI('memStorage_set', {n:'test_key', v:'Wow!!'})
If you pass a key name, this will return the key's value from the memory storage, or null if the key does not exist. The memory storage is shared across all VisiOS apps and is cleared when the user closes the tab. This feature is good for storing temporary data that you want to share across multiple apps in real time.
async function test(){
VisiAPI('memStorage_set', {n:'test_key', v:'Wow VisiOS!!'})
let v = await VisiAPI('memStorage_get', {n:'test_key'})
alert( v ) //Wow VisiOS!!
}
test()
If you pass a key name and value, this will add that key to the app storage, or update that key's value if it already exists.
If it's just temporary, consider using memStorage_set
instead since it's faster and doesn't use up the VisiOS storage.
VisiAPI('appStorage_set', {n:'test_key', v:'Wow!!'})
If you pass a key name, this will return the key's value from the app storage, or null if the key does not exist.
async function test(){
VisiAPI('appStorage_set', {n:'test_key', v:'Wow VisiOS!!'})
let v = await VisiAPI('appStorage_get', {n:'test_key'})
alert( v ) //Wow VisiOS!!
}
test()