Jump to content

Chrome App Creator


Recommended Posts

Due to school I haven't been too active doing AutoIt stuff so i thought I would write up something.

As im currently customizing my newly formatted desktop i thought i would make something to aid at that.

Say hi to my Chrome App Creator!

Let's do this systematical and nice.

What is an app?

- You know the chrome web store, gmail, youtube icons ?

Well thats the kind of app this is making.

Its basicly a shortcut.

You choose what icon it will be using, and where it will take you when you click it.

What does it do?

- It takes the image file and copy/move it to a folder together with creating a manifest.json.

The manifest is where it saves the name of the app, and the web page you set it to open.

Isn't this the wrong forum part if you're showing off your program?

- No, I don't think so, since the main reason for posting is to get feedback on the way its coded.

Any particular "rules" to follow?

- Yes, keep the image at 128x128 or less.

I always use 128x128, so i don't know what happens if you use less, but the program stops you if its bigger.

Also if you don't remember to add Http:// it will add it for you.

The code?

- Here:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#Include <GDIPlus.au3>
Local $msg
Global $HorizontalPlacement = 1
Global $HorizontalSpacing = 10
;Global $VerticalPlacement = 1
;Global $VerticalSpacing = 10
Global $FileLocation
Global $JSON
Global $hImage
$GUI = GUICreate("App Creator", 230, 400)
$NameInput = GUICtrlCreateInput("Name", 10, ($HorizontalPlacement*$HorizontalSpacing), 210)
;$HorizontalPlacement += 3
;$DescriptionInput = GUICtrlCreateInput("Description", 10, ($HorizontalPlacement*$HorizontalSpacing), 210)
$HorizontalPlacement += 3
$WebsiteInput = GUICtrlCreateInput("Website", 10, ($HorizontalPlacement*$HorizontalSpacing))
$HorizontalPlacement += 3
$ImageLocationOutput = GUICtrlCreateInput("No file selected", 10, ($HorizontalPlacement*$HorizontalSpacing))
GUICtrlSetState(-1,$GUI_DISABLE)
$HorizontalPlacement += 3
$MoveFileCheckbox = GUICtrlCreateCheckbox("Move the image file instead of copying it", 10, ($HorizontalPlacement*$HorizontalSpacing))
$HorizontalPlacement += 3
$ImageBrowseButton = GUICtrlCreateButton("Browse", 10, ($HorizontalPlacement*$HorizontalSpacing),80)
$CreateAppButton = GUICtrlCreateButton("Create App", 220-10-70, ($HorizontalPlacement*$HorizontalSpacing),80)

GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   _GDIPlus_ImageDispose ($hImage)
   _GDIPlus_ShutDown ()
   Exit
  Case $msg = $ImageBrowseButton
   $FileLocation = FileOpenDialog("Select the image file.", @UserProfileDir & "\pictures", "Png Images(*.png)", 1)
   If @error Then
    MsgBox(4096, "Error", "No File(s) chosen!")
   Else
    _GDIPlus_Startup ()
    Local $hImage = _GDIPlus_ImageLoadFromFile($FileLocation)
    If @error Then
     MsgBox(16, "Error", "Does the file exist?")
    EndIf
;~    ConsoleWrite(_GDIPlus_ImageGetWidth($hImage) & @CRLF)
;~    ConsoleWrite(_GDIPlus_ImageGetHeight($hImage) & @CRLF)
    If _GDIPlus_ImageGetWidth($hImage) > 128 or _GDIPlus_ImageGetHeight($hImage) > 128 Then
     MsgBox("","Error!","The image you selected is " & _GDIPlus_ImageGetWidth($hImage) & " x " & _GDIPlus_ImageGetHeight($hImage) & " pixels." & @CRLF & "Maximum size allowed for image is 128x128.")
    Else
     ;MsgBox("","",$FileLocation)
     $StringReturn = StringInStr($FileLocation,"\",0,-1)
     If $StringReturn = 0 then Exitloop
     ;MsgBox("","",$StringReturn)
     $StringReturn = StringTrimLeft($FileLocation, $StringReturn)
     $FileName = $StringReturn
     ;MsgBox("","",$StringReturn)
     GUICtrlSetData($ImageLocationOutput, $FileName)
;~    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hImage)
;~    _GDIPlus_GraphicsDrawRect($hGraphics,10, 10, 128,128)


    EndIf
   ;------------------------------------
   EndIf
  Case $msg = $CreateAppButton
   If @error Then
    MsgBox(4096, "Error", "No File(s) chosen!")
   Else
    ;MsgBox("","",GUICtrlRead($MoveFileCheckbox))
    ; 1 = Checked, 4 = Unchecked
    $FileSaveDirectory = FileSaveDialog("Choose directory",@UserProfileDir & "\documents","Folder(*.*)",-1, "My Chrome App")
    DirCreate ($FileSaveDirectory)
;~   #cs
    If Not StringInStr(Guictrlread($WebsiteInput),"http://") Then
;~    MsgBox("","",Guictrlread($WebsiteInput))
     $WebsiteInput = "http://" & Guictrlread($WebsiteInput)
;~    MsgBox("","",$WebsiteInput)
    EndIf
;~   #CE
    If GUICtrlRead($MoveFileCheckbox) = 1 then
     FileMove($FileLocation, $FileSaveDirectory)
    ElseIf GUICtrlRead($MoveFileCheckbox) = 4 then
     FileCopy($FileLocation, $FileSaveDirectory)
    EndIf
    ;MsgBox("","",$FileSaveDirectory & "\manifest.json")
    _FileCreate($FileSaveDirectory & "\manifest.json")
    $JSONFile = FileOpen($FileSaveDirectory & "\manifest.json",1)
    $JSON ='{' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"name": "' & GUICtrlRead($NameInput) & '",' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"description": "' & GUICtrlRead($NameInput) & ' App",' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"version": "1.0",' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"icons": {' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"128": "' & $FileName & '"' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '},' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"app": {' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"urls": [' & @CRLF
    FileWriteLine($JSONFile, $JSON)
;~   $JSON = '"' & GUICtrlRead($WebsiteInput) & '"' & @CRLF
    $JSON = '"' & $WebsiteInput & '"' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '],' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"launch": {' & @CRLF
    FileWriteLine($JSONFile, $JSON)
;~   $JSON = '"web_url": "' & GUICtrlRead($WebsiteInput) & '"' & @CRLF
    $JSON = '"web_url": "' & $WebsiteInput & '"' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '}' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '},' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"permissions": [' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"unlimitedStorage",' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '"notifications"' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = ']' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    $JSON = '}' & @CRLF
    FileWriteLine($JSONFile, $JSON)
    MsgBox("","","The folder containing all the files was successfully created!" & @CRLF & "Enjoy your new app!")
    GUICtrlSetData($NameInput,"Name")
    GUICtrlSetData($WebsiteInput,"Website")
    GUICtrlSetData($ImageLocationOutput, "No file selected")
   EndIf
EndSelect
WEnd

So to wrappin it up!

1. If you're gonna comment on HOW something is coded (ofc you are...) please remember to tell me WHY you would do it your way, and explain instead of saying "its better".

2. At, i think it is, line 70 you can see some GDI+ stuff commented out.

I tried to make a preview beneath the buttons, but im lost at GDI+ ;)

If anyone have a suggestion on what i need to do here, please tell me.

3. Alot of the commented out MsgBoxes are to debug the script.

If you wonder about anything, please let me know and ill try to explain.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Is it THAT shitty?

You guys won't even comment on it?? ;):)

Well, i should try to work some more on it then ? :)

Btw, ive changed the the input wheree it tell you what image is chosen to a label.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Here's a comment.

Isn't this the wrong forum part if you're showing off your program?

- No, I don't think so, since the main reason for posting is to get feedback on the way its coded.

You're wrong, it belongs in the example scripts if you want feedback, but still, you should not expect any.

You might be proud of your program, and you have every right to be, but that does not mean people

will take the time to read past the first sentence if the idea is uninteresting to them.

Good luck with whatever it is.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I don't use Chrome, hence the very little feedback from me. One idea, a little less FileWriteLine and more of FileOpen & FileWrite!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You're wrong, it belongs in the example scripts if you want feedback, but still, you should not expect any.

You might be proud of your program, and you have every right to be, but that does not mean people

will take the time to read past the first sentence if the idea is uninteresting to them.

Okay, thanks.

Seems like i shoulda given it a bit more thought before posting here.

Thanks for feedback none the less.

I don't use Chrome, hence the very little feedback from me. One idea, a little less FileWriteLine and more of FileOpen & FileWrite!

I was waiting for this.

But i tried

$JSON &= "Text here"
$JSON &= "Text here"
$JSON &= "Text here"
$JSON &= "Text here"
FileWrite($JSONFile,$JSON)

I got an empty file then ;)

I guess ill try to fix it.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Maybe the FileClose is missing. This works just fine here:

Global $JSONFile = FileOpen("C:tempmanifest.json",1)
ConsoleWrite(@error & @CRLF)
Global $JSON
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
FileWrite($JSONFile,$JSON)
FileClose($JSONFile)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Maybe the FileClose is missing. This works just fine here:

Global $JSONFile = FileOpen("C:\temp\manifest.json",1)
ConsoleWrite(@error & @CRLF)
Global $JSON
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
$JSON &= "Text here" & @CRLF
FileWrite($JSONFile,$JSON)
FileClose($JSONFile)

Yes, i used this to create a .json file and it worked, it also worked without the FileClose.

It did not work without the 1 at FileOpen, which i hadn't used in my script... Small things make big problems... ;)

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Because 0 (read mode) is default.

That' s why I always check the return value and/or @error after such function calls. Then I know why my script doesn't work and where it happens.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I usually use MsgBox to do that.

But i fixed that and it still didn't work.

Declaring the variable as Global fixed it.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...